update readme
Browse files
README.md
CHANGED
@@ -10,6 +10,53 @@ datasets:
|
|
10 |
co2_eq_emissions:
|
11 |
emissions: 86.90578464498235
|
12 |
---
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
13 |
|
14 |
# Model Trained Using AutoTrain
|
15 |
|
|
|
10 |
co2_eq_emissions:
|
11 |
emissions: 86.90578464498235
|
12 |
---
|
13 |
+
# French to English Text Translation with Transformers
|
14 |
+
|
15 |
+
This code allows you to translate French text into English using the `ybanas/autotrain-fr-en-translate-51410121895` model from the Transformers library. To use this code, follow the steps below:
|
16 |
+
|
17 |
+
```python
|
18 |
+
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
|
19 |
+
|
20 |
+
# Load the tokenizer and the model
|
21 |
+
tokenizer = AutoTokenizer.from_pretrained("ybanas/autotrain-fr-en-translate-51410121895")
|
22 |
+
model = AutoModelForSeq2SeqLM.from_pretrained("ybanas/autotrain-fr-en-translate-51410121895")
|
23 |
+
|
24 |
+
def translate_text(french_text: str) -> str:
|
25 |
+
"""
|
26 |
+
Translate French text to English using the ybanas/autotrain-fr-en-translate-51410121895 model.
|
27 |
+
|
28 |
+
Args:
|
29 |
+
french_text (str): French text to translate.
|
30 |
+
|
31 |
+
Returns:
|
32 |
+
str: Translated English text.
|
33 |
+
"""
|
34 |
+
# Tokenize the French text
|
35 |
+
inputs = tokenizer(french_text, return_tensors="pt", padding=True, truncation=True)
|
36 |
+
|
37 |
+
# Generate the English translation
|
38 |
+
outputs = model.generate(**inputs)
|
39 |
+
|
40 |
+
# Decode the English translation
|
41 |
+
english_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
42 |
+
|
43 |
+
return english_text
|
44 |
+
|
45 |
+
if __name__ == "__main__":
|
46 |
+
french_text = "Les enfants aiment profiter des beaux jours"
|
47 |
+
english_text = translate_text(french_text)
|
48 |
+
print("French text:", french_text)
|
49 |
+
print("Translated English text:", english_text)
|
50 |
+
```
|
51 |
+
|
52 |
+
## Usage
|
53 |
+
|
54 |
+
1. Install the Transformers library by running `pip install transformers`.
|
55 |
+
2. Copy the code above into a `.py` file, for example `translation.py`.
|
56 |
+
3. Replace the value of the `french_text` variable with the French text you want to translate.
|
57 |
+
4. Run the script with `python translation.py`. The translated English text will be displayed on the screen.
|
58 |
+
|
59 |
+
This script uses the `ybanas/autotrain-fr-en-translate-51410121895` model to translate French text into English. The model is loaded using the `AutoTokenizer` and `AutoModelForSeq2SeqLM` classes from the Transformers library. The `translate_text` function takes a French text as input and returns its translation in English.
|
60 |
|
61 |
# Model Trained Using AutoTrain
|
62 |
|