-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathseq2seq_translation.py
More file actions
31 lines (24 loc) · 1.02 KB
/
seq2seq_translation.py
File metadata and controls
31 lines (24 loc) · 1.02 KB
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
from asyncio import run
from avalan.entities import GenerationSettings
from avalan.model.nlp.sequence import TranslationModel
async def example() -> None:
print("Loading model... ", end="", flush=True)
with TranslationModel("facebook/mbart-large-50-many-to-many-mmt") as t:
print("DONE.", flush=True)
text = """
Lionel Messi, commonly known as Leo Messi, is an Argentine
professional footballer who plays as a forward for the Argentina
national team. Regarded by many as the greatest footballer of all
time, Messi has achieved unparalleled success throughout his career.
"""
translation = await t(
text,
source_language="en_US",
destination_language="es_XX",
settings=GenerationSettings(num_beams=4, max_length=512),
)
print(" ".join([line.strip() for line in text.splitlines()]).strip())
print("-" * 12)
print(translation)
if __name__ == "__main__":
run(example())