def gen_lang_yamls()

in lm_eval/tasks/afrixnli/utils.py [0:0]


def gen_lang_yamls(output_dir: str, overwrite: bool, mode: str) -> None:
    """
    Generate a yaml file for each language.

    :param output_dir: The directory to output the files to.
    :param overwrite: Whether to overwrite files if they already exist.
    """
    err = []
    languages = [
        "eng",
        "amh",
        "ibo",
        "fra",
        "sna",
        "wol",
        "ewe",
        "lin",
        "lug",
        "xho",
        "kin",
        "twi",
        "zul",
        "orm",
        "yor",
        "hau",
        "sot",
        "swa",
    ]
    for lang in languages:
        try:
            if mode == "native-direct":
                QUESTION_WORD = LANGUAGES[lang]["QUESTION_WORD"]
                ENTAILMENT_LABEL = LANGUAGES[lang]["ENTAILMENT_LABEL"]
                NEUTRAL_LABEL = LANGUAGES[lang]["NEUTRAL_LABEL"]
                CONTRADICTION_LABEL = LANGUAGES[lang]["CONTRADICTION_LABEL"]

                file_name = f"afrixnli_native_direct_{lang}.yaml"
                task_name = f"afrixnli_native_direct_{lang}"
                yaml_template = "afrixnli_native_direct_yaml"
                with open(
                    f"{output_dir}/{file_name}",
                    "w" if overwrite else "x",
                    encoding="utf8",
                ) as f:
                    f.write("# Generated by utils.py\n")
                    yaml.dump(
                        {
                            "include": yaml_template,
                            "task": task_name,
                            "dataset_name": lang,
                            "doc_to_choice": f"{{{{["
                            f"""premise+\", {QUESTION_WORD}? {ENTAILMENT_LABEL}, \"+hypothesis,"""
                            f"""premise+\", {QUESTION_WORD}? {NEUTRAL_LABEL}, \"+hypothesis,"""
                            f"""premise+\", {QUESTION_WORD}? {CONTRADICTION_LABEL}, \"+hypothesis"""
                            f"]}}}}",
                        },
                        f,
                        allow_unicode=True,
                    )
            else:
                file_name = f"afrixnli_{mode}_{lang}.yaml"
                task_name = f"afrixnli_{mode}_{lang}"
                yaml_template = f"afrixnli_{mode}_yaml"
                with open(
                    f"{output_dir}/{file_name}",
                    "w" if overwrite else "x",
                    encoding="utf8",
                ) as f:
                    f.write("# Generated by utils.py\n")
                    yaml.dump(
                        {
                            "include": yaml_template,
                            "task": task_name,
                            "dataset_name": lang,
                        },
                        f,
                        allow_unicode=True,
                    )
        except FileExistsError:
            err.append(file_name)

    if len(err) > 0:
        raise FileExistsError(
            "Files were not created because they already exist (use --overwrite flag):"
            f" {', '.join(err)}"
        )