Update README.md
Browse files
README.md
CHANGED
@@ -24,9 +24,13 @@ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
|
|
24 |
max_length = 100
|
25 |
src_lang = 'eng_Latn'
|
26 |
tgt_lang = 'deu_Latn'
|
27 |
-
context_text = 'This is an optional context sentence.'
|
28 |
sentence_text = 'Text to be translated.'
|
|
|
|
|
29 |
input_text = f'{context_text} {tokenizer.sep_token} {sentence_text}'
|
|
|
|
|
30 |
|
31 |
tokenizer.src_lang = src_lang
|
32 |
inputs = tokenizer(input_text, return_tensors='pt').to(model.device)
|
@@ -46,9 +50,14 @@ model_name = 'voxreality/src_ctx_aware_nllb_1.3B'
|
|
46 |
translation_pipeline = pipeline("translation", model=model_name)
|
47 |
src_lang = 'eng_Latn'
|
48 |
tgt_lang = 'deu_Latn'
|
49 |
-
context_text = 'This is an optional context sentence.'
|
50 |
sentence_text = 'Text to be translated.'
|
51 |
-
|
|
|
|
|
|
|
|
|
|
|
52 |
|
53 |
pipeline_output = translation_pipeline(input_texts, src_lang=src_lang, tgt_lang=tgt_lang)
|
54 |
|
|
|
24 |
max_length = 100
|
25 |
src_lang = 'eng_Latn'
|
26 |
tgt_lang = 'deu_Latn'
|
27 |
+
context_text = 'This is an optional context sentence.'
|
28 |
sentence_text = 'Text to be translated.'
|
29 |
+
|
30 |
+
# if the context is provided use the following:
|
31 |
input_text = f'{context_text} {tokenizer.sep_token} {sentence_text}'
|
32 |
+
# if no context is provided use the following:
|
33 |
+
# input_text = sentence_text
|
34 |
|
35 |
tokenizer.src_lang = src_lang
|
36 |
inputs = tokenizer(input_text, return_tensors='pt').to(model.device)
|
|
|
50 |
translation_pipeline = pipeline("translation", model=model_name)
|
51 |
src_lang = 'eng_Latn'
|
52 |
tgt_lang = 'deu_Latn'
|
53 |
+
context_text = 'This is an optional context sentence.'
|
54 |
sentence_text = 'Text to be translated.'
|
55 |
+
|
56 |
+
# if the context is provided use the following:
|
57 |
+
input_texts = [f'{context_text} {tokenizer.sep_token} {sentence_text}']
|
58 |
+
# if no context is provided use the following:
|
59 |
+
# input_texts = [sentence_text]
|
60 |
+
|
61 |
|
62 |
pipeline_output = translation_pipeline(input_texts, src_lang=src_lang, tgt_lang=tgt_lang)
|
63 |
|