-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrun_translation.txt
More file actions
33 lines (22 loc) · 1.8 KB
/
run_translation.txt
File metadata and controls
33 lines (22 loc) · 1.8 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
32
33
this time performing Machine Translation and explicitly using a model from the popular Helsinki-NLP collection.
We'll translate a sentence from English to French using a dedicated model fine-tuned for this language pair.
Prerequisites:
Ensure you have the necessary libraries. Helsinki-NLP models often use the sentencepiece tokenizer library.
Bash
pip install transformers sentencepiece torch
# Or: pip install transformers sentencepiece tensorflow
(Ensure your existing virtual environment is active).
Explicit Model Choice:
We will use Helsinki-NLP/opus-mt-en-fr, a model specifically trained for English-to-French translation, part of the OPUS-MT project which provides many high-quality translation models. These models are often quite efficient.
How to Run:
Make sure you've run pip install transformers sentencepiece torch (or the tensorflow equivalent) in your activated virtual environment.
Save the code above into a file named run_translation.py.
Open your Ubuntu terminal.
Make sure your virtual environment is activated (source .venv/bin/activate).
Run the script:
Bash
python run_translation.py
What to Expect:
First Run: It will download the Helsinki-NLP/opus-mt-en-fr model files. These models are usually more compact than BERT/BART large models (often a few hundred MB) and should download relatively quickly. The files will be cached locally.
Translation Execution: The model will process the input English sentence.
Output: It will print the original English text and then the resulting French translation generated by the model. For the example text, you should expect something like: "C'est un bel après-midi de vendredi ici à Perth, en Australie occidentale. Peut-être que j'irai me promener au bord de la rivière Swan plus tard aujourd'hui." (The exact wording might vary slightly based on the model version).