Pawel-M commited on
Commit
c093256
1 Parent(s): 692de29

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +10 -3
README.md CHANGED
@@ -24,9 +24,12 @@ 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.' # use '' empty string if not context should be used
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 +49,13 @@ model_name = 'voxreality/src_ctx_aware_nllb_600M'
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.' # use '' empty string if not context should be used
50
  sentence_text = 'Text to be translated.'
51
- input_texts = [f'{context_text} {translation_pipeline.tokenizer.sep_token} {sentence_text}']
 
 
 
 
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
+ # if the context is provided use the following:
30
  input_text = f'{context_text} {tokenizer.sep_token} {sentence_text}'
31
+ # if no context is provided use the following:
32
+ # input_text = sentence_text
33
 
34
  tokenizer.src_lang = src_lang
35
  inputs = tokenizer(input_text, return_tensors='pt').to(model.device)
 
49
  translation_pipeline = pipeline("translation", model=model_name)
50
  src_lang = 'eng_Latn'
51
  tgt_lang = 'deu_Latn'
52
+ context_text = 'This is an optional context sentence.'
53
  sentence_text = 'Text to be translated.'
54
+ # if the context is provided use the following:
55
+ input_texts = [f'{context_text} {tokenizer.sep_token} {sentence_text}']
56
+ # if no context is provided use the following:
57
+ # input_texts = [sentence_text]
58
+
59
 
60
  pipeline_output = translation_pipeline(input_texts, src_lang=src_lang, tgt_lang=tgt_lang)
61