usrbinenv python 2020 the huggingface team licensed under the apache license version 2 0 the license you may not use this file except in compliance with the license you may obtain a copy of the license at http www apache orglicenseslicense2 0 unless required by applicable law or agreed to in writing software distributed under the license is distributed on an as is basis without warranties or conditions of any kind either express or implied see the license for the specific language governing permissions and limitations under the license usage gencardallenaiwmt16 py blue scores as follows pair fairseq transformers fsmt model description intended uses limitations how to use limitations and bias training data eval results data sources bibtex entry and citation info modelcarddir mkdirparentstrue existoktrue path os path joinmodelcarddir readme md printfgenerating path with openpath w encodingutf8 as f f writereadme make sure we are under the root of the project repodir pathfile resolve parent parent parent modelcardsdir repodir modelcards for modelname in wmt16endedist121 wmt16endedist61 wmt16ende121 modelcarddir modelcardsdir allenai modelname writemodelcardmodelcarddir srclangen tgtlangde modelnamemodelname usr bin env python 2020 the huggingface team licensed under the apache license version 2 0 the license you may not use this file except in compliance with the license you may obtain a copy of the license at http www apache org licenses license 2 0 unless required by applicable law or agreed to in writing software distributed under the license is distributed on an as is basis without warranties or conditions of any kind either express or implied see the license for the specific language governing permissions and limitations under the license usage gen card allenai wmt16 py blue scores as follows pair fairseq transformers language src_lang tgt_lang thumbnail tags translation wmt16 allenai license apache 2 0 datasets wmt16 metrics bleu fsmt model description this is a ported version of fairseq based wmt16 transformer https github com jungokasai deep shallow for src_lang tgt_lang for more details please see deep encoder shallow decoder reevaluating the speed quality tradeoff in machine translation https arxiv org abs 2006 10369 all 3 models are available wmt16 en de dist 12 1 https huggingface co allenai wmt16 en de dist 12 1 wmt16 en de dist 6 1 https huggingface co allenai wmt16 en de dist 6 1 wmt16 en de 12 1 https huggingface co allenai wmt16 en de 12 1 intended uses limitations how to use python from transformers import fsmtforconditionalgeneration fsmttokenizer mname allenai model_name 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 training data pretrained weights were left identical to the original model released by allenai for more details please see the paper https arxiv org abs 2006 10369 eval results here are the bleu scores model fairseq transformers model_name scores model_name 0 scores model_name 1 the score is slightly below the score reported in the paper as the researchers don t use sacrebleu and measure the score on tokenized outputs transformers score was measured using sacrebleu on detokenized outputs 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 5 mkdir p data_dir sacrebleu t wmt16 l pair echo src data_dir val source sacrebleu t wmt16 l pair echo ref data_dir val target echo pair pythonpath src examples seq2seq python examples seq2seq run_eval py allenai model_name 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 data sources training etc http www statmt org wmt16 test set http matrix statmt org test_sets newstest2016 tgz 1504722372 bibtex entry and citation info misc kasai2020deep title deep encoder shallow decoder reevaluating the speed quality tradeoff in machine translation jungo kasai and nikolaos pappas and hao peng and james cross and noah a smith year 2020 eprint 2006 10369 archiveprefix arxiv primaryclass cs cl make sure we are under the root of the project
import os
from pathlib import Path


def write_model_card(model_card_dir, src_lang, tgt_lang, model_name):

    texts = {
        "en": "Machine learning is great, isn't it?",
        "ru": "Машинное обучение - это здорово, не так ли?",
        "de": "Maschinelles Lernen ist großartig, nicht wahr?",
    }

    
    
    scores = {
        "wmt16-en-de-dist-12-1": [28.3, 27.52],
        "wmt16-en-de-dist-6-1": [27.4, 27.11],
        "wmt16-en-de-12-1": [26.9, 25.75],
    }
    pair = f"{src_lang}-{tgt_lang}"

    readme = f
    model_card_dir.mkdir(parents=True, exist_ok=True)
    path = os.path.join(model_card_dir, "README.md")
    print(f"Generating {path}")
    with open(path, "w", encoding="utf-8") as f:
        f.write(readme)


repo_dir = Path(__file__).resolve().parent.parent.parent
model_cards_dir = repo_dir / "model_cards"

for model_name in ["wmt16-en-de-dist-12-1", "wmt16-en-de-dist-6-1", "wmt16-en-de-12-1"]:
    model_card_dir = model_cards_dir / "allenai" / model_name
    write_model_card(model_card_dir, src_lang="en", tgt_lang="de", model_name=model_name)