Commit
·
94113a9
1
Parent(s):
aeeec0d
update app
Browse files
app.py
CHANGED
@@ -9,9 +9,9 @@ model = AutoModelForSeq2SeqLM.from_pretrained(
|
|
9 |
print("Model loaded successfully!")
|
10 |
|
11 |
|
12 |
-
def
|
13 |
results = []
|
14 |
-
for sentence in
|
15 |
outputs = model.generate(
|
16 |
**tokenizer([sentence], return_tensors="pt"),
|
17 |
num_beams=5,
|
@@ -22,39 +22,47 @@ def disambiguate_sentences(sentences):
|
|
22 |
return results
|
23 |
|
24 |
|
25 |
-
|
26 |
-
|
27 |
-
|
28 |
-
|
29 |
-
|
30 |
-
|
31 |
-
|
32 |
-
|
33 |
-
|
34 |
-
|
35 |
-
|
36 |
-
|
37 |
-
|
38 |
-
|
39 |
-
|
40 |
-
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
|
60 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
9 |
print("Model loaded successfully!")
|
10 |
|
11 |
|
12 |
+
def disambiguate_sentence(sentence):
|
13 |
results = []
|
14 |
+
for sentence in [sentence]:
|
15 |
outputs = model.generate(
|
16 |
**tokenizer([sentence], return_tensors="pt"),
|
17 |
num_beams=5,
|
|
|
22 |
return results
|
23 |
|
24 |
|
25 |
+
def nel_app_interface():
|
26 |
+
input_sentence = gr.Textbox(
|
27 |
+
lines=5,
|
28 |
+
label="Input Sentence",
|
29 |
+
placeholder="Enter your sentence here in the following format: // << We are going to [START] Paris [END]. >>"
|
30 |
+
" // This format ensures that the model knows which entities to disambiguate, more exactly the "
|
31 |
+
"entity should be surrounded by `[START]` and `[END]`. // "
|
32 |
+
"!Only one entity per sentence is supported at the moment!",
|
33 |
+
)
|
34 |
+
output_entities = gr.HighlightedText(label="Extracted Entities")
|
35 |
+
|
36 |
+
# Interface definition
|
37 |
+
interface = gr.Interface(
|
38 |
+
fn=disambiguate_sentence,
|
39 |
+
inputs=input_sentence,
|
40 |
+
outputs=output_entities,
|
41 |
+
title="Entity Linking with impresso-project/nel-hipe-multilingual",
|
42 |
+
description="Link entities using the `impresso-project/nel-hipe-multilingual` model under the hood!",
|
43 |
+
examples=[
|
44 |
+
[
|
45 |
+
"Des chercheurs de l' [START] Université de Cambridge [END] ont développé une nouvelle technique de calcul "
|
46 |
+
"quantique qui promet d'augmenter exponentiellement les vitesses de calcul.",
|
47 |
+
"Le rapport complet sur ces découvertes a été publié dans la prestigieuse revue 'Nature Physics'. ([START] "
|
48 |
+
"Reuters [END])",
|
49 |
+
"In the [START] year 1789 [END], the Estates-General was convened in France.",
|
50 |
+
"[START] King Louis XVI, ruler of France [END], called for the meeting.",
|
51 |
+
"The event was held at the [START] Palace of Versailles [END], a symbol of French monarchy.",
|
52 |
+
"At Versailles, Marie Antoinette, the Queen of France, was involved in discussions.",
|
53 |
+
"Maximilien Robespierre, a leading member of the National Assembly, also participated.",
|
54 |
+
"[START] Jean-Jacques Rousseau, the famous philosopher [END], was a significant figure in the debate.",
|
55 |
+
"Another important participant was [START] Charles de Talleyrand, the Bishop of Autun [END].",
|
56 |
+
"Meanwhile, across the Atlantic, [START] George Washington, the first President of the United States [END], "
|
57 |
+
"was shaping policies.",
|
58 |
+
"[START] Thomas Jefferson, the nation's Secretary of State [END], played a key role in drafting policies for "
|
59 |
+
"the new American government.",
|
60 |
+
]
|
61 |
+
],
|
62 |
+
)
|
63 |
+
|
64 |
+
interface.launch()
|
65 |
+
|
66 |
+
|
67 |
+
if __name__ == "__main__":
|
68 |
+
nel_app_interface()
|