Spaces:
Sleeping
Sleeping
Gabriela Nicole Gonzalez Saez
commited on
Commit
·
9221f9f
1
Parent(s):
056bbdc
fix error
Browse files- __pycache__/bertviz_gradio.cpython-310.pyc +0 -0
- app.py +57 -0
__pycache__/bertviz_gradio.cpython-310.pyc
ADDED
Binary file (6.54 kB). View file
|
|
app.py
CHANGED
@@ -20,6 +20,63 @@ from bertviz import model_view, head_view
|
|
20 |
from bertviz_gradio import head_view_mod
|
21 |
|
22 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
def get_bertvis_data(input_text, lg_model):
|
24 |
tokenizer_tr = dict_tokenizer_tr[lg_model]
|
25 |
model_tr = dict_models_tr[lg_model]
|
|
|
20 |
from bertviz_gradio import head_view_mod
|
21 |
|
22 |
|
23 |
+
|
24 |
+
model_es = "Helsinki-NLP/opus-mt-en-es"
|
25 |
+
model_fr = "Helsinki-NLP/opus-mt-en-fr"
|
26 |
+
model_zh = "Helsinki-NLP/opus-mt-en-zh"
|
27 |
+
|
28 |
+
tokenizer_es = AutoTokenizer.from_pretrained(model_es)
|
29 |
+
tokenizer_fr = AutoTokenizer.from_pretrained(model_fr)
|
30 |
+
tokenizer_zh = AutoTokenizer.from_pretrained(model_zh)
|
31 |
+
|
32 |
+
model_tr_es = MarianMTModel.from_pretrained(model_es)
|
33 |
+
model_tr_fr = MarianMTModel.from_pretrained(model_fr)
|
34 |
+
model_tr_zh = MarianMTModel.from_pretrained(model_zh)
|
35 |
+
|
36 |
+
model_es = inseq.load_model("Helsinki-NLP/opus-mt-en-es", "input_x_gradient")
|
37 |
+
model_fr = inseq.load_model("Helsinki-NLP/opus-mt-en-fr", "input_x_gradient")
|
38 |
+
model_zh = inseq.load_model("Helsinki-NLP/opus-mt-en-zh", "input_x_gradient")
|
39 |
+
|
40 |
+
|
41 |
+
dict_models = {
|
42 |
+
'en-es': model_es,
|
43 |
+
'en-fr': model_fr,
|
44 |
+
'en-zh': model_zh,
|
45 |
+
}
|
46 |
+
|
47 |
+
dict_models_tr = {
|
48 |
+
'en-es': model_tr_es,
|
49 |
+
'en-fr': model_tr_fr,
|
50 |
+
'en-zh': model_tr_zh,
|
51 |
+
}
|
52 |
+
|
53 |
+
dict_tokenizer_tr = {
|
54 |
+
'en-es': tokenizer_es,
|
55 |
+
'en-fr': tokenizer_fr,
|
56 |
+
'en-zh': tokenizer_zh,
|
57 |
+
}
|
58 |
+
|
59 |
+
saliency_examples = [
|
60 |
+
"Peace of Mind: Protection for consumers.",
|
61 |
+
"The sustainable development goals report: towards a rescue plan for people and planet",
|
62 |
+
"We will leave no stone unturned to hold those responsible to account.",
|
63 |
+
"The clock is now ticking on our work to finalise the remaining key legislative proposals presented by this Commission to ensure that citizens and businesses can reap the benefits of our policy actions.",
|
64 |
+
"Pumpkins, squash and gourds, fresh or chilled, excluding courgettes",
|
65 |
+
"The labour market participation of mothers with infants has even deteriorated over the past two decades, often impacting their career and incomes for years.",
|
66 |
+
]
|
67 |
+
|
68 |
+
contrastive_examples = [
|
69 |
+
["Peace of Mind: Protection for consumers.",
|
70 |
+
"Paz mental: protección de los consumidores",
|
71 |
+
"Paz de la mente: protección de los consumidores"],
|
72 |
+
["the slaughterer has finished his work.",
|
73 |
+
"l'abatteur a terminé son travail.",
|
74 |
+
"l'abatteuse a terminé son travail."],
|
75 |
+
['A fundamental shift is needed - in commitment, solidarity, financing and action - to put the world on a better path.',
|
76 |
+
'需要在承诺、团结、筹资和行动方面进行根本转变,使世界走上更美好的道路。',
|
77 |
+
'我们需要从根本上转变承诺、团结、资助和行动,使世界走上更美好的道路。',]
|
78 |
+
]
|
79 |
+
|
80 |
def get_bertvis_data(input_text, lg_model):
|
81 |
tokenizer_tr = dict_tokenizer_tr[lg_model]
|
82 |
model_tr = dict_models_tr[lg_model]
|