🚀 French to English Text Translation with Transformers
This project enables French text translation to English using the ybanas/autotrain-fr-en-translate-51410121895
model from the Transformers library.
🚀 Quick Start
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:
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
tokenizer = AutoTokenizer.from_pretrained("ybanas/autotrain-fr-en-translate-51410121895")
model = AutoModelForSeq2SeqLM.from_pretrained("ybanas/autotrain-fr-en-translate-51410121895")
def translate_text(french_text: str) -> str:
"""
Translate French text to English using the ybanas/autotrain-fr-en-translate-51410121895 model.
Args:
french_text (str): French text to translate.
Returns:
str: Translated English text.
"""
inputs = tokenizer(french_text, return_tensors="pt", padding=True, truncation=True)
outputs = model.generate(**inputs)
english_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
return english_text
if __name__ == "__main__":
french_text = "Les enfants aiment profiter des beaux jours"
english_text = translate_text(french_text)
print("French text:", french_text)
print("Translated English text:", english_text)
💻 Usage Examples
Basic Usage
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
tokenizer = AutoTokenizer.from_pretrained("ybanas/autotrain-fr-en-translate-51410121895")
model = AutoModelForSeq2SeqLM.from_pretrained("ybanas/autotrain-fr-en-translate-51410121895")
def translate_text(french_text: str) -> str:
"""
Translate French text to English using the ybanas/autotrain-fr-en-translate-51410121895 model.
Args:
french_text (str): French text to translate.
Returns:
str: Translated English text.
"""
inputs = tokenizer(french_text, return_tensors="pt", padding=True, truncation=True)
outputs = model.generate(**inputs)
english_text = tokenizer.decode(outputs[0], skip_special_tokens=True)
return english_text
if __name__ == "__main__":
french_text = "Les enfants aiment profiter des beaux jours"
english_text = translate_text(french_text)
print("French text:", french_text)
print("Translated English text:", english_text)
📦 Installation
- Install the Transformers library by running
pip install transformers
.
- Copy the code above into a
.py
file, for example translation.py
.
- Replace the value of the
french_text
variable with the French text you want to translate.
- Run the script with
python translation.py
. The translated English text will be displayed on the screen.
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.
📚 Documentation
Model Trained Using AutoTrain
Property |
Details |
Problem Type |
Translation |
Model ID |
51410121895 |
CO2 Emissions (in grams) |
86.9058 |
Validation Metrics
Metric |
Value |
Loss |
1.455 |
SacreBLEU |
15.999 |
Gen len |
15.299 |