File size: 509 Bytes
cfdc0e6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
from transformers import pipeline

# Load the translation pipeline for English to French
translator = pipeline("translation_en_to_fr")

# Define the English text you want to translate
english_texts = [
    "Hello, how are you?",
    "I love learning new languages!",
    "Transformers make NLP tasks so easy."
]

# Translate each sentence
for text in english_texts:
    translated = translator(text)[0]['translation_text']
    print(f"English: {text}")
    print(f"French: {translated}\n")