





import os
from pathlib import Path
def 							_lowerCamelCase(  UpperCamelCase__    : List[Any]    ,       UpperCamelCase__    : Optional[Any]    ,       UpperCamelCase__    : List[Any]		)		->  List[Any]:
    A       :       Any							=						{
        '''en''': '''Machine learning is great, isn\'t it?''',
        '''ru''': '''Машинное обучение - это здорово, не так ли?''',
        '''de''': '''Maschinelles Lernen ist großartig, oder?''',
    }

    # BLUE scores as follows:
    # "pair": [fairseq, transformers]
    A       :       List[Any]							=						{
        '''ru-en''': ['''[41.3](http://matrix.statmt.org/matrix/output/1907?run_id=6937)''', '''39.20'''],
        '''en-ru''': ['''[36.4](http://matrix.statmt.org/matrix/output/1914?run_id=6724)''', '''33.47'''],
        '''en-de''': ['''[43.1](http://matrix.statmt.org/matrix/output/1909?run_id=6862)''', '''42.83'''],
        '''de-en''': ['''[42.3](http://matrix.statmt.org/matrix/output/1902?run_id=6750)''', '''41.35'''],
    }
    A       :       List[Any]							=						F'''{src_lang}-{tgt_lang}'''

    A       :       Any							=						F'''
---
language: 
- {src_lang}
- {tgt_lang}
thumbnail:
tags:
- translation
- wmt19
- facebook
license: apache-2.0
datasets:
- wmt19
metrics:
- bleu
---

# FSMT

## Model description

This is a ported version of [fairseq wmt19 transformer](https://github.com/pytorch/fairseq/blob/master/examples/wmt19/README.md) for {src_lang}-{tgt_lang}.

For more details, please see, [Facebook FAIR\'s WMT19 News Translation Task Submission](https://arxiv.org/abs/1907.06616).

The abbreviation FSMT stands for FairSeqMachineTranslation

All four models are available:

* [wmt19-en-ru](https://huggingface.co/facebook/wmt19-en-ru)
* [wmt19-ru-en](https://huggingface.co/facebook/wmt19-ru-en)
* [wmt19-en-de](https://huggingface.co/facebook/wmt19-en-de)
* [wmt19-de-en](https://huggingface.co/facebook/wmt19-de-en)

## Intended uses & limitations

#### How to use

```python
from transformers import FSMTForConditionalGeneration, FSMTTokenizer
mname = "facebook/wmt19-{src_lang}-{tgt_lang}"
tokenizer = FSMTTokenizer.from_pretrained(mname)
model = FSMTForConditionalGeneration.from_pretrained(mname)

input = "{texts[src_lang]}"
input_ids = tokenizer.encode(input, return_tensors="pt")
outputs = model.generate(input_ids)
decoded = tokenizer.decode(outputs[0], skip_special_tokens=True)
print(decoded) # {texts[tgt_lang]}

```

#### Limitations and bias

- The original (and this ported model) doesn\'t seem to handle well inputs with repeated sub-phrases, [content gets truncated](https://discuss.huggingface.co/t/issues-with-translating-inputs-containing-repeated-phrases/981)

## Training data

Pretrained weights were left identical to the original model released by fairseq. For more details, please, see the [paper](https://arxiv.org/abs/1907.06616).

## Eval results

pair   | fairseq | transformers
-------|---------|----------
{pair}  | {scores[pair][0]} | {scores[pair][1]}

The score is slightly below the score reported by `fairseq`, since `transformers`` currently doesn\'t support:
- model ensemble, therefore the best performing checkpoint was ported (``model4.pt``).
- re-ranking

The score was calculated using this code:

```bash
git clone https://github.com/huggingface/transformers
cd transformers
export PAIR={pair}
export DATA_DIR=data/$PAIR
export SAVE_DIR=data/$PAIR
export BS=8
export NUM_BEAMS=15
mkdir -p $DATA_DIR
sacrebleu -t wmt19 -l $PAIR --echo src > $DATA_DIR/val.source
sacrebleu -t wmt19 -l $PAIR --echo ref > $DATA_DIR/val.target
echo $PAIR
PYTHONPATH="src:examples/seq2seq" python examples/seq2seq/run_eval.py facebook/wmt19-$PAIR $DATA_DIR/val.source $SAVE_DIR/test_translations.txt --reference_path $DATA_DIR/val.target --score_path $SAVE_DIR/test_bleu.json --bs $BS --task translation --num_beams $NUM_BEAMS
```
note: fairseq reports using a beam of 50, so you should get a slightly higher score if re-run with `--num_beams 50`.

## Data Sources

- [training, etc.](http://www.statmt.org/wmt19/)
- [test set](http://matrix.statmt.org/test_sets/newstest2019.tgz?1556572561)


### BibTeX entry and citation info

```bibtex
@inproceedings{{...,
  year={{2020}},
  title={{Facebook FAIR\'s WMT19 News Translation Task Submission}},
  author={{Ng, Nathan and Yee, Kyra and Baevski, Alexei and Ott, Myle and Auli, Michael and Edunov, Sergey}},
  booktitle={{Proc. of WMT}},
}}
```


## TODO

- port model ensemble (fairseq uses 4 model checkpoints)

'''
    os.makedirs(UpperCamelCase__    ,       exist_ok=UpperCamelCase__		)
    A       :       Optional[int]							=						os.path.join(UpperCamelCase__    ,       '''README.md'''		)
    print(F'''Generating {path}'''		)
    with open(UpperCamelCase__    ,       '''w'''    ,       encoding='''utf-8'''		) as f:
        f.write(UpperCamelCase__		)


