Skip to content

Commit

Permalink
Allow inaccurate majority voting
Browse files Browse the repository at this point in the history
  • Loading branch information
tongyx361 committed Sep 15, 2024
1 parent e659008 commit 2ed193a
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 369 deletions.
64 changes: 5 additions & 59 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,6 @@

<!-- WARNING: THIS FILE WAS AUTOGENERATED! DO NOT EDIT! -->

``` python
```

The autoreload extension is already loaded. To reload it, use:
%reload_ext autoreload

[autoreload of symeval.core failed: Traceback (most recent call last):
File "/ssddata/tongyx/miniconda3/envs/dart-math/lib/python3.11/site-packages/IPython/extensions/autoreload.py", line 276, in check
superreload(m, reload, self.old_objects)
File "/ssddata/tongyx/miniconda3/envs/dart-math/lib/python3.11/site-packages/IPython/extensions/autoreload.py", line 475, in superreload
module = reload(module)
^^^^^^^^^^^^^^
File "/ssddata/tongyx/miniconda3/envs/dart-math/lib/python3.11/importlib/__init__.py", line 169, in reload
_bootstrap._exec(spec, module)
File "<frozen importlib._bootstrap>", line 621, in _exec
File "<frozen importlib._bootstrap_external>", line 940, in exec_module
File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
File "/ssddata/tongyx/projects/symeval/symeval/core.py", line 228, in <module>
class EvaluatorBatchBase(EvaluatorBase):
File "/ssddata/tongyx/projects/symeval/symeval/core.py", line 250, in EvaluatorBatchBase
) -> Tuple[List[str], List[bool]]:
~~~~~^^^^^^^^^^^^^^^^^^^^^^^
TypeError: type 'Tuple' is not subscriptable
]

## Installation

For common users/developers, please just run the following command the
Expand Down Expand Up @@ -82,7 +57,8 @@ target="_blank" style="float:right; font-size:smaller">source</a>
> EvaluatorMathBatch (strict_extract:bool=True,
> include_percentage:bool=True, rel_tol:float=1e-09,
> abs_tol:float=1e-08, percent_rel_tol:float=0.001,
> ascii_only:bool=True, timeout:int=5)
> ascii_only:bool=True, timeout:int=5, n_procs:int=2,
> use_tqdm:bool=True)
*Batch evaluator for math problems, capable of extracting answer segment
from complex resp and processing various mathematical objects
Expand All @@ -97,7 +73,9 @@ text (e.g. bool values).*
| abs_tol | float | 1e-08 | The absolute tolerance for numerical comparisons. Necessary for precision issues. |
| percent_rel_tol | float | 0.001 | The absolute tolerance for percentage comparisons. |
| ascii_only | bool | True | Only allowing ASCII characters |
| timeout | int | 5 | |
| timeout | int | 5 | The timeout for each evaluation. |
| n_procs | int | 2 | |
| use_tqdm | bool | True | |

#### Accurately Extracting Answer Strings

Expand All @@ -112,17 +90,13 @@ can:
math_evaluator.extract_ans("Therefore, $1+1=\\boxed{2}$.")
```

'2'

``` python
# Answer around "answer"
math_evaluator.extract_ans(
"Both $1$ and $11$ divide $11,$ so $\\boxed{11}=2$, and since $1,$ $2,$ $4,$ $5,$ $10,$ and $20$ divide $20,$ then $\\boxed{20}=6$. The inner expression, $\\boxed{11}\\times\\boxed{20}=2\\times6=12$. Finally, $\\boxed{12}=6$ because $1,$ $2,$ $3,$ $4,$ $6,$ and $12$ divide $12.$\n\nTherefore, $6$ is our answer. Please note that we have not boxed the correct answer as we normally do, as that would be especially confusing for this problem."
)
```

'6'

``` python
# Use the last number by default
math_evaluator.extract_ans(
Expand All @@ -131,15 +105,11 @@ math_evaluator.extract_ans(
# More cases ...
```

''

``` python
# Normalize fraction
math_evaluator.extract_ans("The answer is 1/2")
```

'\\frac{1}{2}'

``` python
# Normalize pmatrix
math_evaluator.extract_ans(
Expand All @@ -148,8 +118,6 @@ math_evaluator.extract_ans(
# More cases ...
```

'\\begin{array}3\\\\frac{\\pi}{2}\\end{array}'

#### Correctly Processing Various Mathematical Objects / Special Text

[`EvaluatorMath`](https://tongyx361.github.io/symeval/core.html#evaluatormath),
Expand All @@ -165,36 +133,26 @@ calculation, is able to correctly process
math_evaluator.eq("x+y", "y+x") == True # Expression
```

True

``` python
math_evaluator.eq("\\frac{1}{2}", "0.5") == True # LaTeX
```

True

``` python
math_evaluator.eq(
"\\begin{array}1\\\\2\\end{array}",
"1,2",
) # Matrix (Vector)
```

True

``` python
math_evaluator.eq("{1,2}", "{2,1}", compare_sets=True) # Set
```

True

``` python
math_evaluator.eq("no", "false") # Bool
# More mathematical objects and special texts ...
```

True

More test cases:

<details class="code-fold">
Expand Down Expand Up @@ -244,8 +202,6 @@ test_eq(math_evaluator.eq("\\frac{2003}{2}", "1001"), False)
math_evaluator.get_maj_answers(["", "", "1", "2", "2", "3", "3", "3"])
```

['', '', '1', '1', '2', '2', '2', '3']

### Parsing LaTeX

#### Interval
Expand All @@ -258,20 +214,14 @@ from symeval import latex2sympy_interval
latex2sympy_interval("(-11,-10)\\cup\\{-\\sqrt{110}\\}")
```

$\displaystyle \left(-11, -10\right)$

``` python
latex2sympy_interval("(-\\infty, 0) \\cup (0, \\infty)")
```

$\displaystyle \left(-\infty, 0\right) \cup \left(0, \infty\right)$

``` python
latex2sympy_interval("(a+b,b]")
```

$\displaystyle \left(a + b, b\right]$

#### Matrix / Vector

``` python
Expand All @@ -284,16 +234,12 @@ math_evaluator = EvaluatorMathBatch()
math_evaluator.latex2matrix(r"\sqrt{400\cos^2(9\pi/44)},\frac{\pi}{4}")
```

$\displaystyle \left[\begin{matrix}\sqrt{400 \cos^{2}{\left(\frac{9 \pi}{44} \right)}} & \frac{\pi}{4}\end{matrix}\right]$

``` python
math_evaluator.latex2matrix(
r"\begin{pmatrix} \frac{1}{2} & 0 & -\frac{\sqrt{3}}{2} \\ 0 & 1 & 0 \\ \frac{\sqrt{3}}{2} & 0 & \frac{1}{2} \end{pmatrix}"
)
```

$\displaystyle \left[\begin{matrix}\frac{1}{2} & 0 & - \frac{\sqrt{3}}{2}\\0 & 1 & 0\\\frac{\sqrt{3}}{2} & 0 & \frac{1}{2}\end{matrix}\right]$

``` python
test_eq(
math_evaluator.latex2matrix("\\begin{pmatrix}-18\\\\-49\\\\96\\end{pmatrix}"),
Expand Down
Loading

0 comments on commit 2ed193a

Please sign in to comment.