1+ """This module contains the functions to export all the embeddings to a time series format, group them together and export it as a pickle file"""
2+
13# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/01_pickle.ipynb.
24
3- # %% ../nbs/01_pickle.ipynb 2
5+ # %% ../nbs/01_pickle.ipynb #cc0ae037
46from __future__ import annotations
57import os
68import numpy as np
1113from fastcore .xtras import *
1214from fastcore .script import *
1315
14- # %% auto 0
16+ # %% auto # 0
1517__all__ = ['label' , 'cos_sim' , 'successive_similarities' , 'create_dict_whole_book' , 'create_label_whole_book' , 'create_label' ,
1618 'get_embed_method_and_name' ]
1719
18- # %% ../nbs/01_pickle.ipynb 4
20+ # %% ../nbs/01_pickle.ipynb #01c70e33
1921def label (method : str ): # name of the method
2022 """
2123 Returns the full name of the model based on the abbreviation
@@ -41,7 +43,7 @@ def label(method: str): # name of the method
4143 return switcher .get (method )
4244
4345
44- # %% ../nbs/01_pickle.ipynb 5
46+ # %% ../nbs/01_pickle.ipynb #091b0d73
4547def cos_sim (
4648 a : np .ndarray , # vector 1
4749 b : np .ndarray , # vector 2
@@ -52,18 +54,18 @@ def cos_sim(
5254 return dot (a , b ) / (norm (a ) * norm (b ))
5355
5456
55- # %% ../nbs/01_pickle.ipynb 6
57+ # %% ../nbs/01_pickle.ipynb #0463a325
5658from pathlib import Path
5759
58- # %% ../nbs/01_pickle.ipynb 7
60+ # %% ../nbs/01_pickle.ipynb #aad409d5
5961def successive_similarities (embeddings , k ):
6062 successive = []
6163 for i in range (len (embeddings ) - k ):
6264 successive .append (cos_sim (embeddings [i ], embeddings [i + k ]))
6365 return successive
6466
6567
66- # %% ../nbs/01_pickle.ipynb 8
68+ # %% ../nbs/01_pickle.ipynb #9b793316
6769@call_parse
6870def create_dict_whole_book (
6971 embedding_path : str = "." , # path to the embeddings
@@ -128,7 +130,7 @@ def create_dict_whole_book(
128130 print (f"Saved pkl at { new_path } " )
129131
130132
131- # %% ../nbs/01_pickle.ipynb 9
133+ # %% ../nbs/01_pickle.ipynb #4a217262
132134def create_label_whole_book (method , parent_dir ):
133135 # returns only the method name
134136 return label (method )
@@ -137,13 +139,13 @@ def create_label_whole_book(method, parent_dir):
137139 # return parent_dir.title() + ' ' + label(method)
138140
139141
140- # %% ../nbs/01_pickle.ipynb 10
142+ # %% ../nbs/01_pickle.ipynb #c35ac5e6
141143def create_label (index , method , parent_dir ):
142144 met = label (method )
143145 return "Book " + str (index + 1 ) + " " + parent_dir .title () + " " + met
144146
145147
146- # %% ../nbs/01_pickle.ipynb 11
148+ # %% ../nbs/01_pickle.ipynb #bad8ed11
147149def get_embed_method_and_name (
148150 fname , # name of the file
149151) -> (str , str ): # name of file, embeddding method
0 commit comments