# make sure we are under the root of the project
snake_case_     =	Path(__file__).resolve().parent.parent.parent
snake_case_     =	repo_dir / """model_cards"""

for model_name in ["wmt19-ru-en", "wmt19-en-ru", "wmt19-en-de", "wmt19-de-en"]:
     snake_case_ ,  snake_case_ ,  snake_case_     =	model_name.split("""-""")
     snake_case_     =	model_cards_dir / """facebook""" / model_name
     write_model_card(model_card_dir, src_lang=src_lang, tgt_lang=tgt_lang)







'''simple docstring'''






snake_case_     =	[
    9_99,
    8_00,
    7_99,
    6_00,
    5_99,
    5_00,
    4_00,
    3_99,
    3_77,
    3_55,
    3_33,
    3_11,
    2_88,
    2_66,
    2_44,
    2_22,
    2_00,
    1_99,
    1_77,
    1_55,
    1_33,
    1_11,
    88,
    66,
    44,
    22,
    0,
]

snake_case_     =	[
    9_99,
    9_76,
    9_52,
    9_28,
    9_05,
    8_82,
    8_58,
    8_57,
    8_10,
    7_62,
    7_15,
    7_14,
    5_72,
    4_29,
    4_28,
    2_86,
    2_85,
    2_38,
    1_90,
    1_43,
    1_42,
    1_18,
    95,
    71,
    47,
    24,
    0,
]

snake_case_     =	[
    9_99,
    9_88,
    9_77,
    9_66,
    9_55,
    9_44,
    9_33,
    9_22,
    9_11,
    9_00,
    8_99,
    8_79,
    8_59,
    8_40,
    8_20,
    8_00,
    7_99,
    7_66,
    7_33,
    7_00,
    6_99,
    6_50,
    6_00,
    5_99,
    5_00,
    4_99,
    4_00,
    3_99,
    3_50,
    3_00,
    2_99,
    2_66,
    2_33,
    2_00,
    1_99,
    1_79,
    1_59,
    1_40,
    1_20,
    1_00,
    99,
    88,
    77,
    66,
    55,
    44,
    33,
    22,
    11,
    0,
]

snake_case_     =	[
    9_99,
    9_95,
    9_92,
    9_89,
    9_85,
    9_81,
    9_78,
    9_75,
    9_71,
    9_67,
    9_64,
    9_61,
    9_57,
    9_56,
    9_51,
    9_47,
    9_42,
    9_37,
    9_33,
    9_28,
    9_23,
    9_19,
    9_14,
    9_13,
    9_08,
    9_03,
    8_97,
    8_92,
    8_87,
    8_81,
    8_76,
    8_71,
    8_70,
    8_64,
    8_58,
    8_52,
    8_46,
    8_40,
    8_34,
    8_28,
    8_27,
    8_20,
    8_13,
    8_06,
    7_99,
    7_92,
    7_85,
    7_84,
    7_77,
    7_70,
    7_63,
    7_56,
    7_49,
    7_42,
    7_41,
    7_33,
    7_24,
    7_16,
    7_07,
    6_99,
    6_98,
    6_88,
    6_77,
    6_66,
    6_56,
    6_55,
    6_45,
    6_34,
    6_23,
    6_13,
    6_12,
    5_98,
    5_84,
    5_70,
    5_69,
    5_55,
    5_41,
    5_27,
    5_26,
    5_05,
    4_84,
    4_83,
    4_62,
    4_40,
    4_39,
    3_96,
    3_95,
    3_52,
    3_51,
    3_08,
    3_07,
    2_64,
    2_63,
    2_20,
    2_19,
    1_76,
    1_32,
    88,
    44,
    0,
]

