huggingface / huggingface/transformers

Problem about using mBART50 for Russian to Chinese translation

Open
#13,116 10 comments 0 reactions 1 assignee Claimed by @patil-suraj View on GitHub
WIP
Dominant language
Python
Stars
166k
Forks
34.6k
Avg merge
3d 9h
Merged PRs (30d)
281

Description

## Environment info

- `transformers` version: 4.9.1
- Platform: ubuntu 18.04
- Python version: 3.6.9.
- PyTorch version (GPU?): 1.8.0
- Tensorflow version (GPU?): 2.3.0
- Using GPU in script?: yes
- Using distributed or parallel set-up in script?: no

### Who can help

mbart-large-50-many-to-many-mmt:@LysandreJik @patrickvonplaten

## Information

Model I am using: mbart-large-50-many-to-many-mmt

The problem arises when using:

* my own modified scripts: (give details below)

We originally wanted to do a Russian-Chinese translation task, but our translation results showed a lot of English. We used a script to test.

## To reproduce

Steps to reproduce the behavior:

1.The code is as follow:
```python
from transformers import MBartForConditionalGeneration, MBart50TokenizerFast

text_list = ['Это позволит облегчить транспортировку грузов для Китая и Германии.',
'Россия останется одним из лидеров, возможности для наращивания экспорта есть.',
'Это позволит оптимизировать торговые отношения.']

src_lang = 'ru_RU'
tgt_lang = 'zh_CN'
model = MBartForConditionalGeneration.from_pretrained("facebook/mbart-large-50-many-to-many-mmt")
tokenizer = MBart50TokenizerFast.from_pretrained("facebook/mbart-large-50-many-to-many-mmt")

for text in text_list:
tokenizer.src_lang = src_lang
encoded_hi = tokenizer(text, return_tensors="pt")
generated_tokens = model.generate(**encoded_hi, forced_bos_token_id=tokenizer.lang_code_to_id[tgt_lang])
translated = tokenizer.batch_decode(generated_tokens, skip_special_tokens=True)
print(translated)
```
when the src_lang was ‘ru_RU’ and the tgt_lang was ‘zh_CN’, the results were:
```
['This will facilitate the transport of goods for China and Germany.']
['Russia will remain one of the leaders, there are opportunities to increase export.']
['This will allow to optimize trade relations.']
```

## Expected behavior

We wanted to obtain a set of Chinese translations. Here are the Chinese translations for reference.
```
['这将使中国和德国更容易运输货物。']
['俄罗斯仍将是一个领导者,有机会增加出口。']
['这将有助于改善贸易关系。']
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.