Skip to content

Commit 5c39caa

Browse files
committed
export
1 parent cfa0147 commit 5c39caa

7 files changed

Lines changed: 81 additions & 69 deletions

File tree

clean_plot/_modidx.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
# Autogenerated by nbdev
22

33
d = { 'settings': { 'branch': 'master',
4-
'doc_baseurl': '/clean_plot/',
4+
'doc_baseurl': '/clean_plot',
55
'doc_host': 'https://deven367.github.io',
6-
'git_url': 'https://github.com/deven367/clean_plot/',
6+
'git_url': 'https://github.com/deven367/clean_plot',
77
'lib_path': 'clean_plot'},
88
'syms': { 'clean_plot.errors': { 'clean_plot.errors.MyException': ('errors.html#myexception', 'clean_plot/errors.py'),
99
'clean_plot.errors.MyException.__init__': ('errors.html#myexception.__init__', 'clean_plot/errors.py'),

clean_plot/errors.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
1+
"""Implementations of custom errors"""
2+
13
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/07_errors.ipynb.
24

3-
# %% auto 0
5+
# %% auto #0
46
__all__ = ['MyException']
57

6-
# %% ../nbs/07_errors.ipynb 3
8+
# %% ../nbs/07_errors.ipynb #e47f666a
79
class MyException(Exception):
810
def __init__(self, message):
911
super().__init__(message)
@@ -14,5 +16,5 @@ def __str__(self):
1416
return self.message
1517

1618

17-
# %% ../nbs/07_errors.ipynb 4
19+
# %% ../nbs/07_errors.ipynb #bd0b5135
1820
import inspect

clean_plot/heatmaps_novels.py

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
"""This module is to create heatmaps for given books. It even includes some functions to generate smaller heatmaps"""
2+
13
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/03_heatmaps_novels.ipynb.
24

3-
# %% ../nbs/03_heatmaps_novels.ipynb 3
5+
# %% ../nbs/03_heatmaps_novels.ipynb #496cc07d
46
from __future__ import annotations
57
from .utils import *
68
from .utils import check_files
@@ -16,11 +18,11 @@
1618
import pickle
1719
from scipy.stats import zscore
1820

19-
# %% auto 0
21+
# %% auto #0
2022
__all__ = ['heatmap_from_pkl', 'plot_novels', 'plot_histograms', 'ssms_from_pkl', 'corr_heatmaps', 'corr_ts', 'lex_ts',
2123
'plot_standardized']
2224

23-
# %% ../nbs/03_heatmaps_novels.ipynb 6
25+
# %% ../nbs/03_heatmaps_novels.ipynb #adfe6474
2426
@call_parse
2527
def heatmap_from_pkl(
2628
path: str = ".", # path to pkl files
@@ -121,7 +123,7 @@ def heatmap_from_pkl(
121123
print("-" * 45)
122124

123125

124-
# %% ../nbs/03_heatmaps_novels.ipynb 9
126+
# %% ../nbs/03_heatmaps_novels.ipynb #ea177d41
125127
@call_parse
126128
def plot_novels(
127129
path: str = None, # path for embeddings
@@ -263,10 +265,10 @@ def plot_novels(
263265
del em, sim, n
264266

265267

266-
# %% ../nbs/03_heatmaps_novels.ipynb 11
268+
# %% ../nbs/03_heatmaps_novels.ipynb #d4662490
267269
from scipy.stats import zscore
268270

269-
# %% ../nbs/03_heatmaps_novels.ipynb 12
271+
# %% ../nbs/03_heatmaps_novels.ipynb #12edf4e8
270272
@call_parse
271273
def plot_histograms(
272274
path: str, # path for embeddings
@@ -343,10 +345,10 @@ def plot_histograms(
343345
print(f"Done plotting {title}.png")
344346

345347

346-
# %% ../nbs/03_heatmaps_novels.ipynb 13
348+
# %% ../nbs/03_heatmaps_novels.ipynb #b80c8a10
347349
import pandas as pd
348350

349-
# %% ../nbs/03_heatmaps_novels.ipynb 14
351+
# %% ../nbs/03_heatmaps_novels.ipynb #57b04ae7
350352
@call_parse
351353
def ssms_from_pkl(
352354
path: str, # path for pkl file
@@ -393,7 +395,7 @@ def ssms_from_pkl(
393395
plt.clf()
394396

395397

396-
# %% ../nbs/03_heatmaps_novels.ipynb 15
398+
# %% ../nbs/03_heatmaps_novels.ipynb #1d8809d3
397399
@call_parse
398400
def corr_heatmaps(
399401
path: str, # path for embeddings
@@ -480,7 +482,7 @@ def corr_heatmaps(
480482
# plt.clf()
481483

482484

483-
# %% ../nbs/03_heatmaps_novels.ipynb 16
485+
# %% ../nbs/03_heatmaps_novels.ipynb #b9f81ea5
484486
@call_parse
485487
def corr_ts(
486488
path: str, # path for embeddings
@@ -499,7 +501,7 @@ def corr_ts(
499501
_plot(embedding_path, data, name)
500502

501503

502-
# %% ../nbs/03_heatmaps_novels.ipynb 17
504+
# %% ../nbs/03_heatmaps_novels.ipynb #f082e00b
503505
@call_parse
504506
def lex_ts(
505507
path: str, # path for embeddings
@@ -523,7 +525,7 @@ def lex_ts(
523525
print(len(z))
524526

525527

526-
# %% ../nbs/03_heatmaps_novels.ipynb 18
528+
# %% ../nbs/03_heatmaps_novels.ipynb #8f9a5f21
527529
@call_parse
528530
def plot_standardized(
529531
path: str, # path for embeddings

clean_plot/lexical.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,19 @@
1+
"""This file goes over generating lexical embeddings"""
2+
13
# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/02_lexical.ipynb.
24

3-
# %% auto 0
5+
# %% auto #0
46
__all__ = ['interpolate', 'load_pmi', 'load_dictionary', 'write_to_file_lexical', 'process_v2']
57

6-
# %% ../nbs/02_lexical.ipynb 3
8+
# %% ../nbs/02_lexical.ipynb #a99648f1
79
import re
810
from . import *
911
import os
1012
import unidecode
1113
from collections import OrderedDict
1214
from fastcore.all import *
1315

14-
# %% ../nbs/02_lexical.ipynb 6
16+
# %% ../nbs/02_lexical.ipynb #92362780
1517
def interpolate(lex, removed_indices=[]):
1618
"""
1719
Method does interpolation based on the removed indices.
@@ -23,28 +25,28 @@ def interpolate(lex, removed_indices=[]):
2325
return lex
2426

2527

26-
# %% ../nbs/02_lexical.ipynb 7
28+
# %% ../nbs/02_lexical.ipynb #7b6b4ad9
2729
def load_pmi(path):
2830
pmi = np.load(path)
2931
return pmi
3032

3133

32-
# %% ../nbs/02_lexical.ipynb 8
34+
# %% ../nbs/02_lexical.ipynb #9ef07dfc
3335
def load_dictionary(path):
3436
fname = open(path, "rb")
3537
data = pickle.load(fname)
3638
return data
3739

3840

39-
# %% ../nbs/02_lexical.ipynb 9
41+
# %% ../nbs/02_lexical.ipynb #3ece596a
4042
def write_to_file_lexical(sentences, fname):
4143
with open(fname[:-4] + "_lexical.txt", "w") as f:
4244
for line in sentences:
4345
f.write(line + "\n")
4446
f.close()
4547

4648

47-
# %% ../nbs/02_lexical.ipynb 10
49+
# %% ../nbs/02_lexical.ipynb #37e49d2d
4850
def process_v2(fname):
4951
all_data = get_data(fname)
5052
all_data = unidecode.unidecode(all_data)

clean_plot/pickle.py

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
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
46
from __future__ import annotations
57
import os
68
import numpy as np
@@ -11,11 +13,11 @@
1113
from fastcore.xtras import *
1214
from 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
1921
def 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
4547
def 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
5658
from pathlib import Path
5759

58-
# %% ../nbs/01_pickle.ipynb 7
60+
# %% ../nbs/01_pickle.ipynb #aad409d5
5961
def 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
6870
def 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
132134
def 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
141143
def 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
147149
def get_embed_method_and_name(
148150
fname, # name of the file
149151
) -> (str, str): # name of file, embeddding method

clean_plot/plot/utils.py

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1+
"""This module tries to include most of the plotting functionality available in the package"""
2+
13
# AUTOGENERATED! DO NOT EDIT! File to edit: ../../nbs/04_plot.utils.ipynb.
24

3-
# %% ../../nbs/04_plot.utils.ipynb 3
5+
# %% ../../nbs/04_plot.utils.ipynb #b2cde59e
46
from __future__ import annotations
57
from fastcore.basics import store_attr, patch_to, patch
68
from fastcore.xtras import globtastic
@@ -16,16 +18,16 @@
1618
import matplotlib.pyplot as plt
1719
import gc
1820

19-
# %% auto 0
21+
# %% auto #0
2022
__all__ = ['Plot']
2123

22-
# %% ../../nbs/04_plot.utils.ipynb 4
24+
# %% ../../nbs/04_plot.utils.ipynb #42232bac
2325
sns.set_style(style="white")
2426

25-
# %% ../../nbs/04_plot.utils.ipynb 5
27+
# %% ../../nbs/04_plot.utils.ipynb #d40153c2
2628
import inspect
2729

28-
# %% ../../nbs/04_plot.utils.ipynb 6
30+
# %% ../../nbs/04_plot.utils.ipynb #0c04e9eb
2931
class Plot:
3032
"Plotting module"
3133

@@ -119,7 +121,7 @@ def __repr__(self):
119121
return f"This object contains the path to `{self.path.absolute()}`"
120122

121123

122-
# %% ../../nbs/04_plot.utils.ipynb 7
124+
# %% ../../nbs/04_plot.utils.ipynb #0f9376f0
123125
@patch
124126
def get_normalized(self: Plot):
125127
"Returns the normalized ssms"
@@ -150,7 +152,7 @@ def get_normalized(self: Plot):
150152
return self.norm
151153

152154

153-
# %% ../../nbs/04_plot.utils.ipynb 8
155+
# %% ../../nbs/04_plot.utils.ipynb #6ca425a9
154156
@patch
155157
def get_standardized(self: Plot):
156158
"Returns the standardized ssms"

0 commit comments

Comments
 (0)