word_embeddings / app.py
felipekitamura's picture
Create app.py
7b42f20 verified
raw
history blame
800 Bytes
import gensim.downloader
import gradio as gr
model = gensim.downloader.load("glove-wiki-gigaword-50")
description = """
### Word Embedding Demo App
Universidade Federal de São Paulo - Escola Paulista de Medicina
The output is Word3 + (Word2 - Word1)
Credits:
* Gensim
* Glove
"""
Word1 = gr.Textbox()
Word2 = gr.Textbox()
Word3 = gr.Textbox()
label = gr.Label(show_label=True, label="Word4")
def inference(word1, word2, word3):
return model.similar_by_vector(model[word3] + model[word2] - model[word1])
examples = [
["woman", "man", "aunt"],
["woman", "man", "girl"],
["woman", "man", "granddaughter"],
]
iface = gr.Interface(
fn=inference,
inputs=[Word1, Word2, Word3],
outputs=label,
description=description,
examples=examples
)
iface.launch()