File size: 2,446 Bytes
9b8e9c4
 
 
 
 
 
 
 
 
 
 
 
eac54a0
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9b8e9c4
 
 
 
 
 
 
 
 
 
 
 
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
---
tags:
- autotrain
- translation
language:
- fr
- en
datasets:
- ybanas/autotrain-data-fr-en-translate
co2_eq_emissions:
  emissions: 86.90578464498235
---
# French to English Text Translation with Transformers

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:

```python
from transformers import AutoTokenizer, AutoModelForSeq2SeqLM

# Load the tokenizer and the model
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.
    """
    # Tokenize the French text
    inputs = tokenizer(french_text, return_tensors="pt", padding=True, truncation=True)

    # Generate the English translation
    outputs = model.generate(**inputs)

    # Decode the English translation
    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

1. Install the Transformers library by running `pip install transformers`.
2. Copy the code above into a `.py` file, for example `translation.py`.
3. Replace the value of the `french_text` variable with the French text you want to translate.
4. 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.

# Model Trained Using AutoTrain

- Problem type: Translation
- Model ID: 51410121895
- CO2 Emissions (in grams): 86.9058

## Validation Metrics

- Loss: 1.455
- SacreBLEU: 15.999
- Gen len: 15.299