Views
No views yet
| Training Loss | Epoch | Step | Validation Loss | Bleu | Gen Len |
|---|---|---|---|---|---|
| 2.2391 | 0.18 | 1000 | 1.9921 | 7.4066 | 16.377 |
| 1.8436 | 0.36 | 2000 | 1.6756 | 9.3443 | 18.428 |
| 1.63 | 0.53 | 3000 | 1.5361 | 10.9057 | 17.134 |
| 1.5205 | 0.71 | 4000 | 1.3994 | 12.6061 | 17.471 |
| 1.4471 | 0.89 | 5000 | 1.3107 | 14.4452 | 16.985 |
| 1.1915 | 1.07 | 6000 | 1.2462 | 15.1903 | 16.544 |
| 1.1165 | 1.25 | 7000 | 1.1917 | 16.3859 | 17.044 |
| 1.0654 | 1.43 | 8000 | 1.1351 | 17.617 | 16.481 |
| 1.0464 | 1.6 | 9000 | 1.0939 | 18.649 | 16.517 |
| 1.0376 | 1.78 | 10000 | 1.0603 | 18.2567 | 17.152 |
| 1.0027 | 1.96 | 11000 | 1.0184 | 20.6011 | 16.875 |
| 0.7741 | 2.14 | 12000 | 1.0159 | 20.4801 | 16.488 |
| 0.7566 | 2.32 | 13000 | 0.9899 | 21.6967 | 16.681 |
| 0.7346 | 2.49 | 14000 | 0.9738 | 21.8249 | 16.679 |
| 0.7397 | 2.67 | 15000 | 0.9555 | 21.569 | 16.608 |
| 0.6919 | 2.85 | 16000 | 0.9441 | 22.4658 | 16.493 |
pip install transformers sentencepiece torch ctranslate21from huggingface_hub import hf_hub_download
2
3hf_hub_download(repo_id='anzorq/m2m100_418M_ft_ru-kbd_44K', subfolder='ctranslate2', filename='config.json', local_dir='./')
4hf_hub_download(repo_id='anzorq/m2m100_418M_ft_ru-kbd_44K', subfolder='ctranslate2', filename='model.bin', local_dir='./')
5hf_hub_download(repo_id='anzorq/m2m100_418M_ft_ru-kbd_44K', subfolder='ctranslate2', filename='sentencepiece.bpe.model', local_dir='./')
6hf_hub_download(repo_id='anzorq/m2m100_418M_ft_ru-kbd_44K', subfolder='ctranslate2', filename='shared_vocabulary.json', local_dir='./')1import ctranslate2
2import transformers
3
4translator = ctranslate2.Translator("ctranslate2") # Ensure correct path to the ctranslate2 model directory
5tokenizer = transformers.AutoTokenizer.from_pretrained("anzorq/m2m100_418M_ft_ru-kbd_44K")
6tgt_lang="zu"
7
8def translate(text, num_beams=4, num_return_sequences=4):
9 num_return_sequences = min(num_return_sequences, num_beams)
10
11 source = tokenizer.convert_ids_to_tokens(tokenizer.encode(text))
12 target_prefix = [tokenizer.lang_code_to_token[tgt_lang]]
13 results = translator.translate_batch(
14 [source],
15 target_prefix=[target_prefix],
16 beam_size=num_beams,
17 num_hypotheses=num_return_sequences
18 )
19
20 translations = []
21 for hypothesis in results[0].hypotheses:
22 target = hypothesis[1:]
23 decoded_sentence = tokenizer.decode(tokenizer.convert_tokens_to_ids(target))
24 translations.append(decoded_sentence)
25
26 return text, translations
27
28# Test the translation
29text = "Текст для перевода"
30print(translate(text))pip install transformers sentencepiece1from transformers import AutoModelForSeq2SeqLM, AutoTokenizer
2
3model_path = "anzorq/m2m100_418M_ft_ru-kbd_44K"
4tgt_lang="zu"
5
6tokenizer = AutoTokenizer.from_pretrained(model_path)
7model = AutoModelForSeq2SeqLM.from_pretrained(model_path)
8
9def translate(text, num_beams=4, num_return_sequences=4):
10 inputs = tokenizer(text, return_tensors="pt")
11 num_return_sequences = min(num_return_sequences, num_beams)
12
13 translated_tokens = model.generate(
14 **inputs, forced_bos_token_id=tokenizer.lang_code_to_id[tgt_lang], num_beams=num_beams, num_return_sequences=num_return_sequences
15 )
16
17 translations = [tokenizer.decode(translation, skip_special_tokens=True) for translation in translated_tokens]
18 return text, translations
19
20# Test the translation
21text = "Текст для перевода"
22print(translate(text))