text
stringlengths 0
15.3k
|
---|
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(f"Files were not created because they already exist (use --overwrite flag): {', '.join(err)}") |
def main() -> None: |
parser = argparse.ArgumentParser() |
parser.add_argument('--overwrite', default=True, action='store_true', help='Overwrite files if they already exist') |
parser.add_argument('--output-dir', default='./manual/translate', help='Directory to write yaml files to') |
parser.add_argument('--mode', default='manual_translate', choices=['en_direct', 'native-direct', 'manual_direct', 'manual_translate'], help='Mode of chain-of-thought') |
args = parser.parse_args() |
gen_lang_yamls(output_dir=args.output_dir, overwrite=args.overwrite, mode=args.mode) |
if __name__ == '__main__': |
main() |
# File: lm-evaluation-harness-main/lm_eval/tasks/agieval/utils.py |
import re |
from typing import Dict, List |
import numpy as np |
def parse_math_answer(raw_string): |
def remove_boxed(s): |
left = '\\boxed{' |
try: |
assert s[:len(left)] == left |
assert s[-1] == '}' |
answer = s[len(left):-1] |
if '=' in answer: |
answer = answer.split('=')[-1].lstrip(' ') |
return answer |
except Exception: |
return None |
def last_boxed_only_string(string): |
idx = string.rfind('\\boxed') |
if idx < 0: |
idx = string.rfind('\\fbox') |
if idx < 0: |
return None |
i = idx |
right_brace_idx = None |
num_left_braces_open = 0 |
while i < len(string): |
if string[i] == '{': |
num_left_braces_open += 1 |
if string[i] == '}': |
num_left_braces_open -= 1 |
if num_left_braces_open == 0: |
right_brace_idx = i |
break |
i += 1 |
if right_brace_idx is None: |
retval = None |
else: |
retval = string[idx:right_brace_idx + 1] |
return retval |
def get_answer_with_dollar_sign(s): |
first_pattern = '\\$(.*)\\$' |
last_match = None |
matches = re.findall(first_pattern, s) |
if matches: |
last_match = matches[-1] |
if '=' in last_match: |
last_match = last_match.split('=')[-1].lstrip(' ') |
return last_match |
def get_answer_without_dollar_sign(s): |
last_match = None |
if '=' in s: |
last_match = s.split('=')[-1].lstrip(' ').rstrip('.') |
if '\\n' in last_match: |
last_match = last_match.split('\\n')[0] |
else: |
pattern = '(?:\\$)?\\d+(?:\\.\\d+)?(?![\\w\\d])' |
matches = re.findall(pattern, s) |
if matches: |
last_match = matches[-1] |
return last_match |
if '\\boxed' in raw_string: |
answer = remove_boxed(last_boxed_only_string(raw_string)) |
else: |
answer = get_answer_with_dollar_sign(raw_string) |
if not answer: |
answer = get_answer_without_dollar_sign(raw_string) |
return answer |
def _fix_fracs(string): |
substrs = string.split('\\frac') |
new_str = substrs[0] |
if len(substrs) > 1: |
substrs = substrs[1:] |
for substr in substrs: |
new_str += '\\frac' |
if substr[0] == '{': |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.