Spaces:
Runtime error
Runtime error
Added empty app with tabs
Browse files- app.py +27 -0
- word2vec.py +34 -0
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import gradio as gr
|
2 |
+
from word2vec import *
|
3 |
+
|
4 |
+
|
5 |
+
with gr.Blocks() as demo:
|
6 |
+
gr.Markdown("# Welcome to Ancient Greek Word2Vec")
|
7 |
+
|
8 |
+
# Tab 1
|
9 |
+
with gr.Tab("Find nearest neighbours"):
|
10 |
+
gr.Markdown("## Find nearest neighbours")
|
11 |
+
|
12 |
+
# Tab 2
|
13 |
+
with gr.Tab("Cosine similarity"):
|
14 |
+
gr.Markdown("## Cosine similarity")
|
15 |
+
|
16 |
+
# Tab 3
|
17 |
+
with gr.Tab("3D graph"):
|
18 |
+
gr.Markdown("## 3D graph")
|
19 |
+
|
20 |
+
# Tab 4
|
21 |
+
with gr.Tab("Dictionary"):
|
22 |
+
gr.Markdown("## Dictionary")
|
23 |
+
|
24 |
+
|
25 |
+
|
26 |
+
if __name__ == "__main__":
|
27 |
+
demo.launch()
|
word2vec.py
ADDED
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from gensim.models import Word2Vec
|
2 |
+
|
3 |
+
def load_word2vec_model(model_path):
|
4 |
+
'''
|
5 |
+
Load a word2vec model from a file
|
6 |
+
'''
|
7 |
+
return Word2Vec.load(model_path)
|
8 |
+
|
9 |
+
def get_word_vector(model, word):
|
10 |
+
'''
|
11 |
+
Return the word vector of a word
|
12 |
+
'''
|
13 |
+
return model.wv[word]
|
14 |
+
|
15 |
+
def iterate_over_words(model):
|
16 |
+
'''
|
17 |
+
Iterate over all words in the vocabulary and print their vectors
|
18 |
+
'''
|
19 |
+
index = 0
|
20 |
+
for word, index in model.wv.key_to_index.items():
|
21 |
+
vector = get_word_vector(model, word)
|
22 |
+
print(f'{index} Word: {word}, Vector: {vector}')
|
23 |
+
index += 1
|
24 |
+
|
25 |
+
def main():
|
26 |
+
model = load_word2vec_model('../models/archaic_cbow.model')
|
27 |
+
vector = get_word_vector(model, 'ἀνήρ')
|
28 |
+
print(vector)
|
29 |
+
|
30 |
+
# Iterate over all words and print their vectors
|
31 |
+
iterate_over_words(model)
|
32 |
+
|
33 |
+
if __name__ == "__main__":
|
34 |
+
main()
|