|
import argparse |
|
|
|
import yaml |
|
|
|
|
|
|
|
|
|
|
|
|
|
LANGUAGES = { |
|
"de": { |
|
"QUESTION_WORD": "richtig", |
|
"YES": "Ja", |
|
"NO": "Nein", |
|
}, |
|
"en": { |
|
"QUESTION_WORD": "right", |
|
"YES": "Yes", |
|
"NO": "No", |
|
}, |
|
"es": { |
|
"QUESTION_WORD": "verdad", |
|
"YES": "SΓ", |
|
"NO": "No", |
|
}, |
|
"fr": { |
|
"QUESTION_WORD": "n'est-ce pas", |
|
"YES": "Oui", |
|
"NO": "No", |
|
}, |
|
"ja": { |
|
"QUESTION_WORD": "γ§γγ", |
|
"YES": "γ―γ", |
|
"NO": "γγγ", |
|
}, |
|
"ko": { |
|
"QUESTION_WORD": "λ§μ£ ", |
|
"YES": "μ", |
|
"NO": "μλμ", |
|
}, |
|
"zh": { |
|
"QUESTION_WORD": "ε―Ήε§", |
|
"YES": "ζ―", |
|
"NO": "δΈζ―", |
|
}, |
|
} |
|
|
|
|
|
def gen_lang_yamls(output_dir: str, overwrite: bool) -> 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 = [] |
|
for lang in LANGUAGES.keys(): |
|
file_name = f"paws_{lang}.yaml" |
|
try: |
|
QUESTION_WORD = LANGUAGES[lang]["QUESTION_WORD"] |
|
YES = LANGUAGES[lang]["YES"] |
|
NO = LANGUAGES[lang]["NO"] |
|
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": "pawsx_template_yaml", |
|
"dataset_name": lang, |
|
"task": f"paws_{lang}", |
|
"doc_to_text": "", |
|
"doc_to_choice": f"{{{{[" |
|
f"""sentence1+\", {QUESTION_WORD}? {YES}, \"+sentence2,""" |
|
f""" sentence1+\", {QUESTION_WORD}? {NO}, \"+sentence2""" |
|
f"]}}}}", |
|
}, |
|
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)}" |
|
) |
|
|
|
|
|
def main() -> None: |
|
"""Parse CLI args and generate language-specific yaml files.""" |
|
parser = argparse.ArgumentParser() |
|
parser.add_argument( |
|
"--overwrite", |
|
default=False, |
|
action="store_true", |
|
help="Overwrite files if they already exist", |
|
) |
|
parser.add_argument( |
|
"--output-dir", default=".", help="Directory to write yaml files to" |
|
) |
|
args = parser.parse_args() |
|
|
|
gen_lang_yamls(output_dir=args.output_dir, overwrite=args.overwrite) |
|
|
|
|
|
if __name__ == "__main__": |
|
main() |
|
|