text
stringlengths 0
15.3k
|
---|
instruction.build_description(prompt=inp.prompt) |
if response.strip() and instruction.check_following(response): |
is_following_list.append(True) |
else: |
is_following_list.append(False) |
return OutputExample(instruction_id_list=inp.instruction_id_list, prompt=inp.prompt, response=response, follow_all_instructions=all(is_following_list), follow_instruction_list=is_following_list) |
def test_instruction_following_loose(inp, response): |
r = response.split('\n') |
response_remove_first = '\n'.join(r[1:]).strip() |
response_remove_last = '\n'.join(r[:-1]).strip() |
response_remove_both = '\n'.join(r[1:-1]).strip() |
revised_response = response.replace('*', '') |
revised_response_remove_first = response_remove_first.replace('*', '') |
revised_response_remove_last = response_remove_last.replace('*', '') |
revised_response_remove_both = response_remove_both.replace('*', '') |
all_responses = [response, revised_response, response_remove_first, response_remove_last, response_remove_both, revised_response_remove_first, revised_response_remove_last, revised_response_remove_both] |
instruction_list = inp.instruction_id_list |
is_following_list = [] |
for (index, instruction_id) in enumerate(instruction_list): |
instruction_cls = instructions_registry.INSTRUCTION_DICT[instruction_id] |
instruction = instruction_cls(instruction_id) |
kwargs = {k: v for (k, v) in inp.kwargs[index].items() if v} |
instruction.build_description(**kwargs) |
args = instruction.get_instruction_args() |
if args and 'prompt' in args: |
instruction.build_description(prompt=inp.prompt) |
is_following = False |
for r in all_responses: |
if r.strip() and instruction.check_following(r): |
is_following = True |
break |
is_following_list.append(is_following) |
return OutputExample(instruction_id_list=inp.instruction_id_list, prompt=inp.prompt, response=response, follow_all_instructions=all(is_following_list), follow_instruction_list=is_following_list) |
def process_results(doc, results): |
inp = InputExample(key=doc['key'], instruction_id_list=doc['instruction_id_list'], prompt=doc['prompt'], kwargs=doc['kwargs']) |
response = results[0] |
out_strict = test_instruction_following_strict(inp, response) |
out_loose = test_instruction_following_loose(inp, response) |
return {'prompt_level_strict_acc': out_strict.follow_all_instructions, 'inst_level_strict_acc': out_strict.follow_instruction_list, 'prompt_level_loose_acc': out_loose.follow_all_instructions, 'inst_level_loose_acc': out_loose.follow_instruction_list} |
def agg_inst_level_acc(items): |
flat_items = [item for sublist in items for item in sublist] |
inst_level_acc = sum(flat_items) / len(flat_items) |
return inst_level_acc |
# File: lm-evaluation-harness-main/lm_eval/tasks/leaderboard/math/utils.py |
import re |
import signal |
from typing import Dict, List, Optional |
import datasets |
from lm_eval.utils import eval_logger |
try: |
import sympy |
from sympy.parsing.latex import parse_latex |
except ModuleNotFoundError: |
raise ModuleNotFoundError('`sympy` is required for generating translation task prompt templates. please install sympy via pip install lm-eval[math] or pip install -e .[math]') |
def doc_to_text(doc: dict) -> str: |
return 'Problem:' + '\n' + doc['problem'] + '\n\n' + 'Solution:' |
def process_docs(dataset: datasets.Dataset) -> datasets.Dataset: |
def _process_doc(doc: dict) -> dict: |
out_doc = {'problem': doc['problem'], 'solution': doc['solution'], 'answer': normalize_final_answer(remove_boxed(last_boxed_only_string(doc['solution'])))} |
if getattr(doc, 'few_shot', None) is not None: |
out_doc['few_shot'] = True |
return out_doc |
return dataset.map(_process_doc) |
def list_fewshot_samples() -> list[dict]: |
return [{'problem': 'Find the domain of the expression $\\frac{\\sqrt{x-2}}{\\sqrt{5-x}}$.}', 'solution': 'The expressions inside each square root must be non-negative. Therefore, $x-2 \\ge 0$, so $x\\ge2$, and $5 - x \\ge 0$, so $x \\le 5$. Also, the denominator cannot be equal to zero, so $5-x>0$, which gives $x<5$. Therefore, the domain of the expression is $\\boxed{[2,5)}$.\nFinal Answer: The final answer is $[2,5)$. I hope it is correct.', 'few_shot': '1'}, {'problem': 'If $\\det \\mathbf{A} = 2$ and $\\det \\mathbf{B} = 12,$ then find $\\det (\\mathbf{A} \\mathbf{B}).$', 'solution': 'We have that $\\det (\\mathbf{A} \\mathbf{B}) = (\\det \\mathbf{A})(\\det \\mathbf{B}) = (2)(12) = \\boxed{24}.$\nFinal Answer: The final answer is $24$. I hope it is correct.', 'few_shot': '1'}, {'problem': 'Terrell usually lifts two 20-pound weights 12 times. If he uses two 15-pound weights instead, how many times must Terrell lift them in order to lift the same total weight?', 'solution': 'If Terrell lifts two 20-pound weights 12 times, he lifts a total of $2\\cdot 12\\cdot20=480$ pounds of weight. If he lifts two 15-pound weights instead for $n$ times, he will lift a total of $2\\cdot15\\cdot n=30n$ pounds of weight. Equating this to 480 pounds, we can solve for $n$:\n\\begin{align*}\n30n&=480\\\n\\Rightarrow\\qquad n&=480/30=\\boxed{16}\n\\end{align*}\nFinal Answer: The final answer is $16$. I hope it is correct.', 'few_shot': '1'}, {'problem': 'If the system of equations\n\n\\begin{align*}\n6x-4y&=a,\\\n6y-9x &=b.\n\\end{align*}has a solution $(x, y)$ where $x$ and $y$ are both nonzero,\nfind $\\frac{a}{b},$ assuming $b$ is nonzero.', 'solution': 'If we multiply the first equation by $-\\frac{3}{2}$, we obtain\n\n$$6y-9x=-\\frac{3}{2}a.$$Since we also know that $6y-9x=b$, we have\n\n$$-\\frac{3}{2}a=b\\Rightarrow\\frac{a}{b}=\\boxed{-\\frac{2}{3}}.$$\nFinal Answer: The final answer is $-\\frac{2}{3}$. I hope it is correct.', 'few_shot': '1'}] |
def process_results(doc: dict, results: List[str]) -> Dict[str, int]: |
candidates = results[0] |
unnormalized_answer = get_unnormalized_answer(candidates) |
answer = normalize_final_answer(unnormalized_answer) |
if is_equiv(answer, doc['answer']): |
retval = 1 |
else: |
retval = 0 |
results = {'exact_match': retval} |
return results |
def last_boxed_only_string(string: str) -> Optional[str]: |
idx = string.rfind('\\boxed') |
if '\\boxed ' in string: |
return '\\boxed ' + string.split('\\boxed ')[-1].split('$')[0] |
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] == '}': |
Subsets and Splits
No saved queries yet
Save your SQL queries to embed, download, and access them later. Queries will appear here once saved.