added docstring and removed unnecessary imported modules
Browse files
plots.py
CHANGED
|
@@ -1,20 +1,26 @@
|
|
| 1 |
-
import streamlit as st
|
| 2 |
-
import matplotlib.pyplot as plt
|
| 3 |
-
import numpy as np
|
| 4 |
-
from mpl_toolkits.mplot3d import Axes3D
|
| 5 |
-
import umap
|
| 6 |
import pandas as pd
|
| 7 |
from word2vec import *
|
| 8 |
-
from sklearn.preprocessing import StandardScaler
|
| 9 |
import plotly.express as px
|
| 10 |
-
from sklearn.manifold import TSNE
|
| 11 |
import pickle
|
| 12 |
|
| 13 |
|
| 14 |
def make_3d_plot_tSNE(vectors_list, target_word, time_slice_model):
|
| 15 |
"""
|
| 16 |
-
|
| 17 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 18 |
"""
|
| 19 |
word = target_word
|
| 20 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
import pandas as pd
|
| 2 |
from word2vec import *
|
|
|
|
| 3 |
import plotly.express as px
|
|
|
|
| 4 |
import pickle
|
| 5 |
|
| 6 |
|
| 7 |
def make_3d_plot_tSNE(vectors_list, target_word, time_slice_model):
|
| 8 |
"""
|
| 9 |
+
Create a 3D plot using t-SNE and Plotly from a list of 100-dimensional vectors.
|
| 10 |
+
|
| 11 |
+
vectors_list: list of tuples containing (word, model_name, vector, cosine_sim)
|
| 12 |
+
- word: the word in the model
|
| 13 |
+
- model_name: the name of the model
|
| 14 |
+
- vector: the 100-dimensional vector representation of the word
|
| 15 |
+
- cosine_sim: the cosine similarity of the word to the target word
|
| 16 |
+
|
| 17 |
+
target_word: the word for which the nearest neighbours are calculated and plotted
|
| 18 |
+
|
| 19 |
+
time_slice_model: the time slice model name used to extract 3D vector representations
|
| 20 |
+
|
| 21 |
+
Return: a tuple containing:
|
| 22 |
+
- fig: the Plotly 3D scatter plot figure
|
| 23 |
+
- df: a pandas DataFrame containing the words, their 3D vectors, and cosine similarities
|
| 24 |
"""
|
| 25 |
word = target_word
|
| 26 |
|