Spaces:
Sleeping
Sleeping
Upload app.py
Browse files
app.py
CHANGED
@@ -7,7 +7,6 @@ from langdetect import detect, DetectorFactory
|
|
7 |
import numpy as np
|
8 |
import matplotlib.pyplot as plt
|
9 |
import pandas as pd
|
10 |
-
import torch
|
11 |
|
12 |
st.set_page_config(page_title="Multilingual Text Analysis System", layout="wide")
|
13 |
|
@@ -59,7 +58,9 @@ def detect_language(text):
|
|
59 |
|
60 |
@st.cache_data
|
61 |
def tsne_visualization(embeddings, words):
|
62 |
-
|
|
|
|
|
63 |
embeddings_2d = tsne.fit_transform(embeddings)
|
64 |
df = pd.DataFrame(embeddings_2d, columns=['x', 'y'])
|
65 |
df['word'] = words
|
|
|
7 |
import numpy as np
|
8 |
import matplotlib.pyplot as plt
|
9 |
import pandas as pd
|
|
|
10 |
|
11 |
st.set_page_config(page_title="Multilingual Text Analysis System", layout="wide")
|
12 |
|
|
|
58 |
|
59 |
@st.cache_data
|
60 |
def tsne_visualization(embeddings, words):
|
61 |
+
n_samples = len(embeddings)
|
62 |
+
perplexity = min(30, n_samples - 1) # Ensure perplexity is less than the number of samples
|
63 |
+
tsne = TSNE(n_components=2, perplexity=perplexity, random_state=42)
|
64 |
embeddings_2d = tsne.fit_transform(embeddings)
|
65 |
df = pd.DataFrame(embeddings_2d, columns=['x', 'y'])
|
66 |
df['word'] = words
|