|
python -m venv .senseenv |
|
|
|
source .senseenv/bin/activate |
|
|
|
source .senseenv/bin/deactivate |
|
|
|
|
|
pip install -r requirements.txt |
|
pip install faiss-cpu |
|
|
|
|
|
python -m spacy download en_core_web_sm |
|
|
|
pip install gradio |
|
|
|
import sensegram |
|
from wsd import WSD |
|
from gensim.models import KeyedVectors |
|
|
|
|
|
sense_vectors_fpath = "./best_sense_gram_model/best_model.sense_vectors" |
|
word_vectors_fpath = "./best_sense_gram_model/best_model.word_vectors" |
|
|
|
|
|
max_context_words = 3 |
|
context_window_size = 5 |
|
ignore_case = True |
|
lang = "ar" |
|
|
|
|
|
sv = sensegram.SenseGram.load_word2vec_format(sense_vectors_fpath, binary=False) |
|
wv = KeyedVectors.load_word2vec_format(word_vectors_fpath, binary=False, unicode_errors="ignore") |
|
|
|
|
|
def wsd_method(word, context): |
|
output = "" |
|
output += "Probabilities of the senses:\n{}\n\n".format(sv.get_senses(word, ignore_case=ignore_case)) |
|
for sense_id, prob in sv.get_senses(word, ignore_case=ignore_case): |
|
output += sense_id |
|
output += ("\n"+"="*20+"\n") |
|
for rsense_id, sim in sv.wv.most_similar(sense_id): |
|
output += "{} {:f}\n".format(rsense_id, sim) |
|
output +="\n" |
|
|
|
wsd_model = WSD(sv, wv, window=context_window_size, lang=lang, |
|
max_context_words=max_context_words, ignore_case=ignore_case) |
|
output += str(wsd_model.disambiguate(context, word)) |
|
return output |
|
|
|
import gradio as gr |
|
|
|
demo = gr.Interface( |
|
fn=wsd_method, |
|
inputs=[gr.Textbox(lines=1, placeholder="الكلمة"),gr.Textbox(lines=2, placeholder="السياق")], |
|
outputs="text", |
|
title="فـك الالتباس الدلالي", |
|
description="فضلًا أدخل الكلمة ثم السياق ثم اضغط على زر إرسال، ولاستعراض المخرجات كاملة يرجى استخدام زر التمرير لأسفل.", |
|
) |
|
demo.launch() |
|
|
|
|