math_gen_943d32.py 2.12 KB
Newer Older
1
2
3
from opencompass.openicl.icl_prompt_template import PromptTemplate
from opencompass.openicl.icl_retriever import ZeroRetriever
from opencompass.openicl.icl_inferencer import AgentInferencer
Hubert's avatar
Hubert committed
4
from opencompass.datasets import MATHDataset, MATHAgentEvaluator, math_postprocess
5
6
7

# This config is for code interpreter
math_example = """
Hubert's avatar
Hubert committed
8
9
Example:

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
<HUMAN>Find the domain of the expression $\\frac{{\sqrt{{x-2}}}}{{\sqrt{{5-x}}}}$.
<ASSISTANT>{thought} The domain restrictions are determined by:

The square root in the numerator must be non-negative.
The square root in the denominator must be positive (because we can't have 0 in the denominator).
The value inside a square root (the radicand) must be non-negative. We can use `sympy` to determine the domain of the expression.
{action} PythonInterpreter
{action_input}
```python
from sympy import symbols, solveset, S, And

def solution():
    # Define the variable
    x = symbols('x')

    # Define the inequalities for the domain based on the expression
    inequality1 = x-2 >= 0  # because of the square root in the numerator
    inequality2 = 5-x > 0  # because of the square root in the denominator

    # Solve the inequalities
    domain1 = solveset(inequality1, x, domain=S.Reals)
    domain2 = solveset(inequality2, x, domain=S.Reals)

    # Find the intersection of the two domains
    final_domain = domain1.intersect(domain2)

    return final_domain

```
<SYSTEM>{response}'Interval.Ropen(2, 5)'
<ASSISTANT> {thought} Therefore, the domain of the expression is $\\boxed{{[2,5)}}$
{finish} [2,5)
"""

math_infer_cfg = dict(
    prompt_template=dict(type=PromptTemplate, template='{problem}'),
    retriever=dict(type=ZeroRetriever),
    inferencer=dict(type=AgentInferencer, example=math_example))

math_eval_cfg = dict(
Hubert's avatar
Hubert committed
50
    evaluator=dict(type=MATHAgentEvaluator),
51
52
53
54
55
56
57
58
59
60
61
62
63
64
    pred_postprocessor=dict(type=math_postprocess))

math_datasets = [
    dict(
        type=MATHDataset,
        abbr='math',
        path='./data/math/math.json',
        reader_cfg=dict(
            input_columns=['problem'],
            output_column='solution',
        ),
        infer_cfg=math_infer_cfg,
        eval_cfg=math_eval_cfg)
]