Pawel-M commited on
Commit
24fbbc4
1 Parent(s): 2c53a59

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +57 -0
README.md ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ - de
5
+ - nl
6
+ - it
7
+ - el
8
+ - es
9
+ pipeline_tag: translation
10
+ ---
11
+ The model and the tokenizer are based on [facebook/nllb-200-1.3B]( https://huggingface.co/facebook/nllb-200-1.3B).
12
+
13
+ We trained the model to use one sentence of context. The context is prepended to the input sentence with the `sep_token` in between. We used a subset of the [OpenSubtitles2018]( https://huggingface.co/datasets/open_subtitles) dataset for training. We trained on the interleaved dataset for all directions between the following languages: English, German, Dutch, Spanish, Italian, and Greek.
14
+
15
+ The tokenizer of the base model was not changed. For the language codes, see the base model.
16
+
17
+ Use this code for translation:
18
+ ``` from transformers import AutoTokenizer, AutoModelForSeq2SeqLM
19
+
20
+ model_name = 'voxreality/src_ctx_aware_nllb_1.3B'
21
+ tokenizer = AutoTokenizer.from_pretrained(model_name)
22
+ model = AutoModelForSeq2SeqLM.from_pretrained(model_name)
23
+
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)
33
+ model_output = model.generate(**inputs,
34
+ forced_bos_token_id=tokenizer.lang_code_to_id[tgt_lang],
35
+ max_length=max_length)
36
+ output_text = tokenizer.batch_decode(model_output, skip_special_tokens=True)[0]
37
+
38
+ print(output_text)
39
+ ```
40
+
41
+ You can also use the pipeline
42
+ ```
43
+ from transformers import pipeline
44
+
45
+ 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.' # 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
+
55
+ print(pipeline_output[0]['translation_text'])
56
+
57
+ ```