Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ on:
jobs:
deploy:
runs-on: ubuntu-latest
steps: [uses: fastai/workflows/quarto-ghp@master]
steps: [uses: fastai/workflows/quarto-ghp3@master]
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ on: [workflow_dispatch, pull_request, push]
jobs:
test:
runs-on: ubuntu-latest
steps: [uses: fastai/workflows/nbdev-ci@master]
steps: [uses: fastai/workflows/nbdev3-ci@master]
6 changes: 5 additions & 1 deletion clean_plot/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
__version__ = "0.0.14"
__version__ = "0.0.14"

from .utils import download_nltk_dep

download_nltk_dep()
4 changes: 2 additions & 2 deletions clean_plot/_modidx.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# Autogenerated by nbdev

d = { 'settings': { 'branch': 'master',
'doc_baseurl': '/clean_plot/',
'doc_baseurl': '/clean_plot',
'doc_host': 'https://deven367.github.io',
'git_url': 'https://github.com/deven367/clean_plot/',
'git_url': 'https://github.com/deven367/clean_plot',
'lib_path': 'clean_plot'},
'syms': { 'clean_plot.errors': { 'clean_plot.errors.MyException': ('errors.html#myexception', 'clean_plot/errors.py'),
'clean_plot.errors.MyException.__init__': ('errors.html#myexception.__init__', 'clean_plot/errors.py'),
Expand Down
8 changes: 5 additions & 3 deletions clean_plot/errors.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
"""Implementations of custom errors"""

# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/07_errors.ipynb.

# %% auto 0
# %% auto #0
__all__ = ['MyException']

# %% ../nbs/07_errors.ipynb 3
# %% ../nbs/07_errors.ipynb #e47f666a
class MyException(Exception):
def __init__(self, message):
super().__init__(message)
Expand All @@ -14,5 +16,5 @@ def __str__(self):
return self.message


# %% ../nbs/07_errors.ipynb 4
# %% ../nbs/07_errors.ipynb #bd0b5135
import inspect
26 changes: 14 additions & 12 deletions clean_plot/heatmaps_novels.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""This module is to create heatmaps for given books. It even includes some functions to generate smaller heatmaps"""

# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/03_heatmaps_novels.ipynb.

# %% ../nbs/03_heatmaps_novels.ipynb 3
# %% ../nbs/03_heatmaps_novels.ipynb #496cc07d
from __future__ import annotations
from .utils import *
from .utils import check_files
Expand All @@ -16,11 +18,11 @@
import pickle
from scipy.stats import zscore

# %% auto 0
# %% auto #0
__all__ = ['heatmap_from_pkl', 'plot_novels', 'plot_histograms', 'ssms_from_pkl', 'corr_heatmaps', 'corr_ts', 'lex_ts',
'plot_standardized']

# %% ../nbs/03_heatmaps_novels.ipynb 6
# %% ../nbs/03_heatmaps_novels.ipynb #adfe6474
@call_parse
def heatmap_from_pkl(
path: str = ".", # path to pkl files
Expand Down Expand Up @@ -121,7 +123,7 @@ def heatmap_from_pkl(
print("-" * 45)


# %% ../nbs/03_heatmaps_novels.ipynb 9
# %% ../nbs/03_heatmaps_novels.ipynb #ea177d41
@call_parse
def plot_novels(
path: str = None, # path for embeddings
Expand Down Expand Up @@ -263,10 +265,10 @@ def plot_novels(
del em, sim, n


# %% ../nbs/03_heatmaps_novels.ipynb 11
# %% ../nbs/03_heatmaps_novels.ipynb #d4662490
from scipy.stats import zscore

# %% ../nbs/03_heatmaps_novels.ipynb 12
# %% ../nbs/03_heatmaps_novels.ipynb #12edf4e8
@call_parse
def plot_histograms(
path: str, # path for embeddings
Expand Down Expand Up @@ -343,10 +345,10 @@ def plot_histograms(
print(f"Done plotting {title}.png")


# %% ../nbs/03_heatmaps_novels.ipynb 13
# %% ../nbs/03_heatmaps_novels.ipynb #b80c8a10
import pandas as pd

# %% ../nbs/03_heatmaps_novels.ipynb 14
# %% ../nbs/03_heatmaps_novels.ipynb #57b04ae7
@call_parse
def ssms_from_pkl(
path: str, # path for pkl file
Expand Down Expand Up @@ -393,7 +395,7 @@ def ssms_from_pkl(
plt.clf()


# %% ../nbs/03_heatmaps_novels.ipynb 15
# %% ../nbs/03_heatmaps_novels.ipynb #1d8809d3
@call_parse
def corr_heatmaps(
path: str, # path for embeddings
Expand Down Expand Up @@ -480,7 +482,7 @@ def corr_heatmaps(
# plt.clf()


# %% ../nbs/03_heatmaps_novels.ipynb 16
# %% ../nbs/03_heatmaps_novels.ipynb #b9f81ea5
@call_parse
def corr_ts(
path: str, # path for embeddings
Expand All @@ -499,7 +501,7 @@ def corr_ts(
_plot(embedding_path, data, name)


# %% ../nbs/03_heatmaps_novels.ipynb 17
# %% ../nbs/03_heatmaps_novels.ipynb #f082e00b
@call_parse
def lex_ts(
path: str, # path for embeddings
Expand All @@ -523,7 +525,7 @@ def lex_ts(
print(len(z))


# %% ../nbs/03_heatmaps_novels.ipynb 18
# %% ../nbs/03_heatmaps_novels.ipynb #8f9a5f21
@call_parse
def plot_standardized(
path: str, # path for embeddings
Expand Down
16 changes: 9 additions & 7 deletions clean_plot/lexical.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
"""This file goes over generating lexical embeddings"""

# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/02_lexical.ipynb.

# %% auto 0
# %% auto #0
__all__ = ['interpolate', 'load_pmi', 'load_dictionary', 'write_to_file_lexical', 'process_v2']

# %% ../nbs/02_lexical.ipynb 3
# %% ../nbs/02_lexical.ipynb #a99648f1
import re
from . import *
import os
import unidecode
from collections import OrderedDict
from fastcore.all import *

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


# %% ../nbs/02_lexical.ipynb 7
# %% ../nbs/02_lexical.ipynb #7b6b4ad9
def load_pmi(path):
pmi = np.load(path)
return pmi


# %% ../nbs/02_lexical.ipynb 8
# %% ../nbs/02_lexical.ipynb #9ef07dfc
def load_dictionary(path):
fname = open(path, "rb")
data = pickle.load(fname)
return data


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


# %% ../nbs/02_lexical.ipynb 10
# %% ../nbs/02_lexical.ipynb #37e49d2d
def process_v2(fname):
all_data = get_data(fname)
all_data = unidecode.unidecode(all_data)
Expand Down
22 changes: 12 additions & 10 deletions clean_plot/pickle.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""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"""

# AUTOGENERATED! DO NOT EDIT! File to edit: ../nbs/01_pickle.ipynb.

# %% ../nbs/01_pickle.ipynb 2
# %% ../nbs/01_pickle.ipynb #cc0ae037
from __future__ import annotations
import os
import numpy as np
Expand All @@ -11,11 +13,11 @@
from fastcore.xtras import *
from fastcore.script import *

# %% auto 0
# %% auto #0
__all__ = ['label', 'cos_sim', 'successive_similarities', 'create_dict_whole_book', 'create_label_whole_book', 'create_label',
'get_embed_method_and_name']

# %% ../nbs/01_pickle.ipynb 4
# %% ../nbs/01_pickle.ipynb #01c70e33
def label(method: str): # name of the method
"""
Returns the full name of the model based on the abbreviation
Expand All @@ -41,7 +43,7 @@ def label(method: str): # name of the method
return switcher.get(method)


# %% ../nbs/01_pickle.ipynb 5
# %% ../nbs/01_pickle.ipynb #091b0d73
def cos_sim(
a: np.ndarray, # vector 1
b: np.ndarray, # vector 2
Expand All @@ -52,18 +54,18 @@ def cos_sim(
return dot(a, b) / (norm(a) * norm(b))


# %% ../nbs/01_pickle.ipynb 6
# %% ../nbs/01_pickle.ipynb #0463a325
from pathlib import Path

# %% ../nbs/01_pickle.ipynb 7
# %% ../nbs/01_pickle.ipynb #aad409d5
def successive_similarities(embeddings, k):
successive = []
for i in range(len(embeddings) - k):
successive.append(cos_sim(embeddings[i], embeddings[i + k]))
return successive


# %% ../nbs/01_pickle.ipynb 8
# %% ../nbs/01_pickle.ipynb #9b793316
@call_parse
def create_dict_whole_book(
embedding_path: str = ".", # path to the embeddings
Expand Down Expand Up @@ -128,7 +130,7 @@ def create_dict_whole_book(
print(f"Saved pkl at {new_path}")


# %% ../nbs/01_pickle.ipynb 9
# %% ../nbs/01_pickle.ipynb #4a217262
def create_label_whole_book(method, parent_dir):
# returns only the method name
return label(method)
Expand All @@ -137,13 +139,13 @@ def create_label_whole_book(method, parent_dir):
# return parent_dir.title() + ' ' + label(method)


# %% ../nbs/01_pickle.ipynb 10
# %% ../nbs/01_pickle.ipynb #c35ac5e6
def create_label(index, method, parent_dir):
met = label(method)
return "Book " + str(index + 1) + " " + parent_dir.title() + " " + met


# %% ../nbs/01_pickle.ipynb 11
# %% ../nbs/01_pickle.ipynb #bad8ed11
def get_embed_method_and_name(
fname, # name of the file
) -> (str, str): # name of file, embeddding method
Expand Down
16 changes: 9 additions & 7 deletions clean_plot/plot/utils.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
"""This module tries to include most of the plotting functionality available in the package"""

# AUTOGENERATED! DO NOT EDIT! File to edit: ../../nbs/04_plot.utils.ipynb.

# %% ../../nbs/04_plot.utils.ipynb 3
# %% ../../nbs/04_plot.utils.ipynb #b2cde59e
from __future__ import annotations
from fastcore.basics import store_attr, patch_to, patch
from fastcore.xtras import globtastic
Expand All @@ -16,16 +18,16 @@
import matplotlib.pyplot as plt
import gc

# %% auto 0
# %% auto #0
__all__ = ['Plot']

# %% ../../nbs/04_plot.utils.ipynb 4
# %% ../../nbs/04_plot.utils.ipynb #42232bac
sns.set_style(style="white")

# %% ../../nbs/04_plot.utils.ipynb 5
# %% ../../nbs/04_plot.utils.ipynb #d40153c2
import inspect

# %% ../../nbs/04_plot.utils.ipynb 6
# %% ../../nbs/04_plot.utils.ipynb #0c04e9eb
class Plot:
"Plotting module"

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


# %% ../../nbs/04_plot.utils.ipynb 7
# %% ../../nbs/04_plot.utils.ipynb #0f9376f0
@patch
def get_normalized(self: Plot):
"Returns the normalized ssms"
Expand Down Expand Up @@ -150,7 +152,7 @@ def get_normalized(self: Plot):
return self.norm


# %% ../../nbs/04_plot.utils.ipynb 8
# %% ../../nbs/04_plot.utils.ipynb #6ca425a9
@patch
def get_standardized(self: Plot):
"Returns the standardized ssms"
Expand Down
Loading
Loading