snake_case_     =	[
    9_99,
    9_97,
    9_95,
    9_92,
    9_90,
    9_88,
    9_86,
    9_84,
    9_81,
    9_79,
    9_77,
    9_75,
    9_72,
    9_70,
    9_68,
    9_66,
    9_64,
    9_61,
    9_59,
    9_57,
    9_56,
    9_54,
    9_51,
    9_49,
    9_46,
    9_44,
    9_41,
    9_39,
    9_36,
    9_34,
    9_31,
    9_29,
    9_26,
    9_24,
    9_21,
    9_19,
    9_16,
    9_14,
    9_13,
    9_10,
    9_07,
    9_05,
    9_02,
    8_99,
    8_96,
    8_93,
    8_91,
    8_88,
    8_85,
    8_82,
    8_79,
    8_77,
    8_74,
    8_71,
    8_70,
    8_67,
    8_64,
    8_61,
    8_58,
    8_55,
    8_52,
    8_49,
    8_46,
    8_43,
    8_40,
    8_37,
    8_34,
    8_31,
    8_28,
    8_27,
    8_24,
    8_21,
    8_17,
    8_14,
    8_11,
    8_08,
    8_04,
    8_01,
    7_98,
    7_95,
    7_91,
    7_88,
    7_85,
    7_84,
    7_80,
    7_77,
    7_74,
    7_70,
    7_66,
    7_63,
    7_60,
    7_56,
    7_52,
    7_49,
    7_46,
    7_42,
    7_41,
    7_37,
    7_33,
    7_30,
    7_26,
    7_22,
    7_18,
    7_14,
    7_10,
    7_07,
    7_03,
    6_99,
    6_98,
    6_94,
    6_90,
    6_85,
    6_81,
    6_77,
    6_73,
    6_69,
    6_64,
    6_60,
    6_56,
    6_55,
    6_50,
    6_46,
    6_41,
    6_36,
    6_32,
    6_27,
    6_22,
    6_18,
    6_13,
    6_12,
    6_07,
    6_02,
    5_96,
    5_91,
    5_86,
    5_80,
    5_75,
    5_70,
    5_69,
    5_63,
    5_57,
    5_51,
    5_45,
    5_39,
    5_33,
    5_27,
    5_26,
    5_19,
    5_12,
    5_05,
    4_98,
    4_91,
    4_84,
    4_83,
    4_74,
    4_66,
    4_57,
    4_49,
    4_40,
    4_39,
    4_28,
    4_18,
    4_07,
    3_96,
    3_95,
    3_81,
    3_66,
    3_52,
    3_51,
    3_30,
    3_08,
    3_07,
    2_86,
    2_64,
    2_63,
    2_42,
    2_20,
    2_19,
    1_76,
    1_75,
    1_32,
    1_31,
    88,
    44,
    0,
]

snake_case_     =	[
    9_99,
    9_91,
    9_82,
    9_74,
    9_66,
    9_58,
    9_50,
    9_41,
    9_33,
    9_25,
    9_16,
    9_08,
    9_00,
    8_99,
    8_74,
    8_50,
    8_25,
    8_00,
    7_99,
    7_00,
    6_00,
    5_00,
    4_00,
    3_00,
    2_00,
    1_00,
    0,
]

snake_case_     =	[
    9_99,
    9_92,
    9_85,
    9_78,
    9_71,
    9_64,
    9_57,
    9_49,
    9_42,
    9_35,
    9_28,
    9_21,
    9_14,
    9_07,
    9_00,
    8_99,
    8_79,
    8_59,
    8_40,
    8_20,
    8_00,
    7_99,
    7_66,
    7_33,
    7_00,
    6_99,
    6_50,
    6_00,
    5_99,
    5_00,
    4_99,
    4_00,
    3_99,
    3_00,
    2_99,
    2_00,
    1_99,
    1_00,
    99,
    0,
]

snake_case_     =	[
    9_99,
    9_96,
    9_92,
    9_89,
    9_85,
    9_82,
    9_79,
    9_75,
    9_72,
    9_68,
    9_65,
    9_61,
    9_58,
    9_55,
    9_51,
    9_48,
    9_44,
    9_41,
    9_38,
    9_34,
    9_31,
    9_27,
    9_24,
    9_20,
    9_17,
    9_14,
    9_10,
    9_07,
    9_03,
    9_00,
    8_99,
    8_91,
    8_84,
    8_76,
    8_69,
    8_61,
    8_53,
    8_46,
    8_38,
    8_30,
    8_23,
    8_15,
    8_08,
    8_00,
    7_99,
    7_88,
    7_77,
    7_66,
    7_55,
    7_44,
    7_33,
    7_22,
    7_11,
    7_00,
    6_99,
    6_88,
    6_77,
    6_66,
    6_55,
    6_44,
    6_33,
    6_22,
    6_11,
    6_00,
    5_99,
    5_85,
    5_71,
    5_57,
    5_42,
    5_28,
    5_14,
    5_00,
    4_99,
    4_85,
    4_71,
    4_57,
    4_42,
    4_28,
    4_14,
    4_00,
    3_99,
    3_79,
    3_59,
    3_40,
    3_20,
    3_00,
    2_99,
    2_79,
    2_59,
    2_40,
    2_20,
    2_00,
    1_99,
    1_66,
    1_33,
    1_00,
    99,
    66,
    33,
    0,
]
