Spaces:
Build error
Build error
Update app.py
Browse files
app.py
CHANGED
|
@@ -14,9 +14,9 @@ def get_bert_embeddings(words):
|
|
| 14 |
for word in words:
|
| 15 |
inputs = tokenizer(word, return_tensors='pt')
|
| 16 |
outputs = model(**inputs)
|
| 17 |
-
#
|
| 18 |
-
|
| 19 |
-
embeddings.append(
|
| 20 |
|
| 21 |
if len(embeddings) > 0:
|
| 22 |
pca = PCA(n_components=3)
|
|
@@ -25,6 +25,7 @@ def get_bert_embeddings(words):
|
|
| 25 |
return []
|
| 26 |
|
| 27 |
|
|
|
|
| 28 |
# Plotly plotting function
|
| 29 |
def plot_interactive_bert_embeddings(embeddings, words):
|
| 30 |
if len(words) < 4:
|
|
|
|
| 14 |
for word in words:
|
| 15 |
inputs = tokenizer(word, return_tensors='pt')
|
| 16 |
outputs = model(**inputs)
|
| 17 |
+
# Calculate mean of embeddings across all tokens in the phrase
|
| 18 |
+
mean_embedding = outputs.last_hidden_state[0].mean(dim=0).detach().numpy()
|
| 19 |
+
embeddings.append(mean_embedding)
|
| 20 |
|
| 21 |
if len(embeddings) > 0:
|
| 22 |
pca = PCA(n_components=3)
|
|
|
|
| 25 |
return []
|
| 26 |
|
| 27 |
|
| 28 |
+
|
| 29 |
# Plotly plotting function
|
| 30 |
def plot_interactive_bert_embeddings(embeddings, words):
|
| 31 |
if len(words) < 4:
|