File size: 2,941 Bytes
06e9286
 
 
 
 
 
 
 
aeeec0d
 
06e9286
 
 
 
 
 
 
 
 
 
 
 
 
 
98c3feb
06e9286
98c3feb
 
 
 
9d37bcd
 
 
 
98c3feb
 
1c0c890
98c3feb
 
 
 
 
9d37bcd
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98c3feb
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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
61
import gradio as gr
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

tokenizer = AutoTokenizer.from_pretrained("impresso-project/nel-hipe-multilingual")
model = AutoModelForSeq2SeqLM.from_pretrained(
    "impresso-project/nel-hipe-multilingual"
).eval()

print("Model loaded successfully!")


def disambiguate_sentences(sentences):
    results = []
    for sentence in sentences:
        outputs = model.generate(
            **tokenizer([sentence], return_tensors="pt"),
            num_beams=5,
            num_return_sequences=5
        )
        decoded = tokenizer.batch_decode(outputs, skip_special_tokens=True)
        results.append(decoded)
    return results


demo = gr.Interface(
    fn=disambiguate_sentences,
    inputs=[
        gr.Textbox(
            label="Input Sentences:",
            lines=5,
            placeholder="Enter your sentence here in the following format: //  << We are going to [START] Paris [END]. >>"
            " // This format ensures that the model knows which entities to disambiguate, more exactly the "
            "entity should be surrounded by `[START]` and `[END]`. // "
            "!Only one entity per sentence is supported at the moment!",
        )
    ],
    outputs=[gr.Textbox(label="Predictions")],
    title="Entity Linking with impresso-project/nel-hipe-multilingual",
    description="Link entities using the `impresso-project/nel-hipe-multilingual` model under the hood!",
    allow_flagging="never",
    # Here we introduce a new tag, examples, easy to use examples for your application
    examples=[
        "Des chercheurs de l' [START] Université de Cambridge [END] ont développé une nouvelle technique de calcul "
        "quantique qui promet d'augmenter exponentiellement les vitesses de calcul.",
        "Le rapport complet sur ces découvertes a été publié dans la prestigieuse revue 'Nature Physics'. ([START] "
        "Reuters [END])",
        "In the [START] year 1789 [END], the Estates-General was convened in France.",
        "[START] King Louis XVI, ruler of France [END], called for the meeting.",
        "The event was held at the [START] Palace of Versailles [END], a symbol of French monarchy.",
        "At Versailles, Marie Antoinette, the Queen of France, was involved in discussions.",
        "Maximilien Robespierre, a leading member of the National Assembly, also participated.",
        "[START] Jean-Jacques Rousseau, the famous philosopher [END], was a significant figure in the debate.",
        "Another important participant was [START] Charles de Talleyrand, the Bishop of Autun [END].",
        "Meanwhile, across the Atlantic, [START] George Washington, the first President of the United States [END], "
        "was shaping policies.",
        "[START] Thomas Jefferson, the nation's Secretary of State [END], played a key role in drafting policies for "
        "the new American government.",
    ],
)
demo.launch()