try on GPU
Browse files- translation.py +30 -0
translation.py
ADDED
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
from transformers import pipeline
|
2 |
+
|
3 |
+
model_checkpoint = "Helsinki-NLP/opus-mt-en-fr"
|
4 |
+
translator = pipeline("translation", model=model_checkpoint)
|
5 |
+
# print(translator("how old are you"))
|
6 |
+
|
7 |
+
########################################################################################
|
8 |
+
|
9 |
+
from transformers import AutoTokenizer, AutoModelWithLMHead, TranslationPipeline
|
10 |
+
|
11 |
+
pipeline = TranslationPipeline(
|
12 |
+
model=AutoModelWithLMHead.from_pretrained("SEBIS/legal_t5_small_trans_fr_en"),
|
13 |
+
tokenizer=AutoTokenizer.from_pretrained(pretrained_model_name_or_path =
|
14 |
+
"SEBIS/legal_t5_small_trans_fr_en", do_lower_case=False, skip_special_tokens=True), device=0)
|
15 |
+
|
16 |
+
fr_text = "salut, comment vas-tu ?"
|
17 |
+
|
18 |
+
translator2 = pipeline([fr_text], max_length=512)
|
19 |
+
|
20 |
+
print(translator2)
|
21 |
+
|
22 |
+
########################################################################################
|
23 |
+
responseBase = "this is the second test"
|
24 |
+
|
25 |
+
def englishtofrench():
|
26 |
+
print(translator(responseBase))
|
27 |
+
return translator(responseBase)
|
28 |
+
|
29 |
+
englishtofrench()
|
30 |
+
|