Files changed (7) hide show
  1. .gitignore +1 -5
  2. README.md +4 -9
  3. index.html +0 -0
  4. pyproject.toml +0 -14
  5. tasks.py +49 -690
  6. tlem.py +48 -159
  7. utils.py +152 -1190
.gitignore CHANGED
@@ -1,6 +1,2 @@
1
  __pycache__
2
- *.ju.py
3
- tests
4
-
5
- README_files
6
- .ipynb_checkpoints
 
1
  __pycache__
2
+ tlem.ju.py
 
 
 
 
README.md CHANGED
@@ -1,10 +1,5 @@
1
- ---
2
- title: TLEM
3
- emoji: 🐢
4
- colorFrom: yellow
5
- colorTo: purple
6
- sdk: static
7
- pinned: false
8
- ---
9
 
10
- Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
 
 
 
 
 
 
 
 
 
 
 
 
1
 
2
+
3
+ # Transparent LLMs Evaluation Metrics
4
+
5
+ > LLMs belong to *tout le monde*
index.html CHANGED
The diff for this file is too large to render. See raw diff
 
pyproject.toml DELETED
@@ -1,14 +0,0 @@
1
- [tool.poetry]
2
- name = "tlem"
3
- version = "0.1.0"
4
- description = ""
5
- authors = ["fecet <xiezej@gmail.com>"]
6
- readme = "README.md"
7
-
8
- [tool.poetry.dependencies]
9
- python = "^3.10"
10
-
11
-
12
- [build-system]
13
- requires = ["poetry-core"]
14
- build-backend = "poetry.core.masonry.api"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
tasks.py CHANGED
@@ -1,9 +1,8 @@
1
  from dataclasses import dataclass, field
2
-
3
  from datasets import load_dataset, Dataset
4
  from functools import cached_property
5
  from tqdm.auto import tqdm
6
- from typing import Any, Optional, Callable
7
  import logging
8
  import pandas as pd
9
  from functools import partial
@@ -14,7 +13,6 @@ from .utils import *
14
  from evaluate import load
15
  from collections import defaultdict
16
  import sys
17
- from pathlib import Path
18
 
19
 
20
  # if sys.version_info >= (3, 9):
@@ -59,15 +57,13 @@ class Task:
59
  dataset_name: str | tuple[str, str] = ("gsm8k", "main")
60
  split: str = "test"
61
  # metrics: list[str] = field(default_factory=list)
62
- metric_name: str | tuple[str, str] = ("sustech/tlem", "mmlu")
63
  input_column: str = "question"
64
  label_column: str = ""
65
- output_column: str = "generated_text"
66
  prompt: Optional[Callable | str] = None
67
  few_shot: int = 0
68
  few_shot_from: Optional[str] = None
69
  # results: dict[str, Any] = field(default_factory=dict)
70
- # outputs: Optional[list] = field(default_factory=list)
71
 
72
  def __post_init__(self):
73
  names = (
@@ -75,41 +71,28 @@ class Task:
75
  if isinstance(self.dataset_name, str)
76
  else list(self.dataset_name)
77
  )
78
- names[0] = Path(names[0]).name
79
 
80
  self.name = "-".join(names) + f"-{self.split}"
81
  if isinstance(self.prompt, str):
82
- prompt_format = self.prompt
83
  self.prompt = lambda example: {
84
- self.input_column: prompt_format.format(
85
  input_column=example[self.input_column]
86
  )
87
  }
88
  self.label_column = self.label_column or self.input_column
89
 
90
- def __eq__(self, __value: object) -> bool:
91
- return self.name == __value.name
92
-
93
  @cached_property
94
  def samples(self):
95
  return self.dataset[self.input_column]
96
 
97
- @cached_property
98
- def labels(self):
99
- return self.dataset[self.label_column]
100
-
101
- @cached_property
102
- def outputs(self):
103
- return self.dataset[self.output_column]
104
-
105
  @cached_property
106
  def dataset(self):
107
- ds = (
108
- load_dataset(
109
- *self.dataset_name,
110
- )
111
  if isinstance(self.dataset_name, tuple)
112
- else load_dataset(self.dataset_name)
 
113
  )
114
  test_ds = ds[self.split]
115
  if self.prompt is not None:
@@ -124,15 +107,12 @@ class Task:
124
 
125
  assert self.few_shot_from != self.split
126
  shots = ds[self.few_shot_from].select(range(self.few_shot))
127
- # else:
128
- # shots = ds.select(range(self.few_shot))
129
  if self.prompt is not None:
130
  shots = shots.map(self.prompt)
131
 
132
  shots = shots.map(
133
  lambda example: {
134
  self.input_column: example[self.input_column]
135
- + "\n"
136
  + example[self.label_column],
137
  }
138
  )[self.input_column]
@@ -155,37 +135,32 @@ class Task:
155
  if isinstance(self.metric_name, str)
156
  else load(*self.metric_name)
157
  )
158
- return metric._compute
159
-
160
- @property
161
- def result(self) -> dict:
162
- assert self.outputs, "Please run the task first."
163
- results = self.metric(self.outputs, self.labels)
164
- # logging.info(f"{self.name}:{results}")
165
- return results
166
 
 
167
  def run(
168
  self,
169
  pipeline,
170
  ):
171
- if self.output_column not in self.dataset.column_names:
172
- self.dataset = self.dataset.add_column(
173
- self.output_column, pipeline(self.samples)
 
 
 
 
174
  )
 
 
 
 
 
 
 
 
 
175
 
176
- return self.result
177
-
178
- async def arun(self, pipeline):
179
- self.dataset = self.dataset.add_column(
180
- self.output_column, await pipeline(self.samples)
181
- )
182
-
183
- return self.result
184
-
185
- def save(self, path):
186
- self.dataset.select_columns(
187
- [self.input_column, self.output_column, self.label_column]
188
- ).save_to_disk(path)
189
 
190
 
191
  def multichoice(responses: Any, references: list[str]):
@@ -209,52 +184,6 @@ def multichoice_zh(responses: Any, references: list[str]):
209
  class Metrics:
210
  cmmlu = multichoice_zh
211
  mmlu = multichoice
212
- truthful_qa_mc1 = multichoice
213
- ceval = multichoice_zh
214
-
215
- def winogrande(responses: list[str], answers: list[str | int]):
216
- responses = [first_option_postprocess(pred, options="AB") for pred in responses]
217
- return responses, answers
218
-
219
- def arc(responses: list[str], answers: list[str | int]):
220
- if len(responses) != len(answers):
221
- return {"error": "predictions and references have different " "length"}
222
- responses = [
223
- first_option_postprocess(pred, options="ABCD") for pred in responses
224
- ]
225
-
226
- return responses, answers
227
-
228
- def hellaswag(responses: list[str], answers: list[str | int]):
229
- if len(responses) != len(answers):
230
- return {"error": "predictions and references have different " "length"}
231
- responses = [
232
- first_option_postprocess(pred, options="ABCD") for pred in responses
233
- ]
234
- answers = ["ABCD"[int(ans)] for ans in answers]
235
- return responses, answers
236
-
237
- def drop(responses: list[str], answers: list[list]):
238
- scores = []
239
- for pred, ans in zip(responses, answers):
240
- score = np.mean([1 if a in pred else 0 for a in ans])
241
- scores.append(score)
242
- return {"em": np.mean(scores)}
243
-
244
- def bbh_mcq(responses: list[str], answers: list[str | int]):
245
- if len(responses) != len(answers):
246
- return {"error": "predictions and references have different " "length"}
247
- responses = [bbh_mcq_postprocess(pred) for pred in responses]
248
-
249
- return responses, answers
250
-
251
- def bbh_freefrom(responses: list[str], answers: list[str | int]):
252
- if len(responses) != len(answers):
253
- return {"error": "predictions and references have different " "length"}
254
-
255
- responses = [bbh_freeform_postprocess(pred) for pred in responses]
256
-
257
- return responses, answers
258
 
259
  def gsm8k(responses: list[str], answers: list[str | int]):
260
  # scores = []
@@ -270,25 +199,28 @@ class Metrics:
270
 
271
  return responses, answers
272
 
273
- def boolq(responses: list[str], answers: list[str | int]):
274
-
275
- responses = [first_capital_postprocess(response) for response in responses]
276
- answers = ["A" if answer else "B" for answer in answers]
277
-
278
- return responses, answers
279
-
280
  def MATH(responses: list[str], answers: list[str]):
281
- extract_responses = sync_pipe(get_answer)(responses)
282
- extract_answers = sync_pipe(get_answer)(answers)
283
- try:
284
- from math_equivalence import is_equiv
285
- except ImportError as e:
286
- logging.error(
287
- "math_equivalence not installed, pip install git+https://github.com/hendrycks/math.git"
288
- )
289
- raise e
290
 
291
- return sync_pipe(is_equiv)(zip(extract_responses, extract_answers))
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
292
 
293
 
294
  class CMMLU:
@@ -301,7 +233,7 @@ class CMMLU:
301
  for choice in list("ABCD"):
302
  prompt += f"\n{choice}. {example[choice]}"
303
 
304
- prompt += "\n答案:"
305
  return {"prompt": prompt}
306
 
307
  subcategories = {
@@ -398,6 +330,7 @@ class CMMLU:
398
  ],
399
  "Other": ["other"],
400
  "China specific": ["china specific"],
 
401
  }
402
 
403
  @classmethod
@@ -560,577 +493,3 @@ class MMLU:
560
  ]
561
  )
562
  return suite
563
-
564
-
565
- class Winogrande:
566
- input_column = "input"
567
- label_column = "answer"
568
-
569
- categories = [
570
- "winogrande_debiased",
571
- "winogrande_l",
572
- "winogrande_m",
573
- "winogrande_s",
574
- "winogrande_xl",
575
- "winogrande_xs",
576
- ]
577
-
578
- @classmethod
579
- def prompt_winogrande(cls, example):
580
- option1 = example["sentence"].replace("_", example["option1"])
581
- option2 = example["sentence"].replace("_", example["option2"])
582
- answer = example[cls.label_column]
583
- prompt = f"Which of the following is a good sentence:\nA. {option1}\nB. {option2}\nAnswer:"
584
-
585
- return {
586
- cls.input_column: prompt,
587
- cls.label_column: " AB"[int(answer)] if answer != "" else "",
588
- }
589
-
590
- @classmethod
591
- def suite(
592
- cls,
593
- ):
594
- subcategories = {item: [item] for item in cls.categories}
595
- finer_categories = (
596
- pd.Series(subcategories) # noqa # type: ignore
597
- .explode()
598
- .reset_index()
599
- .set_index(0)
600
- .groupby(0)
601
- .agg(list)["index"]
602
- .to_dict()
603
- )
604
- suite = defaultdict(list)
605
- subcategories["all"] = list(finer_categories.keys())
606
- for cate, sub_cates in subcategories.items():
607
- for sub_cate in sub_cates:
608
- suite[cate].append(
609
- Task(
610
- ("winogrande", sub_cate),
611
- metric_name=("sustech/tlem", "winogrande"),
612
- input_column=cls.input_column,
613
- label_column=cls.label_column,
614
- prompt=partial(cls.prompt_winogrande),
615
- few_shot=0,
616
- split="validation",
617
- )
618
- )
619
-
620
- return suite
621
-
622
-
623
- class DROP:
624
- input_column = "input"
625
- label_column = "answers"
626
-
627
- @classmethod
628
- def prompt_drop(cls, example):
629
- prompt = f"Read the following passage and answer the question.\n\n{example['passage']}\n\nQuestion: {example['question']}"
630
-
631
- return {
632
- cls.input_column: prompt,
633
- cls.label_column: ",".join(example["answers_spans"]["spans"]),
634
- }
635
-
636
- @classmethod
637
- def suite(
638
- cls,
639
- ):
640
- return Task(
641
- "drop",
642
- metric_name=("sustech/tlem", "drop"),
643
- input_column=cls.input_column,
644
- label_column=cls.label_column,
645
- prompt=partial(cls.prompt_drop),
646
- few_shot=3,
647
- few_shot_from="train",
648
- split="validation",
649
- )
650
-
651
-
652
- class HellaSwag:
653
- input_column = "input"
654
- label_column = "label"
655
-
656
- categories = ["validation"]
657
-
658
- @classmethod
659
- def prompt_hellaswag(cls, example):
660
- prompt = f"{example['ctx']}\nQuestion: Which ending makes the most sense?\n"
661
- prompt += f"A. {example['endings'][0]}\n"
662
- prompt += f"B. {example['endings'][1]}\n"
663
- prompt += f"C. {example['endings'][2]}\n"
664
- prompt += f"D. {example['endings'][3]}\n"
665
- prompt += "You may choose from 'A', 'B', 'C', 'D'.\nAnswer:"
666
-
667
- return {cls.input_column: prompt}
668
-
669
- @classmethod
670
- def suite(
671
- cls,
672
- ):
673
- finer_categories = (
674
- pd.Series(cls.categories) # noqa # type: ignore
675
- .explode()
676
- .reset_index()
677
- .set_index(0)
678
- .groupby(0)
679
- .agg(list)["index"]
680
- .to_dict()
681
- )
682
- suite = defaultdict(list)
683
- categories = list(finer_categories.keys())
684
- for cate in categories:
685
- suite[cate].append(
686
- Task(
687
- ("Rowan/hellaswag", cate),
688
- metric_name=("sustech/tlem", "hellaswag"),
689
- input_column=cls.input_column,
690
- label_column=cls.label_column,
691
- prompt=partial(cls.prompt_hellaswag),
692
- few_shot=0,
693
- split="validation",
694
- )
695
- )
696
-
697
- return suite
698
-
699
-
700
- class ARC:
701
- input_column = "input"
702
- label_column = "answerKey"
703
-
704
- categories = [
705
- "ARC-Challenge",
706
- "ARC-Easy",
707
- ]
708
-
709
- @classmethod
710
- def prompt_arc(cls, example):
711
- choices = example["choices"]
712
- prompt = f"Question: {example['question']}"
713
- for label, choice in zip(choices["label"], choices["text"]):
714
- prompt += f"\n{label}. {choice}"
715
- prompt += "\nAnswer:"
716
- return {cls.input_column: prompt}
717
-
718
- @classmethod
719
- def suite(cls):
720
- suite = [
721
- Task(
722
- ("ai2_arc", subset),
723
- metric_name=("sustech/tlem", "arc"),
724
- input_column=cls.input_column,
725
- label_column=cls.label_column,
726
- prompt=partial(cls.prompt_arc),
727
- few_shot=0,
728
- )
729
- for subset in cls.categories
730
- ]
731
-
732
- return suite
733
-
734
-
735
- class BBH:
736
- input_column = "input"
737
- label_column = "target"
738
-
739
- multiple_choice_prefix = "Follow the given examples and answer the question.\n[HINT]\n\nQ: [INPUT]\nA: Let's think step by step."
740
- free_form_prefix = "Follow the given examples and answer the question.\n[HINT]\n\nQ: [INPUT]\nA: Let's think step by step."
741
-
742
- bbh_multiple_choice_sets = [
743
- "temporal_sequences",
744
- "disambiguation_qa",
745
- "date_understanding",
746
- "tracking_shuffled_objects_three_objects",
747
- "penguins_in_a_table",
748
- "geometric_shapes",
749
- "snarks",
750
- "ruin_names",
751
- "tracking_shuffled_objects_seven_objects",
752
- "tracking_shuffled_objects_five_objects",
753
- "logical_deduction_three_objects",
754
- "hyperbaton",
755
- "logical_deduction_five_objects",
756
- "logical_deduction_seven_objects",
757
- "movie_recommendation",
758
- "salient_translation_error_detection",
759
- "reasoning_about_colored_objects",
760
- ]
761
-
762
- bbh_free_form_sets = [
763
- "multistep_arithmetic_two",
764
- "navigate",
765
- "dyck_languages",
766
- "word_sorting",
767
- "sports_understanding",
768
- "boolean_expressions",
769
- "object_counting",
770
- "formal_fallacies",
771
- "causal_judgement",
772
- "web_of_lies",
773
- ]
774
-
775
- @classmethod
776
- def prompt_bbh(cls, example, category: str):
777
- meta_prompt = (
778
- cls.multiple_choice_prefix
779
- if category in cls.bbh_multiple_choice_sets
780
- else cls.free_form_prefix
781
- )
782
- prompt = meta_prompt.replace(
783
- "[HINT]", bbh_lib_prompt(category=category)
784
- ).replace("[INPUT]", example[cls.input_column])
785
-
786
- return {"input": prompt}
787
-
788
- @classmethod
789
- def suite(
790
- cls,
791
- ):
792
- suite = []
793
- for cate in cls.bbh_multiple_choice_sets:
794
- suite.append(
795
- Task(
796
- ("lukaemon/bbh", cate),
797
- metric_name=("sustech/tlem", "bbh_mcq"),
798
- input_column=cls.input_column,
799
- label_column=cls.label_column,
800
- prompt=partial(cls.prompt_bbh, category=cate),
801
- few_shot=0,
802
- )
803
- )
804
- for cate in cls.bbh_free_form_sets:
805
- suite.append(
806
- Task(
807
- ("lukaemon/bbh", cate),
808
- metric_name=("sustech/tlem", "bbh_freefrom"),
809
- input_column=cls.input_column,
810
- label_column=cls.label_column,
811
- prompt=partial(cls.prompt_bbh, category=cate),
812
- few_shot=0,
813
- )
814
- )
815
-
816
- return suite
817
-
818
-
819
- class BoolQ:
820
- input_column = "input"
821
- label_column = "answer"
822
-
823
- @classmethod
824
- def prompt_boolq(cls, example, chat=False):
825
-
826
- prompt = f"{example['passage']}\nQuestion: {example['question']}\nA. Yes\nB. No\nAnswer: "
827
-
828
- return {"input": prompt}
829
-
830
- @classmethod
831
- def suite(cls, chat: bool):
832
-
833
- suite = [
834
- Task(
835
- dataset_name="boolq",
836
- metric_name=("sustech/tlem", "boolq"),
837
- input_column=cls.input_column,
838
- label_column=cls.label_column,
839
- prompt=partial(cls.prompt_boolq, chat=chat),
840
- few_shot=0 if chat else 5,
841
- few_shot_from="train",
842
- split="validation",
843
- )
844
- ]
845
-
846
- return suite
847
-
848
- class TruthfulQAMC1:
849
- input_column = "input"
850
- label_column = "answer"
851
-
852
- @classmethod
853
- def prompt_truthful_qa(cls, example):
854
-
855
- target = example["mc1_targets"]
856
- choices = target["choices"]
857
- labels = target["labels"]
858
-
859
- prompt = f"The following is a multiple-choice question. Please choose the most suitable one as the answer to this question.\n\n"
860
- prompt += example["question"]
861
-
862
- answer = []
863
-
864
- for idx, choice, label in zip(list("ABCDEFGHIJ")[:len(choices)], choices, labels):
865
-
866
- prompt += f"\n{idx}. {choice}"
867
-
868
- if label == 1:
869
- answer = idx
870
-
871
- prompt += "\nAnswer: "
872
-
873
- return {
874
- "input": prompt,
875
- "answer": answer
876
- }
877
-
878
- @classmethod
879
- def suite(cls):
880
- suite = [
881
- Task(
882
- dataset_name=("truthful_qa", "multiple_choice"),
883
- metric_name=("sustech/tlem", "truthful_qa_mc1"),
884
- input_column=cls.input_column,
885
- label_column=cls.label_column,
886
- prompt=partial(cls.prompt_truthful_qa),
887
- few_shot=0,
888
- split="validation",
889
- )
890
- ]
891
-
892
- return suite
893
-
894
- class CEVAL:
895
- input_column = "input"
896
- label_column = "answer"
897
-
898
- @classmethod
899
- def prompt_ceval(cls, example, cate: str, chat=False):
900
- _ch_name = cls.ceval_subject_mapping[cate][1]
901
- prefix = f"以下是中国关于{_ch_name}考试的单项选择题,请选出其中的正确答案。\n" if chat else "问题:"
902
-
903
- prompt = prefix + f'{example["question"]}'
904
- for choice in list("ABCD"):
905
- prompt += f"\n{choice}. {example[choice]}"
906
-
907
- prompt += "\n答案:"
908
- return {"input": prompt}
909
-
910
- ceval_subject_mapping = {
911
- "computer_network": [
912
- "Computer Network",
913
- "\u8ba1\u7b97\u673a\u7f51\u7edc",
914
- "STEM",
915
- ],
916
- "operating_system": ["Operating System", "\u64cd\u4f5c\u7cfb\u7edf", "STEM"],
917
- "computer_architecture": [
918
- "Computer Architecture",
919
- "\u8ba1\u7b97\u673a\u7ec4\u6210",
920
- "STEM",
921
- ],
922
- "college_programming": [
923
- "College Programming",
924
- "\u5927\u5b66\u7f16\u7a0b",
925
- "STEM",
926
- ],
927
- "college_physics": ["College Physics", "\u5927\u5b66\u7269\u7406", "STEM"],
928
- "college_chemistry": ["College Chemistry", "\u5927\u5b66\u5316\u5b66", "STEM"],
929
- "advanced_mathematics": [
930
- "Advanced Mathematics",
931
- "\u9ad8\u7b49\u6570\u5b66",
932
- "STEM",
933
- ],
934
- "probability_and_statistics": [
935
- "Probability and Statistics",
936
- "\u6982\u7387\u7edf\u8ba1",
937
- "STEM",
938
- ],
939
- "discrete_mathematics": [
940
- "Discrete Mathematics",
941
- "\u79bb\u6563\u6570\u5b66",
942
- "STEM",
943
- ],
944
- "electrical_engineer": [
945
- "Electrical Engineer",
946
- "\u6ce8\u518c\u7535\u6c14\u5de5\u7a0b\u5e08",
947
- "STEM",
948
- ],
949
- "metrology_engineer": [
950
- "Metrology Engineer",
951
- "\u6ce8\u518c\u8ba1\u91cf\u5e08",
952
- "STEM",
953
- ],
954
- "high_school_mathematics": [
955
- "High School Mathematics",
956
- "\u9ad8\u4e2d\u6570\u5b66",
957
- "STEM",
958
- ],
959
- "high_school_physics": [
960
- "High School Physics",
961
- "\u9ad8\u4e2d\u7269\u7406",
962
- "STEM",
963
- ],
964
- "high_school_chemistry": [
965
- "High School Chemistry",
966
- "\u9ad8\u4e2d\u5316\u5b66",
967
- "STEM",
968
- ],
969
- "high_school_biology": [
970
- "High School Biology",
971
- "\u9ad8\u4e2d\u751f\u7269",
972
- "STEM",
973
- ],
974
- "middle_school_mathematics": [
975
- "Middle School Mathematics",
976
- "\u521d\u4e2d\u6570\u5b66",
977
- "STEM",
978
- ],
979
- "middle_school_biology": [
980
- "Middle School Biology",
981
- "\u521d\u4e2d\u751f\u7269",
982
- "STEM",
983
- ],
984
- "middle_school_physics": [
985
- "Middle School Physics",
986
- "\u521d\u4e2d\u7269\u7406",
987
- "STEM",
988
- ],
989
- "middle_school_chemistry": [
990
- "Middle School Chemistry",
991
- "\u521d\u4e2d\u5316\u5b66",
992
- "STEM",
993
- ],
994
- "veterinary_medicine": ["Veterinary Medicine", "\u517d\u533b\u5b66", "STEM"],
995
- "college_economics": [
996
- "College Economics",
997
- "\u5927\u5b66\u7ecf\u6d4e\u5b66",
998
- "Social Science",
999
- ],
1000
- "business_administration": [
1001
- "Business Administration",
1002
- "\u5de5\u5546\u7ba1\u7406",
1003
- "Social Science",
1004
- ],
1005
- "marxism": [
1006
- "Marxism",
1007
- "\u9a6c\u514b\u601d\u4e3b\u4e49\u57fa\u672c\u539f\u7406",
1008
- "Social Science",
1009
- ],
1010
- "mao_zedong_thought": [
1011
- "Mao Zedong Thought",
1012
- "\u6bdb\u6cfd\u4e1c\u601d\u60f3\u548c\u4e2d\u56fd\u7279\u8272\u793e\u4f1a\u4e3b\u4e49\u7406\u8bba\u4f53\u7cfb\u6982\u8bba",
1013
- "Social Science",
1014
- ],
1015
- "education_science": [
1016
- "Education Science",
1017
- "\u6559\u80b2\u5b66",
1018
- "Social Science",
1019
- ],
1020
- "teacher_qualification": [
1021
- "Teacher Qualification",
1022
- "\u6559\u5e08\u8d44\u683c",
1023
- "Social Science",
1024
- ],
1025
- "high_school_politics": [
1026
- "High School Politics",
1027
- "\u9ad8\u4e2d\u653f\u6cbb",
1028
- "Social Science",
1029
- ],
1030
- "high_school_geography": [
1031
- "High School Geography",
1032
- "\u9ad8\u4e2d\u5730\u7406",
1033
- "Social Science",
1034
- ],
1035
- "middle_school_politics": [
1036
- "Middle School Politics",
1037
- "\u521d\u4e2d\u653f\u6cbb",
1038
- "Social Science",
1039
- ],
1040
- "middle_school_geography": [
1041
- "Middle School Geography",
1042
- "\u521d\u4e2d\u5730\u7406",
1043
- "Social Science",
1044
- ],
1045
- "modern_chinese_history": [
1046
- "Modern Chinese History",
1047
- "\u8fd1\u4ee3\u53f2\u7eb2\u8981",
1048
- "Humanities",
1049
- ],
1050
- "ideological_and_moral_cultivation": [
1051
- "Ideological and Moral Cultivation",
1052
- "\u601d\u60f3\u9053\u5fb7\u4fee\u517b\u4e0e\u6cd5\u5f8b\u57fa\u7840",
1053
- "Humanities",
1054
- ],
1055
- "logic": ["Logic", "\u903b\u8f91\u5b66", "Humanities"],
1056
- "law": ["Law", "\u6cd5\u5b66", "Humanities"],
1057
- "chinese_language_and_literature": [
1058
- "Chinese Language and Literature",
1059
- "\u4e2d\u56fd\u8bed\u8a00\u6587\u5b66",
1060
- "Humanities",
1061
- ],
1062
- "art_studies": ["Art Studies", "\u827a\u672f\u5b66", "Humanities"],
1063
- "professional_tour_guide": [
1064
- "Professional Tour Guide",
1065
- "\u5bfc\u6e38\u8d44\u683c",
1066
- "Humanities",
1067
- ],
1068
- "legal_professional": [
1069
- "Legal Professional",
1070
- "\u6cd5\u5f8b\u804c\u4e1a\u8d44\u683c",
1071
- "Humanities",
1072
- ],
1073
- "high_school_chinese": [
1074
- "High School Chinese",
1075
- "\u9ad8\u4e2d\u8bed\u6587",
1076
- "Humanities",
1077
- ],
1078
- "high_school_history": [
1079
- "High School History",
1080
- "\u9ad8\u4e2d\u5386\u53f2",
1081
- "Humanities",
1082
- ],
1083
- "middle_school_history": [
1084
- "Middle School History",
1085
- "\u521d\u4e2d\u5386\u53f2",
1086
- "Humanities",
1087
- ],
1088
- "civil_servant": ["Civil Servant", "\u516c\u52a1\u5458", "Other"],
1089
- "sports_science": ["Sports Science", "\u4f53\u80b2\u5b66", "Other"],
1090
- "plant_protection": ["Plant Protection", "\u690d\u7269\u4fdd\u62a4", "Other"],
1091
- "basic_medicine": ["Basic Medicine", "\u57fa\u7840\u533b\u5b66", "Other"],
1092
- "clinical_medicine": ["Clinical Medicine", "\u4e34\u5e8a\u533b\u5b66", "Other"],
1093
- "urban_and_rural_planner": [
1094
- "Urban and Rural Planner",
1095
- "\u6ce8\u518c\u57ce\u4e61\u89c4\u5212\u5e08",
1096
- "Other",
1097
- ],
1098
- "accountant": ["Accountant", "\u6ce8\u518c\u4f1a\u8ba1\u5e08", "Other"],
1099
- "fire_engineer": [
1100
- "Fire Engineer",
1101
- "\u6ce8\u518c\u6d88\u9632\u5de5\u7a0b\u5e08",
1102
- "Other",
1103
- ],
1104
- "environmental_impact_assessment_engineer": [
1105
- "Environmental Impact Assessment Engineer",
1106
- "\u73af\u5883\u5f71\u54cd\u8bc4\u4ef7\u5de5\u7a0b\u5e08",
1107
- "Other",
1108
- ],
1109
- "tax_accountant": ["Tax Accountant", "\u7a0e\u52a1\u5e08", "Other"],
1110
- "physician": ["Physician", "\u533b\u5e08\u8d44\u683c", "Other"],
1111
- }
1112
-
1113
- @classmethod
1114
- def suite(cls, chat: bool):
1115
- suite = defaultdict(list)
1116
- cls.categories = defaultdict(list)
1117
- for task, info in cls.ceval_subject_mapping.items():
1118
- cls.categories[info[0]].append(task)
1119
- cls.categories[info[2]].append(task)
1120
- cls.categories["all"] = list(cls.ceval_subject_mapping.keys())
1121
- for k, v in cls.categories.items():
1122
- for subject in v:
1123
- suite[k].append(
1124
- Task(
1125
- dataset_name=("ceval/ceval-exam", subject),
1126
- metric_name=("sustech/tlem", "ceval"),
1127
- input_column=cls.input_column,
1128
- label_column=cls.label_column,
1129
- prompt=partial(cls.prompt_ceval, cate=subject, chat=chat),
1130
- few_shot=0 if chat else 5,
1131
- few_shot_from="dev",
1132
- split="val",
1133
- )
1134
- )
1135
-
1136
- return suite
 
1
  from dataclasses import dataclass, field
 
2
  from datasets import load_dataset, Dataset
3
  from functools import cached_property
4
  from tqdm.auto import tqdm
5
+ from typing import Any, Optional, Protocol, Iterable, Callable
6
  import logging
7
  import pandas as pd
8
  from functools import partial
 
13
  from evaluate import load
14
  from collections import defaultdict
15
  import sys
 
16
 
17
 
18
  # if sys.version_info >= (3, 9):
 
57
  dataset_name: str | tuple[str, str] = ("gsm8k", "main")
58
  split: str = "test"
59
  # metrics: list[str] = field(default_factory=list)
60
+ metric_name: str | tuple[str, str] = ("sustech/tlem", "gsm8k")
61
  input_column: str = "question"
62
  label_column: str = ""
 
63
  prompt: Optional[Callable | str] = None
64
  few_shot: int = 0
65
  few_shot_from: Optional[str] = None
66
  # results: dict[str, Any] = field(default_factory=dict)
 
67
 
68
  def __post_init__(self):
69
  names = (
 
71
  if isinstance(self.dataset_name, str)
72
  else list(self.dataset_name)
73
  )
74
+ names[0] = names[0].split("/")[-1]
75
 
76
  self.name = "-".join(names) + f"-{self.split}"
77
  if isinstance(self.prompt, str):
 
78
  self.prompt = lambda example: {
79
+ self.input_column: self.prompt.format(
80
  input_column=example[self.input_column]
81
  )
82
  }
83
  self.label_column = self.label_column or self.input_column
84
 
 
 
 
85
  @cached_property
86
  def samples(self):
87
  return self.dataset[self.input_column]
88
 
 
 
 
 
 
 
 
 
89
  @cached_property
90
  def dataset(self):
91
+ ds = load_dataset(
92
+ *self.dataset_name
 
 
93
  if isinstance(self.dataset_name, tuple)
94
+ else self.dataset_name,
95
+ # split=self.split,
96
  )
97
  test_ds = ds[self.split]
98
  if self.prompt is not None:
 
107
 
108
  assert self.few_shot_from != self.split
109
  shots = ds[self.few_shot_from].select(range(self.few_shot))
 
 
110
  if self.prompt is not None:
111
  shots = shots.map(self.prompt)
112
 
113
  shots = shots.map(
114
  lambda example: {
115
  self.input_column: example[self.input_column]
 
116
  + example[self.label_column],
117
  }
118
  )[self.input_column]
 
135
  if isinstance(self.metric_name, str)
136
  else load(*self.metric_name)
137
  )
138
+ return metric
 
 
 
 
 
 
 
139
 
140
+ # @cache
141
  def run(
142
  self,
143
  pipeline,
144
  ):
145
+ if (outputs := pipeline(self.samples)) is None:
146
+ logging.warning("pipeline returns None")
147
+ return
148
+ self.outputs = outputs
149
+ try:
150
+ result = self.metric._compute(
151
+ responses=outputs, references=self.dataset[self.label_column]
152
  )
153
+ except Exception as e:
154
+ result = self.metric.compute(
155
+ responses=outputs, references=self.dataset[self.label_column]
156
+ )
157
+ finally:
158
+ result = outputs
159
+ # if log:
160
+ # name = name or pipeline.__name__
161
+ # self.results[name] = result
162
 
163
+ return result
 
 
 
 
 
 
 
 
 
 
 
 
164
 
165
 
166
  def multichoice(responses: Any, references: list[str]):
 
184
  class Metrics:
185
  cmmlu = multichoice_zh
186
  mmlu = multichoice
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
187
 
188
  def gsm8k(responses: list[str], answers: list[str | int]):
189
  # scores = []
 
199
 
200
  return responses, answers
201
 
 
 
 
 
 
 
 
202
  def MATH(responses: list[str], answers: list[str]):
203
+ scores = []
 
 
 
 
 
 
 
 
204
 
205
+ for response, answer in zip(responses, answers):
206
+ indices = [pos for pos, char in enumerate(response) if char == "$"]
207
+ if len(indices) <= 2:
208
+ scores.append(0)
209
+ continue
210
+ else:
211
+ result = response[indices[-2] + 1 : indices[-1]]
212
+ gold = get_answer(answer)
213
+ scores.append(1.0 * is_equiv(result, gold))
214
+
215
+ return scores
216
+
217
+ def math23k(responses: list[str], answers: list[str]):
218
+ scores = []
219
+ for response, answer in zip(responses, answers):
220
+ pred = extract_numeric(response, pattern=NUMERIC_IN_ZH)
221
+ gold = extract_numeric(answer, pattern=NUMERIC_IN_ZH)
222
+ scores.append(1.0 * (pred == gold))
223
+ return scores
224
 
225
 
226
  class CMMLU:
 
233
  for choice in list("ABCD"):
234
  prompt += f"\n{choice}. {example[choice]}"
235
 
236
+ prompt += "\n答案:"
237
  return {"prompt": prompt}
238
 
239
  subcategories = {
 
330
  ],
331
  "Other": ["other"],
332
  "China specific": ["china specific"],
333
+ "Test": ["computer science"],
334
  }
335
 
336
  @classmethod
 
493
  ]
494
  )
495
  return suite
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
tlem.py CHANGED
@@ -1,6 +1,12 @@
1
- import logging
 
 
 
 
 
2
 
3
  from typing import Any, Optional, Protocol, Iterable, Callable
 
4
  from tqdm.auto import tqdm
5
  from evaluate.evaluation_suite import EvaluationSuite
6
  import evaluate
@@ -8,10 +14,7 @@ import numpy as np
8
  import datasets
9
  import pandas as pd
10
  from .tasks import *
11
- from .utils import *
12
- from itertools import chain
13
- from copy import deepcopy
14
- from . import utils
15
 
16
 
17
  class ReasoningMetric(evaluate.Metric):
@@ -43,60 +46,31 @@ class ReasoningMetric(evaluate.Metric):
43
  reference_urls=["http://path.to.reference.url/new_module"],
44
  )
45
 
46
- def _compute(self, responses, references):
47
- return_value = getattr(Metrics, self.config_name)(responses, references)
48
- match return_value:
49
- case extract_responses, extract_references:
50
- results = {
51
- self.config_name: np.mean(
52
- sync_pipe(lambda x, y: x == y)(
53
- zip(extract_responses, extract_references)
54
- )
55
- )
56
- }
57
- case dict():
58
- results = return_value
59
-
60
- case list():
61
- results = {self.config_name: np.mean(return_value)}
62
-
63
- case _:
64
- raise NotImplementedError
65
-
66
  return results
67
 
68
 
69
  class Suite(EvaluationSuite):
70
  task_class = Task
71
- utils = utils
72
- supported_datasets = [
73
- "arc",
74
- "hellaswag",
75
- "mmlu-chat",
76
- "winogrande",
77
- "gsm8k",
78
- "cmmlu-chat",
79
- "ceval-chat",
80
- "bbh",
81
- "drop",
82
- "MATH",
83
- ]
84
-
85
- def __getitem__(self, key) -> Task:
86
- match key:
87
- case str():
88
- return self.suite[key]
89
- case slice() | int():
90
- return self.tasks[key]
91
-
92
- def agg(self, suite):
93
- for cate, tasks in suite.items():
94
- if isinstance(tasks, dict):
95
- suite[cate] = self.agg(tasks)
96
- else:
97
- suite[cate] = np.mean([pd.Series(task.result).mean() for task in tasks])
98
-
99
- return suite
100
 
101
  def run(
102
  self,
@@ -104,26 +78,28 @@ class Suite(EvaluationSuite):
104
  ) -> dict[str, float]:
105
  self.assert_suite_nonempty()
106
 
107
- self.suite: dict[str, list[Task]]
108
- for task in (bar := tqdm(self.tasks)):
109
- bar.desc = f"complete {task.name}."
110
- _ = task.run(model_or_pipeline)
111
- logging.info(f"{task.name} {task.result=}")
112
- return self.agg(deepcopy(self.suite))
 
113
 
114
- def arun(self, model_or_pipeline):
115
- async def sync_function():
116
- return await tqdm.gather(
117
- *[task.arun(model_or_pipeline) for task in self.tasks], leave=False
118
- )
 
119
 
120
- asyncio.run(sync_function())
121
 
122
- return self.agg(deepcopy(self.suite))
 
123
 
124
- def get_suite(self, name) -> dict[str, Task]:
125
  chat = False
126
- suite={}
127
  match name:
128
  case _ if "chat" in name:
129
  chat = True
@@ -132,8 +108,6 @@ class Suite(EvaluationSuite):
132
  suite = MMLU.suite(chat=chat)
133
  case _ if name.startswith("cmmlu"):
134
  suite = CMMLU.suite(chat=chat)
135
- case _ if name.startswith("ceval"):
136
- suite = CEVAL.suite(chat=chat)
137
  case "gsm8k":
138
  suite = Task(
139
  dataset_name=("gsm8k", "main"),
@@ -141,20 +115,6 @@ class Suite(EvaluationSuite):
141
  input_column="question",
142
  label_column="answer",
143
  )
144
- case "bbh":
145
- suite = BBH.suite()
146
- case "arc":
147
- suite = ARC.suite()
148
- case "hellaswag":
149
- suite = HellaSwag.suite()
150
- case "drop":
151
- suite = DROP.suite()
152
- case "winogrande":
153
- suite = Winogrande.suite()
154
- case "truthfulqa_mc1":
155
- suite = TruthfulQAMC1.suite()
156
- case _ if name.startswith("boolq"):
157
- suite = BoolQ.suite(chat=chat)
158
  case "mt_bench":
159
  suite = Task(
160
  dataset_name="SUSTech/mt_bench_judge",
@@ -162,81 +122,10 @@ class Suite(EvaluationSuite):
162
  prompt=mt_bench_prompt
163
  # metric_name=("sustech/tlem", "gsm8k"),
164
  )
165
- case "MATH" | "competition_math":
166
- suite = Task(
167
- dataset_name="hendrycks/competition_math",
168
- prompt="This is a math problem, please think step by step and slove it: {input_column}. Simplify your final answer as much as possible and surround them with '$' in TeX form.",
169
- metric_name=("sustech/tlem", "MATH"),
170
- input_column="problem",
171
- label_column="solution",
172
- )
173
-
174
- case "open-leaderboard":
175
- for name in [
176
- "arc",
177
- "hellaswag",
178
- "mmlu-chat",
179
- "winogrande",
180
- "gsm8k",
181
- # "truthful_qa",
182
- "drop",
183
- ]:
184
- suite.update(self.get_suite(name))
185
- case "tlem":
186
- for name in [
187
- "arc",
188
- "hellaswag",
189
- "mmlu-chat",
190
- "winogrande",
191
- "gsm8k",
192
- # "truthful_qa",
193
- "cmmlu-chat",
194
- "ceval-chat",
195
- "bbh",
196
- ]:
197
- suite.update(self.get_suite(name))
198
-
199
- case "all":
200
- for name in self.supported_datasets:
201
- suite.update(self.get_suite(name))
202
- case _:
203
- raise NotImplementedError(
204
- f"{name} is not supported in {self.supported_datasets}"
205
- )
206
-
207
- if isinstance(suite, Task):
208
- suite = [suite]
209
- suite = {name: suite}
210
-
211
- return suite
212
-
213
- def singleton(self, task):
214
- try:
215
- return self.tasks[self.tasks.index(task)]
216
- except ValueError:
217
- logging.debug(f"add {task.name} to suite.")
218
- self.tasks.append(task)
219
- logging.debug(self.tasks)
220
- return self.tasks[-1]
221
-
222
- def drop_duplicates(self, suite):
223
- for category, tasks in suite.items():
224
- match tasks:
225
- case list():
226
- suite[category] = [self.singleton(task) for task in tasks]
227
- case dict():
228
- suite[category] = self.drop_duplicates(tasks)
229
- case _:
230
- raise NotImplementedError
231
- return suite
232
 
233
- def load(self, name):
234
- sub_suite = self.get_suite(name)
235
- self.suite.update(sub_suite)
236
- self.suite = self.drop_duplicates(self.suite)
237
- # return self
238
 
239
  def __init__(self, name="tlem"):
240
  super().__init__(name)
241
- self.tasks = []
242
- self.suite = {}
 
1
+ # %%
2
+
3
+ try:
4
+ from ipytorch import logging
5
+ except Exception as e:
6
+ import logging
7
 
8
  from typing import Any, Optional, Protocol, Iterable, Callable
9
+ from numpy.lib import extract
10
  from tqdm.auto import tqdm
11
  from evaluate.evaluation_suite import EvaluationSuite
12
  import evaluate
 
14
  import datasets
15
  import pandas as pd
16
  from .tasks import *
17
+ from .utils import is_equiv
 
 
 
18
 
19
 
20
  class ReasoningMetric(evaluate.Metric):
 
46
  reference_urls=["http://path.to.reference.url/new_module"],
47
  )
48
 
49
+ def _compute(self, responses, references, verbose=False):
50
+ extract_responses, extract_references = getattr(Metrics, self.config_name)(
51
+ responses, references
52
+ )
53
+ df = pd.DataFrame(
54
+ {
55
+ "responses": responses,
56
+ "references": references,
57
+ }
58
+ )
59
+ df["extract_responses"] = extract_responses
60
+ df["extract_references"] = extract_references
61
+ results = {
62
+ "Accuracy": (df["extract_references"] == df["extract_responses"])
63
+ .astype(int)
64
+ .mean(),
65
+ }
66
+ logging.info(results)
67
+ if verbose:
68
+ results["df"] = df
69
  return results
70
 
71
 
72
  class Suite(EvaluationSuite):
73
  task_class = Task
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
74
 
75
  def run(
76
  self,
 
78
  ) -> dict[str, float]:
79
  self.assert_suite_nonempty()
80
 
81
+ def run_tasks(tasks):
82
+ for task in (bar := tqdm(tasks, leave=False)):
83
+ bar.desc = f"complete {task.name}."
84
+ if task.name not in self.cached_result:
85
+ self.cached_result[task.name] = task.run(model_or_pipeline)
86
+ results = [self.cached_result[task.name] for task in tasks]
87
+ return pd.DataFrame(results).mean().to_dict()
88
 
89
+ if isinstance(self.suite, dict):
90
+ for category, tasks in (bar := tqdm(self.suite.items())):
91
+ bar.desc = f"complete {category}."
92
+ logging.warning(f"Combined results {category}: {run_tasks(tasks)}")
93
+ else:
94
+ logging.warning(f"Combined results: {run_tasks(self.suite)}")
95
 
96
+ return self.cached_result
97
 
98
+ def add(self, name):
99
+ self.load(name)
100
 
101
+ def load(self, name):
102
  chat = False
 
103
  match name:
104
  case _ if "chat" in name:
105
  chat = True
 
108
  suite = MMLU.suite(chat=chat)
109
  case _ if name.startswith("cmmlu"):
110
  suite = CMMLU.suite(chat=chat)
 
 
111
  case "gsm8k":
112
  suite = Task(
113
  dataset_name=("gsm8k", "main"),
 
115
  input_column="question",
116
  label_column="answer",
117
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
118
  case "mt_bench":
119
  suite = Task(
120
  dataset_name="SUSTech/mt_bench_judge",
 
122
  prompt=mt_bench_prompt
123
  # metric_name=("sustech/tlem", "gsm8k"),
124
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
125
 
126
+ self.suite = [suite] if isinstance(suite, Task) else suite
 
 
 
 
127
 
128
  def __init__(self, name="tlem"):
129
  super().__init__(name)
130
+ self.cached_result = {}
131
+ self.suite = []
utils.py CHANGED
@@ -2,8 +2,6 @@ import logging
2
  import re
3
  import numpy as np
4
  from typing import Any
5
- from tqdm.auto import tqdm
6
- import asyncio
7
 
8
  NUMERIC_IN_EN = r"(?:[\s=+-/<>($:\.\*\\])(?=\S)((?:0|(?:\d{1,3}(?:,\d{3})+(?=\D|$))|(?:\d+))(?:\.\d+)?%?)(?:(?![^\s=+-/>)$:\.\*\\])|(?=, ))"
9
  NUMERIC_IN_ZH = (
@@ -11,38 +9,6 @@ NUMERIC_IN_ZH = (
11
  )
12
 
13
 
14
- def async_pipe(func):
15
- async def sync_function(samples):
16
- if not isinstance(samples, list):
17
- samples = [samples]
18
- return await tqdm.gather(*[func(sample) for sample in samples], leave=False)
19
-
20
- def sync_func(samples):
21
- return asyncio.run(sync_function(samples))
22
-
23
- return sync_func
24
-
25
-
26
- def sync_pipe(func, progress=False):
27
- def sync_func(samples):
28
- return [
29
- func(*sample) if isinstance(sample, tuple) else func(sample)
30
- for sample in tqdm(samples, disable=not progress, leave=False)
31
- ]
32
-
33
- return sync_func
34
-
35
-
36
- def asis_backup(func):
37
- def wrapper(sample):
38
- try:
39
- return func(sample)
40
- except Exception:
41
- return sample
42
-
43
- return wrapper
44
-
45
-
46
  def extract_choice_zh(gen):
47
  # 答案是A | 选项是A | 应该选A选项
48
  res = re.search(
@@ -74,27 +40,27 @@ def extract_choice_zh(gen):
74
  def extract_choice(gen):
75
  # answer is A | choice is A | choose A
76
  res = re.search(
77
- r"(?:(?:[Cc]hoose)|(?:(?:[Aa]nswer|[Cc]hoice)(?![^ABCDEFGHIJKL]{0,20}?(?:n't|not))[^ABCDEFGHIJKL]{0,10}?\b(?:|is|:|be))\b)[^ABCDEFGHIJKL]{0,20}?\b(A|B|C|D|E|F|G|H|I|J|K|L)\b",
78
  gen,
79
  )
80
 
81
  # A is correct | A is right
82
  if res is None:
83
  res = re.search(
84
- r"\b(A|B|C|D|E|F|G|H|I|J|K|L)\b(?![^ABCDEFGHIJKL]{0,8}?(?:n't|not)[^ABCDEFGHIJKL]{0,5}?(?:correct|right))[^ABCDEFGHIJKL]{0,10}?\b(?:correct|right)\b",
85
  gen,
86
  )
87
 
88
  # straight answer: A
89
  if res is None:
90
- res = re.search(r"^(A|B|C|D|E|F|G|H|I|J|K|L)(?:\.|,|:|$)", gen)
91
 
92
  # simply extract the first appearred letter
93
  if res is None:
94
- res = re.search(r"(?<![a-zA-Z])(A|B|C|D|E|F|G|H|I|J|K|L)(?![a-zA-Z=])", gen)
95
 
96
  if res is None:
97
- res = "L"
98
 
99
  if isinstance(res, str):
100
  return res
@@ -136,20 +102,17 @@ def extract_numeric(string, pattern=NUMERIC_IN_EN) -> str:
136
 
137
 
138
  def remove_boxed(s):
139
- try:
140
- if (left := "\\boxed ") in s:
141
- assert s[: len(left)] == left, s
142
- return s[len(left) :]
143
- elif (left := "\\boxed{") in s:
144
- assert s[: len(left)] == left, s
145
- return s[len(left) : -1]
146
 
147
- elif (left := "\\fbox{") in s:
148
- assert s[: len(left)] == left, s
149
- return s[len(left) : -1]
150
- raise ValueError(f"Cannot remove boxed from {s}")
151
- except AssertionError:
152
- return s
153
 
154
 
155
  def last_boxed_only_string(string):
@@ -182,1168 +145,167 @@ def last_boxed_only_string(string):
182
  return retval
183
 
184
 
185
- @asis_backup
186
- def get_answer(string):
187
- if boxed := last_boxed_only_string(string):
188
- return remove_boxed(boxed)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
189
  else:
190
- indices = [pos for pos, char in enumerate(string) if char == "$"]
191
- if len(indices) < 2:
192
- return extract_numeric(string)
193
- string = string[indices[-2] + 1 : indices[-1]]
194
- return string.split("=")[-1]
195
-
196
-
197
- def first_option_postprocess(text: str, options: str) -> str:
198
- """Find first valid option for text."""
199
-
200
- patterns = [
201
- f"[Tt]he answer is [{options}]",
202
- f"[Tt]he correct answer\s?(?:option)?\s?is [{options}]", # noqa
203
- f"答案(?:选项)?是(.*?)[{options}]",
204
- f"答案(?:选项)?为(.*?)[{options}]",
205
- f"答案(?:选项)?选(.*?)[{options}]",
206
- f"选项[{options}]是?正确",
207
- f"选项[{options}]为?正确",
208
- f"固选(.*?)[{options}]",
209
- f"答案应该是(.*?)[{options}]",
210
- f"(\s|^)[{options}][\s。,,\.$]", # noqa
211
- f"[{options}]",
212
- ]
213
-
214
- regexes = [re.compile(pattern) for pattern in patterns]
215
- for regex in regexes:
216
- match = regex.search(text)
217
- if match:
218
- outputs = match.group(0)
219
- for i in options:
220
- if i in outputs:
221
- return i
222
- return ""
223
-
224
-
225
- def first_capital_postprocess(text: str) -> str:
226
- for t in text:
227
- if t.isupper():
228
- return t
229
- return ""
230
-
231
-
232
- def general_postprocess(text: str) -> str:
233
- # Cut off the first newline, period, or comma
234
- truncated_text = re.split(r"[\n.,]", text, 1)[0]
235
-
236
- # Remove punctuation
237
- no_punctuation = re.sub(r"[^\w\s]", "", truncated_text)
238
-
239
- # Remove article
240
- no_articles = re.sub(r"\b(a|an|the)\b", "", no_punctuation, flags=re.IGNORECASE)
241
-
242
- # Remove duplicated blank spaces
243
- cleaned_text = re.sub(r"\s+", " ", no_articles).strip()
244
-
245
- return cleaned_text
246
-
247
-
248
- def bbh_mcq_postprocess(text: str) -> str:
249
- ans = text
250
- ans_line = ans.split("answer is ")
251
- if len(ans_line) != 1:
252
- ans = ans_line[-1].strip()
253
- match = re.search(r"\(([A-Z])\)*", ans)
254
- if match:
255
- return f"({match.group(1)})"
256
- match = re.search(r"([A-Z])", ans)
257
- if match:
258
- return f"({match.group(1)})"
259
- return f"({ans})"
260
-
261
-
262
- def bbh_freeform_postprocess(text: str) -> str:
263
- ans = text
264
- ans_line = ans.split("answer is ")
265
- if len(ans_line) != 1:
266
- ans = ans_line[-1].strip()
267
- ans = ans.split("\n")[0]
268
- if ans.endswith("."):
269
- ans = ans[:-1]
270
- return ans
271
-
272
-
273
- icl_prompts = {
274
- "temporal_sequences": """Task description: Answer questions about which times certain events could have occurred.
275
-
276
- Q: Today, Emily went to the museum. Between what times could they have gone?
277
- We know that:
278
- Emily woke up at 1pm.
279
- Elizabeth saw Emily reading at the library from 2pm to 4pm.
280
- Jessica saw Emily watching a movie at the theater from 4pm to 5pm.
281
- Leslie saw Emily waiting at the airport from 5pm to 6pm.
282
- William saw Emily buying clothes at the mall from 6pm to 7pm.
283
- The museum was closed after 7pm.
284
- Between what times could Emily have gone to the museum?
285
- Options:
286
- (A) 1pm to 2pm
287
- (B) 6pm to 7pm
288
- (C) 5pm to 6pm
289
- (D) 2pm to 4pm
290
- A: Let's think step by step.
291
- Wake-up time: 1pm.
292
- 1pm-2pm: free.
293
- 2pm-4pm: reading at the library.
294
- 4pm-5pm: watching a movie at the theater.
295
- 5pm-6pm: waiting at the airport.
296
- 6pm-7pm: buying clothes at the mall.
297
- The museum closure time: 7pm.
298
- The only time when Emily could have gone to the museum was 1pm to 2pm. So the answer is (A).
299
-
300
- Q: Today, Elizabeth went to the amusement park. Between what times could they have gone?
301
- We know that:
302
- Elizabeth woke up at 7am.
303
- David saw Elizabeth fixing their computer at the electronic store from 1pm to 2pm.
304
- Sarah saw Elizabeth playing tennis at the tennis court from 2pm to 3pm.
305
- Susan saw Elizabeth walking towards the Statue of Liberty from 3pm to 6pm.
306
- Andrew saw Elizabeth taking photos near the Eiffel Tower from 6pm to 9pm.
307
- Emily saw Elizabeth getting a coffee at the cafe from 9pm to 10pm.
308
- The amusement park was closed after 10pm.
309
- Between what times could Elizabeth have gone to the amusement park?
310
- Options:
311
- (A) 7am to 1pm
312
- (B) 9pm to 10pm
313
- (C) 1pm to 2pm
314
- (D) 3pm to 6pm
315
- A: Let's think step by step.
316
- Wake-up time: 7am.
317
- 7am-1pm: free.
318
- 1pm-2pm: fixing their computer at the electronic store.
319
- 2pm-3pm: playing tennis at the tennis court.
320
- 3pm-6pm: walking towards the Statue of Liberty.
321
- 6pm-9pm: taking photos near the Eiffel Tower.
322
- 9pm-10pm: getting a coffee at the cafe.
323
- The amusement park closure time: 10pm.
324
- The only time when Elizabeth could have gone to the amusement park was 7am to 1pm. So the answer is (A).
325
-
326
- Q: Today, Tiffany went to the beach. Between what times could they have gone?
327
- We know that:
328
- Tiffany woke up at 5am.
329
- Betty saw Tiffany getting a coffee at the cafe from 5am to 6am.
330
- Jessica saw Tiffany working at the office from 6am to 9am.
331
- John saw Tiffany stretching at a yoga studio from 9am to 12pm.
332
- Sean saw Tiffany sitting on a rooftop from 12pm to 2pm.
333
- Sarah saw Tiffany playing tennis at the tennis court from 2pm to 3pm.
334
- The beach was closed after 4pm.
335
- Between what times could Tiffany have gone to the beach?
336
- Options:
337
- (A) 9am to 12pm
338
- (B) 12pm to 2pm
339
- (C) 5am to 6am
340
- (D) 3pm to 4pm
341
- A: Let's think step by step.
342
- Wake-up time: 5am.
343
- 5am-6am: getting a coffee at the cafe.
344
- 6am-9am: working at the office.
345
- 9am-12pm: stretching at a yoga studio.
346
- 12pm-2pm: sitting on a rooftop.
347
- 2pm-3pm: playing tennis at the tennis court.
348
- 3pm-4pm: free.
349
- The beach closure time: 4pm.
350
- The only time when Tiffany could have gone to the beach was 3pm to 4pm. So the answer is (D).""",
351
- "disambiguation_qa": """Clarify the meaning of sentences with ambiguous pronouns.
352
-
353
- Q: In the following sentences, explain the antecedent of the pronoun (which thing the pronoun refers to), or state that it is ambiguous.
354
- Sentence: The chief told the counselor that they took the day off.
355
- Options:
356
- (A) The chief took the day off
357
- (B) The counselor took the day off
358
- (C) Ambiguous
359
- A: Let's think step by step.
360
- Here we need to determine who the pronoun "they" might be referring to. There are two possible referents for "they", namely the chief and the counselor. The verb "told" might be able to help us determine which one is more likely (if either). Let X be the chief and Y the counselor. The sentence is then of the form "X told Y that (X or Y) did something."
361
- Let's consider Y first: "X told Y that Y did something." This case does not make much sense, as Y would already have the information that Y did something, because it is information about themself.
362
- Now, consider X: "X told Y that X did something." This makes sense, because X would be sharing some information about themself that Y might not have known before.
363
- Because in this context, X is the chief and Y is the counselor, the answer should be the chief. So the answer is (A).
364
-
365
- Q: In the following sentences, explain the antecedent of the pronoun (which thing the pronoun refers to), or state that it is ambiguous.
366
- Sentence: The manager sent a message to the secretary, but he didn't reply yet.
367
- Options:
368
- (A) The secretary didn't reply yet
369
- (B) The manager didn't reply yet
370
- (C) Ambiguous
371
- A: Let's think step by step.
372
- Here we need to determine who the pronoun "he" might be referring to. There are two possible referents for "he", namely the manager and the secretary. The verbs "sent" and "reply" might be able to help us determine which one is more likely (if either). Let X be the manager and Y the secretary. The sentence is then of the form "X sent a message to Y, but (X or Y) didn't reply yet."
373
- Let's consider Y first: "X sent a message to Y, but Y didn't reply yet." This case makes sense, because of the implicit causality of the sentence. Y was the receiver of the message, but Y didn't get back to X yet.
374
- Now, consider X: "X sent a message to Y, but X didn't reply yet." This case doesn't make sense, because X was the initial sender of the message, so it is now Y's turn to write back to X.
375
- Because in this context, X is the manager and Y is the secretary, the answer should be the secretary. So the answer is (A).
376
-
377
- Q: In the following sentences, explain the antecedent of the pronoun (which thing the pronoun refers to), or state that it is ambiguous.
378
- Sentence: Bailey will plan to meet the director at his office
379
- Options:
380
- (A) It will be Bailey's office
381
- (B) It will be the director's office
382
- (C) Ambiguous
383
- A: Let's think step by step.
384
- Here we need to determine who the pronoun "his" might be referring to. There are two possible referents for "his", namely Bailey's and the director's. The verb phrase "plan to meet" might be able to help us determine which one is more likely (if either). Let X be Bailey and Y the director. The sentence is then of the form "X will plan to meet Y at (X or Y)'s office."
385
- Let's consider Y first: "X will plan to meet Y at Y's office." This case makes sense, because X might want to meet up with Y at Y's office.
386
- Now, consider X: "X will plan to meet Y at X's office." This case also makes sense, because X might want to meet up with Y at X's own office.
387
- Because both X and Y are possible at the same time, we conclude that the antecedent of the pronoun is ambiguous. So the answer is (C).""",
388
- "date_understanding": """Infer the date from context.
389
-
390
- Q: Today is Christmas Eve of 1937. What is the date 10 days ago in MM/DD/YYYY?
391
- Options:
392
- (A) 12/14/2026
393
- (B) 12/14/1950
394
- (C) 12/14/2007
395
- (D) 12/14/1937
396
- (E) 07/14/1938
397
- (F) 12/14/1988
398
- A: Let's think step by step.
399
- If today is Christmas Eve of 1937, then today's date is December 24, 1937. 10 days before today is December 14, 1937, that is 12/14/1937. So the answer is (D).
400
-
401
- Q: Tomorrow is 11/12/2019. What is the date one year ago from today in MM/DD/YYYY?
402
- Options:
403
- (A) 09/04/2018
404
- (B) 11/11/2018
405
- (C) 08/25/2018
406
- (D) 11/02/2018
407
- (E) 11/04/2018
408
- A: Let's think step by step.
409
- If tomorrow is 11/12/2019, then today is 11/11/2019. The date one year ago from today is 11/11/2018. So the answer is (B).
410
-
411
- Q: Jane and John married on Jan 2, 1958. It is their 5-year anniversary today. What is the date tomorrow in MM/DD/YYYY?
412
- Options:
413
- (A) 01/11/1961
414
- (B) 01/03/1963
415
- (C) 01/18/1961
416
- (D) 10/14/1960
417
- (E) 01/03/1982
418
- (F) 12/03/1960
419
- A: Let's think step by step.
420
- If Jane and John married on Jan 2, 1958, then and if it is their 5-year anniversary today, then today's date is Jan 2, 1963. The date tomorrow is Jan 3, 1963, that is 01/03/1963. So the answer is (B).""",
421
- "tracking_shuffled_objects_three_objects": """A task requiring determining the final positions of a set of objects given their initial positions and a description of a sequence of swaps.
422
-
423
- Q: Alice, Bob, and Claire are playing a game. At the start of the game, they are each holding a ball: Alice has a yellow ball, Bob has a blue ball, and Claire has a pink ball.
424
- As the game progresses, pairs of players trade balls. First, Claire and Alice swap balls. Then, Alice and Bob swap balls. Finally, Claire and Bob swap balls. At the end of the game, Bob has the
425
- Options:
426
- (A) yellow ball
427
- (B) blue ball
428
- (C) pink ball
429
- A: Let's think step by step.
430
- (0) At the start: Alice: yellow, Bob: blue, Claire: pink.
431
- (1) Claire and Alice swap balls: Alice: pink, Bob: blue, Claire: yellow.
432
- (2) Alice and Bob swap balls: Alice: blue, Bob: pink, Claire: yellow.
433
- (3) Claire and Bob swap balls: Alice: blue, Bob: yellow, Claire: pink.
434
- At the end of the game, Bob has the yellow ball. So the answer is (A).
435
-
436
- Q: Alice, Bob, and Claire are playing a game. At the start of the game, they are each holding a ball: Alice has a white ball, Bob has a purple ball, and Claire has a pink ball.
437
- As the game progresses, pairs of players trade balls. First, Bob and Alice swap balls. Then, Bob and Claire swap balls. Finally, Bob and Alice swap balls. At the end of the game, Alice has the
438
- Options:
439
- (A) white ball
440
- (B) purple ball
441
- (C) pink ball
442
- A: Let's think step by step.
443
- (0) At the start: Alice: white, Bob: purple, Claire: pink.
444
- (1) Bob and Alice swap balls: Alice: purple, Bob: white, Claire: pink.
445
- (2) Bob and Claire swap balls: Alice: purple, Bob: pink, Claire: white.
446
- (3) Bob and Alice swap balls: Alice: pink, Bob: purple, Claire: white.
447
- At the end of the game, Alice has the pink ball. So the answer is (C).
448
-
449
- Q: Alice, Bob, and Claire are dancers at a square dance. At the start of a song, they each have a partner: Alice is dancing with Lola, Bob is dancing with Rodrigo, and Claire is dancing with Patrick.
450
- Throughout the song, the dancers often trade partners. First, Alice and Bob switch partners. Then, Claire and Bob switch partners. Finally, Bob and Alice switch partners. At the end of the dance, Alice is dancing with
451
- Options:
452
- (A) Lola
453
- (B) Rodrigo
454
- (C) Patrick
455
- A: Let's think step by step.
456
- (0) At the start: Alice: Lola, Bob: Rodrigo, Claire: Patrick.
457
- (1) Alice and Bob switch partners: Alice: Rodrigo, Bob: Lola, Claire: Patrick.
458
- (2) Claire and Bob switch partners: Alice: Rodrigo, Bob: Patrick, Claire: Lola.
459
- (3) Bob and Alice switch partners: Alice: Patrick, Bob: Rodrigo, Claire: Lola.
460
- At the end of the dance, Alice is dancing with Patrick. So the answer is (C).""",
461
- "penguins_in_a_table": """Answer questions about a table of penguins and their attributes.
462
-
463
- Q: Here is a table where the first line is a header and each subsequent line is a penguin: name, age, height (cm), weight (kg) Louis, 7, 50, 11 Bernard, 5, 80, 13 Vincent, 9, 60, 11 Gwen, 8, 70, 15 For example: the age of Louis is 7, the weight of Gwen is 15 kg, the height of Bernard is 80 cm. We now add a penguin to the table:
464
- James, 12, 90, 12
465
- How many penguins are less than 8 years old?
466
- Options:
467
- (A) 1
468
- (B) 2
469
- (C) 3
470
- (D) 4
471
- (E) 5
472
- A: Let's think step by step.
473
- This question focuses on age. We know the following: Louis is 7 years old, Bernard is 5 years old, Vincent is 9 years old, and Gwen is 8 years old.
474
- Now, we add James to this table: James is 12 years old.
475
- The penguins that are less than 8 years old are Louis and Bernard.
476
- There are 2 penguins less than 8 years old. So the answer is (B).
477
-
478
- Q: Here is a table where the first line is a header and each subsequent line is a penguin: name, age, height (cm), weight (kg) Louis, 7, 50, 11 Bernard, 5, 80, 13 Vincent, 9, 60, 11 Gwen, 8, 70, 15 For example: the age of Louis is 7, the weight of Gwen is 15 kg, the height of Bernard is 80 cm. Which is the youngest penguin?
479
- Options:
480
- (A) Louis
481
- (B) Bernard
482
- (C) Vincent
483
- (D) Gwen
484
- (E) James
485
- A: Let's think step by step.
486
- This question focuses on age. We know the following: Louis is 7 years old, Bernard is 5 years old, Vincent is 9 years old, and Gwen is 8 years old.
487
- According to the table, Bernard (5) is the youngest amongst them.
488
- The youngest penguin is Bernard. So the answer is (B).
489
-
490
- Q: Here is a table where the first line is a header and each subsequent line is a penguin: name, age, height (cm), weight (kg) Louis, 7, 50, 11 Bernard, 5, 80, 13 Vincent, 9, 60, 11 Gwen, 8, 70, 15 For example: the age of Louis is 7, the weight of Gwen is 15 kg, the height of Bernard is 80 cm. What is the name of the second penguin sorted by alphabetic order?
491
- Options:
492
- (A) Louis
493
- (B) Bernard
494
- (C) Vincent
495
- (D) Gwen
496
- (E) James
497
- A: Let's think step by step.
498
- This question focuses on the name. We know the following: The names of the penguin in the table are Louis, Bernard, Vincent, and Gwen.
499
- When we sort their names alphabetically, we get Bernard, Gwen, Louis, Vincent.
500
- The name of the second penguin sorted by alphabetical order is Gwen.
501
- The name of the second penguin sorted by alphabetic order is Gwen. So the answer is (D).""",
502
- "geometric_shapes": """Name geometric shapes from their SVG paths.
503
-
504
- Q: This SVG path element <path d="M 31.00,73.00 L 32.00,59.00 L 44.00,50.00 L 49.00,41.00 L 64.00,37.00 L 71.00,55.00 L 64.00,76.00 L 52.00,61.00 L 31.00,73.00"/> draws a
505
- Options:
506
- (A) circle
507
- (B) heptagon
508
- (C) hexagon
509
- (D) kite
510
- (E) line
511
- (F) octagon
512
- (G) pentagon
513
- (H) rectangle
514
- (I) sector
515
- (J) triangle
516
- A: Let's think step by step.
517
- This SVG path element contains "M" and "L" commands. M takes two parameters (x,y) and moves the current point to the coordinates (x,y). L takes two parameters (x,y) and draws a line from the previous coordinate to the new coordinate (x,y).
518
- This path can be decomposed into 9 separate commands.
519
- (1) M 31.00,73.00: Move the current point to 31.00,73.00.
520
- (2) L 32.00,59.00: Create a line from 31.00,73.00 to 32.00,59.00.
521
- (3) L 44.00,50.00: Create a line from 32.00,59.00 to 44.00,50.00.
522
- (4) L 49.00,41.00: Create a line from 44.00,50.00 to 49.00,41.00.
523
- (5) L 64.00,37.00: Create a line from 49.00,41.00 to 64.00,37.00.
524
- (6) L 71.00,55.00: Create a line from 64.00,37.00 to 71.00,55.00.
525
- (7) L 64.00,76.00: Create a line from 71.00,55.00 to 64.00,76.00.
526
- (8) L 52.00,61.00: Create a line from 64.00,76.00 to 52.00,61.00.
527
- (9) L 31.00,73.00: Create a line from 52.00,61.00 to 31.00,73.00.
528
- This SVG path starts at point 31.00,73.00, creates eight consecutive and touching lines, and then returns back its starting point, thereby creating an eight-sided shape. It does not have any curves or arches. "octagon" is the only eight-sided object on the list. So the answer is (F).
529
-
530
- Q: This SVG path element <path d="M 14.19,26.04 L 51.43,39.21 L 58.44,36.69 L 56.63,30.17 L 48.53,26.66 L 14.19,26.04"/> draws a
531
- Options:
532
- (A) circle
533
- (B) heptagon
534
- (C) hexagon
535
- (D) kite
536
- (E) line
537
- (F) octagon
538
- (G) pentagon
539
- (H) rectangle
540
- (I) sector
541
- (J) triangle
542
- A: Let's think step by step.
543
- This SVG path element contains "M" and "L" commands. M takes two parameters (x,y) and moves the current point to the coordinates (x,y). L takes two parameters (x,y) and draws a line from the previous coordinate to the new coordinate (x,y).
544
- This path can be decomposed into 6 separate commands.
545
- (1) M 14.19,26.04: Move the current point to 14.19,26.04.
546
- (2) L 51.43,39.21: Create a line from 14.19,26.04 to 51.43,39.21.
547
- (3) L 58.44,36.69: Create a line from 51.43,39.21 to 58.44,36.69.
548
- (4) L 56.63,30.17: Create a line from 58.44,36.69 to 56.63,30.17.
549
- (5) L 48.53,26.66: Create a line from 56.63,30.17 to 48.53,26.66.
550
- (6) L 14.19,26.04: Create a line from 48.53,26.66 to 14.19,26.04.
551
- This SVG path starts at point 14.19,26.04, creates five consecutive and touching lines, and then returns back its starting point, thereby creating a five-sided shape. It does not have any curves or arches. "pentagon" is the only five-sided polygon on the list. So the answer is (G).
552
-
553
- Q: This SVG path element <path d="M 41.00,43.00 L 37.00,34.00 L 41.00,33.00 L 45.00,34.00 L 41.00,43.00"/> draws a
554
- Options:
555
- (A) circle
556
- (B) heptagon
557
- (C) hexagon
558
- (D) kite
559
- (E) line
560
- (F) octagon
561
- (G) pentagon
562
- (H) rectangle
563
- (I) sector
564
- (J) triangle
565
- A: Let's think step by step.
566
- This SVG path element contains "M" and "L" commands. M takes two parameters (x,y) and moves the current point to the coordinates (x,y). L takes two parameters (x,y) and draws a line from the previous coordinate to the new coordinate (x,y).
567
- This path can be decomposed into 5 separate commands.
568
- (1) M 41.00,43.00: Move the current point to 41.00,43.00.
569
- (2) L 37.00,34.00: Create a line from 41.00,43.00 to 37.00,34.00.
570
- (3) L 41.00,33.00: Create a line from 37.00,34.00 to 41.00,33.00.
571
- (4) L 45.00,34.00: Create a line from 41.00,33.00 to 45.00,34.00.
572
- (5) L 41.00,43.00: Create a line from 45.00,34.00 to 41.00,43.00.
573
- This SVG path starts at point 41.00,43.00, creates four consecutive and touching lines, and then returns back its starting point, thereby creating a four-sided shape. "kite" and "rectangle" are the only two four-sided polygons on the list. So, we need to determine which one is the correct answer.
574
- A kite has two pairs of equal-length adjacent sides, whereas a rectangle has two pairs of equal-length alternate (opposite) sides. Now, let's check whether the two adjacent sides of this shape are equal.
575
- Length of side A: |A| = sqrt((41.00-37.00)^2 + (43.00-34.00)^2) = sqrt((4)^2 + (9)^2) = sqrt(16 + 81) = sqrt(97).
576
- Length of side B: |B| = sqrt((37.00-41.00)^2 + (34.00-33.00)^2)) = sqrt((4)^2 + (1)^2) = sqrt(16 + 1) = sqrt(17).
577
- Length of side C: |C| = sqrt((41.00-45.00)^2 + (33.00-34.00)^2)) = sqrt((-4)^2 + (-1)^2) = sqrt(16 + 1) = sqrt(17).
578
- Length of side D: |D| = sqrt((45.00-41.00)^2 + (34.00-43.00)^2)) = sqrt((4)^2 + (-9)^2) = sqrt(16 + 81) = sqrt(97).
579
- Note that |A| = |D| and |B| = |C|. Furthermore, A and D are adjacent and B and C are adjacent. Thus, this polygon has two pairs of equal-length adjacent sides and is "kite". So the answer is (D).""",
580
- "snarks": """Determine which of two sentences is sarcastic.
581
-
582
- According to Cambridge University Dictionary, sarcasm is "the use of remarks that clearly mean the opposite of what they say, made in order to hurt someone's feelings or to criticize something in a humorous way." Sarcastic sentences often contain satirical or ironic utterances, hyperboles, ambivalent or witty remarks.
583
-
584
- Q: Which statement is sarcastic?
585
- Options:
586
- (A) Yes, because having interests and actively researching them is a huge waste
587
- (B) Yes, because having interests and actively researching them is a huge deal
588
- A: Let's think step by step.
589
- If we look at (A), it says that having interests and actively researching them is a huge waste, implying that it is a useless effort. However, we know that having interests and actively researching them is typically not a waste but rather is beneficial to the individual. The presence of such a juxtaposition in (A) suggests that it contains a taste of irony and sarcasm.
590
- If we look at (B), it says that having interests and actively researching them is a huge deal, implying that it is an important and consequential effort. This is arguably a neutral and correct statement.
591
- Above the above, the sarcastic option is (A). So the answer is (A).
592
-
593
- Q: Which statement is sarcastic?
594
- Options:
595
- (A) No one is going to disagree with you on this. Avoiding ad hominem attacks really help your case
596
- (B) No one is going to disagree with you on this. Ad hominem attacks really help your case
597
- A: Let's think step by step.
598
- If we look at (A), it says that avoiding ad hominem attacks really help your case, implying that ad hominem attacks are adverse and injurious. Because ad hominem attacks are adressed at a person rather than an idea, it is indeed true that avoiding them is often useful and helpful; so, (A) is a neutral (valid and agreeable) statement.
599
- If we look at (B), it says that ad hominem attacks really help your case, implying that ad hominem attacks are a positive thing. However, we stated previously that ad hominem attacks are often not useful or constructive. The speaker in this sentence therefore seems to mean the opposite of what they are saying; so, there appears to have a taste of irony and sarcasm in (B).
600
- Above the above, the sarcastic option is (B). So the answer is (B).
601
-
602
- Q: Which statement is sarcastic?
603
- Options:
604
- (A) Consistency in the league's punishments? What do you think this is supposed to be, politics?
605
- (B) Consistency in the league's punishments? What do you think this is supposed to be, moral?
606
- A: Let's think step by step.
607
- If we look at (A), it likens the consistency in the league's punishments with that in politics. Because politics or political affairs are often not considered to be consistent or dependable, this sentence appears to be satirical.
608
- If we look at (B), it likens the consistency in the league's punishments with that in morality. Discussing the consistency of the league's punishments in the context of morality, ethics, or law makes sense and does not appear to make a satirical point about anything.
609
- Above the above, the sarcastic option is (A). So the answer is (A).""",
610
- "ruin_names": """Select the humorous edit that 'ruins' the input movie or musical artist name.
611
-
612
- Q: Which of the following is a humorous edit of this artist or movie name: 'whitesnake'?
613
- Options:
614
- (A) whitesnape
615
- (B) whitesnapke
616
- (C) whitesnuake
617
- (D) mwhitesnake
618
- A: Let's think step by step.
619
- The original name is "whitesnake". This is the name of an old English hard rock band. It is a compound word, formed by the words "white" and "snake".
620
- (A) "whitesnape": It is formed by the combination of "white" and "snake"; therefore, "snake" has been changed to "snape". Snape makes a reference to the fictional character Severus Snape in the Harry Potter series, so (A) is indeed a meaningful and funny edit.
621
- (B) "whitesnapke": It is formed by the combination of "white" and "snapke", but "snapke" is not an actual word; therefore, "whitesnapke" is not humorous.
622
- (C) "whitesnuake": It is formed by the combination of "white" and "snuake", but "snuake" is not an actual word; therefore, "whitesnuake" is not humorous.
623
- (D) "mwhitesnake": It is formed by the combination of "m", "white", and "snake", but the prefix "-m "seems arbitrary; therefore, "mwhitesnake" is not meaningful or humorous.
624
- Above the above, the only humorous edit is (A). So the answer is (A).
625
-
626
- Q: Which of the following is a humorous edit of this artist or movie name: 'one of our dinosaurs is missing'?
627
- Options:
628
- (A) ofne of our dinosaurs is missing
629
- (B) one af our dinosaurs is missing
630
- (C) one of our dinosaurs is pissing
631
- (D) one of our dinosaur is missing
632
- A: Let's think step by step.
633
- The original name is "one of our dinosaurs is missing". This is the name of an old British movie.
634
- (A) "ofne of our dinosaurs is missing": Here "one of" is changed to "ofne", but the word "ofne" is not an actual word.
635
- (B) "one af our dinosaurs is missing": Here the word "of" is changed to "af", but the word "af" is not an actual word.
636
- (C) "one of our dinosaurs is pissing": Here the word "missing" is changed to "pissing", and "one of our dinosaurs is pissing" is indeed a very whimsical and mischievous edit. This change truly ruins the original title of the movie.
637
- (D) "one of our dinosaur is missing": Here the word "dinosaurs" is changed to "dinosaur", but "dinosaur" is singular but should be plural in the title; this change therefore feels arbitrary and not humorous.
638
- Above the above, the only humorous edit is (C).
639
- Above the above, the only humorous edit is (C). So the answer is (C).
640
-
641
- Q: Which of the following is a humorous edit of this artist or movie name: 'counting crows'?
642
- Options:
643
- (A) countingy crows
644
- (B) counting cows
645
- (C) courting crows
646
- (D) coutnting crows
647
- A: Let's think step by step.
648
- The original name is "counting crows". This is the name of an American rock band. Historically, the band name comes from the British nursery rhyme "One for Sorrow", which is about counting of magpies.
649
- (A) "countingy crows": Here the word "counting" is changed to "countingy", but the word "countingy" is not an actual word.
650
- (B) "counting cows": Here the word "crows" is changed to "cows", and this is indeed a playful and meaningful edit that ruins the original name of the band.
651
- (C) "courting crows": Here the word "counting" is changed to "courting", and "courting" is an actual word; however, "courting crows" does not sound as humorous as "counting cows".
652
- (D) "coutnting crows": Here the word "counting" is changed to "coutnting", but the word "coutnting" is not an actual word.
653
- Above the above, the only humorous edit is (B). So the answer is (B).""",
654
- "tracking_shuffled_objects_seven_objects": """A task requiring determining the final positions of a set of objects given their initial positions and a description of a sequence of swaps.
655
-
656
- Q: Alice, Bob, and Claire are playing a game. At the start of the game, they are each holding a ball: Alice has a yellow ball, Bob has a blue ball, and Claire has a pink ball.
657
- As the game progresses, pairs of players trade balls. First, Claire and Alice swap balls. Then, Alice and Bob swap balls. Finally, Claire and Bob swap balls. At the end of the game, Bob has the
658
- Options:
659
- (A) yellow ball
660
- (B) blue ball
661
- (C) pink ball
662
- A: Let's think step by step.
663
- (0) At the start: Alice: yellow, Bob: blue, Claire: pink.
664
- (1) Claire and Alice swap balls: Alice: pink, Bob: blue, Claire: yellow.
665
- (2) Alice and Bob swap balls: Alice: blue, Bob: pink, Claire: yellow.
666
- (3) Claire and Bob swap balls: Alice: blue, Bob: yellow, Claire: pink.
667
- At the end of the game, Bob has the yellow ball. So the answer is (A).
668
-
669
- Q: Alice, Bob, and Claire are playing a game. At the start of the game, they are each holding a ball: Alice has a white ball, Bob has a purple ball, and Claire has a pink ball.
670
- As the game progresses, pairs of players trade balls. First, Bob and Alice swap balls. Then, Bob and Claire swap balls. Finally, Bob and Alice swap balls. At the end of the game, Alice has the
671
- Options:
672
- (A) white ball
673
- (B) purple ball
674
- (C) pink ball
675
- A: Let's think step by step.
676
- (0) At the start: Alice: white, Bob: purple, Claire: pink.
677
- (1) Bob and Alice swap balls: Alice: purple, Bob: white, Claire: pink.
678
- (2) Bob and Claire swap balls: Alice: purple, Bob: pink, Claire: white.
679
- (3) Bob and Alice swap balls: Alice: pink, Bob: purple, Claire: white.
680
- At the end of the game, Alice has the pink ball. So the answer is (C).
681
-
682
- Q: Alice, Bob, and Claire are dancers at a square dance. At the start of a song, they each have a partner: Alice is dancing with Lola, Bob is dancing with Rodrigo, and Claire is dancing with Patrick.
683
- Throughout the song, the dancers often trade partners. First, Alice and Bob switch partners. Then, Claire and Bob switch partners. Finally, Bob and Alice switch partners. At the end of the dance, Alice is dancing with
684
- Options:
685
- (A) Lola
686
- (B) Rodrigo
687
- (C) Patrick
688
- A: Let's think step by step.
689
- (0) At the start: Alice: Lola, Bob: Rodrigo, Claire: Patrick.
690
- (1) Alice and Bob switch partners: Alice: Rodrigo, Bob: Lola, Claire: Patrick.
691
- (2) Claire and Bob switch partners: Alice: Rodrigo, Bob: Patrick, Claire: Lola.
692
- (3) Bob and Alice switch partners: Alice: Patrick, Bob: Rodrigo, Claire: Lola.
693
- At the end of the dance, Alice is dancing with Patrick. So the answer is (C).""",
694
- "tracking_shuffled_objects_five_objects": """A task requiring determining the final positions of a set of objects given their initial positions and a description of a sequence of swaps.
695
-
696
- Q: Alice, Bob, and Claire are playing a game. At the start of the game, they are each holding a ball: Alice has a yellow ball, Bob has a blue ball, and Claire has a pink ball.
697
- As the game progresses, pairs of players trade balls. First, Claire and Alice swap balls. Then, Alice and Bob swap balls. Finally, Claire and Bob swap balls. At the end of the game, Bob has the
698
- Options:
699
- (A) yellow ball
700
- (B) blue ball
701
- (C) pink ball
702
- A: Let's think step by step.
703
- (0) At the start: Alice: yellow, Bob: blue, Claire: pink.
704
- (1) Claire and Alice swap balls: Alice: pink, Bob: blue, Claire: yellow.
705
- (2) Alice and Bob swap balls: Alice: blue, Bob: pink, Claire: yellow.
706
- (3) Claire and Bob swap balls: Alice: blue, Bob: yellow, Claire: pink.
707
- At the end of the game, Bob has the yellow ball. So the answer is (A).
708
-
709
- Q: Alice, Bob, and Claire are playing a game. At the start of the game, they are each holding a ball: Alice has a white ball, Bob has a purple ball, and Claire has a pink ball.
710
- As the game progresses, pairs of players trade balls. First, Bob and Alice swap balls. Then, Bob and Claire swap balls. Finally, Bob and Alice swap balls. At the end of the game, Alice has the
711
- Options:
712
- (A) white ball
713
- (B) purple ball
714
- (C) pink ball
715
- A: Let's think step by step.
716
- (0) At the start: Alice: white, Bob: purple, Claire: pink.
717
- (1) Bob and Alice swap balls: Alice: purple, Bob: white, Claire: pink.
718
- (2) Bob and Claire swap balls: Alice: purple, Bob: pink, Claire: white.
719
- (3) Bob and Alice swap balls: Alice: pink, Bob: purple, Claire: white.
720
- At the end of the game, Alice has the pink ball. So the answer is (C).
721
-
722
- Q: Alice, Bob, and Claire are dancers at a square dance. At the start of a song, they each have a partner: Alice is dancing with Lola, Bob is dancing with Rodrigo, and Claire is dancing with Patrick.
723
- Throughout the song, the dancers often trade partners. First, Alice and Bob switch partners. Then, Claire and Bob switch partners. Finally, Bob and Alice switch partners. At the end of the dance, Alice is dancing with
724
- Options:
725
- (A) Lola
726
- (B) Rodrigo
727
- (C) Patrick
728
- A: Let's think step by step.
729
- (0) At the start: Alice: Lola, Bob: Rodrigo, Claire: Patrick.
730
- (1) Alice and Bob switch partners: Alice: Rodrigo, Bob: Lola, Claire: Patrick.
731
- (2) Claire and Bob switch partners: Alice: Rodrigo, Bob: Patrick, Claire: Lola.
732
- (3) Bob and Alice switch partners: Alice: Patrick, Bob: Rodrigo, Claire: Lola.
733
- At the end of the dance, Alice is dancing with Patrick. So the answer is (C).""",
734
- "logical_deduction_three_objects": """A logical deduction task which requires deducing the order of a sequence of objects.
735
-
736
- Q: The following paragraphs each describe a set of three objects arranged in a fixed order. The statements are logically consistent within each paragraph. In a golf tournament, there were three golfers: Amy, Eli, and Eve. Eve finished above Amy. Eli finished below Amy.
737
- Options:
738
- (A) Amy finished last
739
- (B) Eli finished last
740
- (C) Eve finished last
741
- A: Let's think step by step.
742
- (1) Eve finished above Amy: "(above) ? Eve ? Amy ? (below)".
743
- (2) Eli finished below Amy: "(above) ? Amy ? Eli ? (below)".
744
- (3) Combining (1) and (2) we get the following ordering: "(above) Eve Amy Eli (below)".
745
- According to this ordering, the person who finished last (the one at the bottom of this list) is Eli.
746
- Eli finished last. So the answer is (B).
747
-
748
- Q: The following paragraphs each describe a set of three objects arranged in a fixed order. The statements are logically consistent within each paragraph. On a shelf, there are three books: a white book, a green book, and an orange book. The green book is to the right of the white book. The orange book is the rightmost.
749
- Options:
750
- (A) The white book is the leftmost
751
- (B) The green book is the leftmost
752
- (C) The orange book is the leftmost
753
- A: Let's think step by step.
754
- (1) The green book is to the right of the white book: "(left) ? white ? green ? (right)".
755
- (2) The orange book is the rightmost: "(left) ? white ? green orange (right)".
756
- (3) Combining (1) and (2) we get the following ordering: "(left) white green orange (right)".
757
- According to this ordering, the leftmost book is the white book.
758
- The white book is the leftmost. So the answer is (A).
759
-
760
- Q: The following paragraphs each describe a set of three objects arranged in a fixed order. The statements are logically consistent within each paragraph. On a shelf, there are three books: a red book, a gray book, and a white book. The white book is to the left of the gray book. The red book is the second from the left.
761
- Options:
762
- (A) The red book is the leftmost
763
- (B) The gray book is the leftmost
764
- (C) The white book is the leftmost
765
- A: Let's think step by step.
766
- (1) The white book is to the left of the gray book: "(left) ? white ? gray ? (right)".
767
- (2) The red book is the second from the left: "(left) ? white red gray ? (right)".
768
- (3) Combining (1) and (2) we get the following ordering: "(left) white red gray (right)".
769
- According to this ordering, the leftmost book is the white book.
770
- The white book is the leftmost. So the answer is (C).""",
771
- "hyperbaton": """Order adjectives correctly in English sentences.
772
-
773
- Q: Which sentence has the correct adjective order:
774
- Options:
775
- (A) rubber terrible ship
776
- (B) terrible rubber ship
777
- A: Let's think step by step.
778
- When there is more than one adjective before a noun, the adjectives need to respect the following order before a noun: "[1. opinion] [2. size] [3. age] [4. shape] [5. color] [6. origin] [7. material] [8. purpose] noun".
779
- Option (A): "rubber terrible ship". (1) rubber" falls into the material category. (2) "terrible" falls into the opinion category. Option (A) has the following adjective order: [7. material] [1. opinion] (or, in numeric terms, 7 1). Because 7 < 1 is not correct, (A) does not have the correct ordering.
780
- Option (B): "terrible rubber ship". Option (B) has the following adjective order: [1. opinion] [7. material] (or, in numeric terms, 1 7). Because 1 < 7 is correct, (B) has the correct ordering. So the answer is (B).
781
-
782
- Q: Which sentence has the correct adjective order:
783
- Options:
784
- (A) repulsive small Brazilian exercise ship
785
- (B) Brazilian repulsive exercise small ship
786
- A: Let's think step by step.
787
- When there is more than one adjective before a noun, the adjectives need to respect the following order before a noun: "[1. opinion] [2. size] [3. age] [4. shape] [5. color] [6. origin] [7. material] [8. purpose] noun".
788
- Option (A): "repulsive small Brazilian exercise ship". (1) "repulsive" falls into the opinion category. (2) "small" falls into the size category. (3) "Brazilian" falls into the origin category. (4) "exercise" falls into the purpose category. Option (A) has the following adjective order: [1. opinion] [2. size] [6. origin] [8. purpose] (or, in numeric terms, 1 2 6 8). Because 1 < 2 < 6 < 8 is correct, (A) has the correct ordering.
789
- Option (B): "Brazilian repulsive exercise small ship". Option (B) has the following adjective order: [6. origin] [1. opinion] [8. purpose] [2. size] (or, in numeric terms, 6 1 8 2). Because 6 < 1 < 8 < 2 is not correct, (B) does not have the correct ordering. So the answer is (A).
790
-
791
- Q: Which sentence has the correct adjective order:
792
- Options:
793
- (A) blue gold wonderful square shoe
794
- (B) wonderful square blue gold shoe
795
- A: Let's think step by step.
796
- When there is more than one adjective before a noun, the adjectives need to respect the following order before a noun: "[1. opinion] [2. size] [3. age] [4. shape] [5. color] [6. origin] [7. material] [8. purpose] noun".
797
- Option (A): "blue gold wonderful square shoe". (1) "blue" falls into the color category. (2) "gold" falls into the material category. (3) "wonderful" falls into the opinion category. (4) "square" falls into the shape category. The adjective order that Option (A) has is [5. color] [7. material] [1. opinion] [4. shape] (or, in numeric terms, 5 7 1 4). Because 5 < 7 < 1 < 4 is not correct, (A) does not have the correct ordering.
798
- Option (B): "wonderful square blue gold shoe". Option (B) has the following adjective order: [1. opinion] [4. shape] [5. color] [7. material] (or, in numeric terms, 1 4 5 7 ). Because 1 < 4 < 5 < 7 is correct, (B) has the correct ordering. So the answer is (B).""",
799
- "logical_deduction_five_objects": """A logical deduction task which requires deducing the order of a sequence of objects.
800
-
801
- Q: The following paragraphs each describe a set of three objects arranged in a fixed order. The statements are logically consistent within each paragraph. In a golf tournament, there were three golfers: Amy, Eli, and Eve. Eve finished above Amy. Eli finished below Amy.
802
- Options:
803
- (A) Amy finished last
804
- (B) Eli finished last
805
- (C) Eve finished last
806
- A: Let's think step by step.
807
- (1) Eve finished above Amy: "(above) ? Eve ? Amy ? (below)".
808
- (2) Eli finished below Amy: "(above) ? Amy ? Eli ? (below)".
809
- (3) Combining (1) and (2) we get the following ordering: "(above) Eve Amy Eli (below)".
810
- According to this ordering, the person who finished last (the one at the bottom of this list) is Eli.
811
- Eli finished last. So the answer is (B).
812
-
813
- Q: The following paragraphs each describe a set of three objects arranged in a fixed order. The statements are logically consistent within each paragraph. On a shelf, there are three books: a white book, a green book, and an orange book. The green book is to the right of the white book. The orange book is the rightmost.
814
- Options:
815
- (A) The white book is the leftmost
816
- (B) The green book is the leftmost
817
- (C) The orange book is the leftmost
818
- A: Let's think step by step.
819
- (1) The green book is to the right of the white book: "(left) ? white ? green ? (right)".
820
- (2) The orange book is the rightmost: "(left) ? white ? green orange (right)".
821
- (3) Combining (1) and (2) we get the following ordering: "(left) white green orange (right)".
822
- According to this ordering, the leftmost book is the white book.
823
- The white book is the leftmost. So the answer is (A).
824
-
825
- Q: The following paragraphs each describe a set of three objects arranged in a fixed order. The statements are logically consistent within each paragraph. On a shelf, there are three books: a red book, a gray book, and a white book. The white book is to the left of the gray book. The red book is the second from the left.
826
- Options:
827
- (A) The red book is the leftmost
828
- (B) The gray book is the leftmost
829
- (C) The white book is the leftmost
830
- A: Let's think step by step.
831
- (1) The white book is to the left of the gray book: "(left) ? white ? gray ? (right)".
832
- (2) The red book is the second from the left: "(left) ? white red gray ? (right)".
833
- (3) Combining (1) and (2) we get the following ordering: "(left) white red gray (right)".
834
- According to this ordering, the leftmost book is the white book.
835
- The white book is the leftmost. So the answer is (C).""",
836
- "logical_deduction_seven_objects": """A logical deduction task which requires deducing the order of a sequence of objects.
837
-
838
- Q: The following paragraphs each describe a set of three objects arranged in a fixed order. The statements are logically consistent within each paragraph. In a golf tournament, there were three golfers: Amy, Eli, and Eve. Eve finished above Amy. Eli finished below Amy.
839
- Options:
840
- (A) Amy finished last
841
- (B) Eli finished last
842
- (C) Eve finished last
843
- A: Let's think step by step.
844
- (1) Eve finished above Amy: "(above) ? Eve ? Amy ? (below)".
845
- (2) Eli finished below Amy: "(above) ? Amy ? Eli ? (below)".
846
- (3) Combining (1) and (2) we get the following ordering: "(above) Eve Amy Eli (below)".
847
- According to this ordering, the person who finished last (the one at the bottom of this list) is Eli.
848
- Eli finished last. So the answer is (B).
849
-
850
- Q: The following paragraphs each describe a set of three objects arranged in a fixed order. The statements are logically consistent within each paragraph. On a shelf, there are three books: a white book, a green book, and an orange book. The green book is to the right of the white book. The orange book is the rightmost.
851
- Options:
852
- (A) The white book is the leftmost
853
- (B) The green book is the leftmost
854
- (C) The orange book is the leftmost
855
- A: Let's think step by step.
856
- (1) The green book is to the right of the white book: "(left) ? white ? green ? (right)".
857
- (2) The orange book is the rightmost: "(left) ? white ? green orange (right)".
858
- (3) Combining (1) and (2) we get the following ordering: "(left) white green orange (right)".
859
- According to this ordering, the leftmost book is the white book.
860
- The white book is the leftmost. So the answer is (A).
861
-
862
- Q: The following paragraphs each describe a set of three objects arranged in a fixed order. The statements are logically consistent within each paragraph. On a shelf, there are three books: a red book, a gray book, and a white book. The white book is to the left of the gray book. The red book is the second from the left.
863
- Options:
864
- (A) The red book is the leftmost
865
- (B) The gray book is the leftmost
866
- (C) The white book is the leftmost
867
- A: Let's think step by step.
868
- (1) The white book is to the left of the gray book: "(left) ? white ? gray ? (right)".
869
- (2) The red book is the second from the left: "(left) ? white red gray ? (right)".
870
- (3) Combining (1) and (2) we get the following ordering: "(left) white red gray (right)".
871
- According to this ordering, the leftmost book is the white book.
872
- The white book is the leftmost. So the answer is (C).""",
873
- "movie_recommendation": """Recommend movies similar to the given list of movies.
874
-
875
- Q: Find a movie similar to Star Wars Episode IV - A New Hope, Indiana Jones and the Last Crusade, Star Wars Episode V - The Empire Strikes Back, The Big Lebowski:
876
- Options:
877
- (A) Tetsuo
878
- (B) the Ironman
879
- (C) The Princess Bride
880
- (D) The Barkley Marathons The Race That Eats Its Young
881
- (E) Bug
882
- A: Let's think step by step.
883
- - Star Wars Episode IV - A New Hope (action, adventure, fantasy; 1977)
884
- - Indiana Jones and the Last Crusade (action, adventure; 1989)
885
- - Star Wars Episode V - The Empire Strikes Back (action, adventure, fantasy; 1980)
886
- - The Big Lebowski (action, drama, comedy; 1998)
887
- These are all famous classic American movies produced before 2000. Amongst all the options, the only movie similar to these ones seems to be The Princess Bride (1987). So the answer is (C).
888
-
889
- Q: Find a movie similar to Twister, The Silence of the Lambs, Independence Day, Braveheart:
890
- Options:
891
- (A) They Shoot Horses
892
- (B) Don't They
893
- (C) Forrest Gump
894
- (D) The Salton Sea
895
- (E) Extreme Days
896
- A: Let's think step by step.
897
- - Twister (action, adventure, thriller; 1996)
898
- - The Silence of the Lambs (crime, drama, thriller; 1991)
899
- - Independence Day (action, science-fiction, drama; 1996)
900
- - Braveheart (biography, drama, epic; 1995)
901
- These are all famous Hollywood movies produced around the 1990s. Amongst all the options, the only movie similar to these ones seems to be Forrest Gump (comedy, drama, romance; 1994). So the answer is (C).
902
-
903
- Q: Find a movie similar to Minority Report, Total Recall, Inside Out, Forrest Gump:
904
- Options:
905
- (A) Phenomena
906
- (B) Lilting
907
- (C) Catwoman
908
- (D) Edge of Tomorrow
909
- A: Let's think step by step.
910
- - Minority Report (action, crime, mystery; 2002)
911
- - Total Recall (action, adventure, science-fiction; 2012)
912
- - Inside Out (animation, family, comedy; 2015)
913
- - Forrest Gump (comedy, drama, romance; 1994)
914
- These are all famous movies produced in the past few decades.Amongst all the options, the only movie similar to these ones seems to be Edge of Tomorrow (action, adventure, crime, mystery; 2014), as it is also a science-fiction movie and features Tom Cruise. So the answer is (D).""",
915
- "salient_translation_error_detection": """Detect the type of error in an English translation of a German source sentence.
916
-
917
- Q: The following translations from German to English contain a particular error. That error will be one of the following types: Named Entities: An entity (names, places, locations, etc.) is changed to a different entity. Numerical Values: Numerical values (ordinals or cardinals), dates, and/or units are changed. Modifiers or Adjectives: The modifiers and adjectives pertaining to a noun are changed. Negation or Antonyms: Introduce or remove a negation or change comparatives to their antonyms. Facts: Trivial factual errors not pertaining to the above classes are introduced in the translations. Dropped Content: A significant clause in the translation is removed. Please identify that error. Source: In der Liste der Baudenkmale in Lenzen (Elbe) sind alle Baudenkmale der brandenburgischen Stadt Lenzen (Elbe) und ihrer Ortsteile aufgelistet.
918
- Translation: In the list of architectural monuments in Lenzen all architectural monuments of the Brandenburg city of Lenzen and its districts are listed.
919
- The translation contains an error pertaining to
920
- Options:
921
- (A) Modifiers or Adjectives
922
- (B) Numerical Values
923
- (C) Negation or Antonyms
924
- (D) Named Entities
925
- (E) Dropped Content
926
- (F) Facts
927
- A: Let's think step by step.
928
- We solve this question by first translating the source sentence to English and then by comparing our translation with the provided translation. According to Google Translate, the correct translation of the source sentence from German to English is "The list of monuments in Lenzen (Elbe) includes all the monuments in the Brandenburg town of Lenzen (Elbe) and its districts." On the other hand, the provided translation is "In the list of architectural monuments in Lenzen all architectural monuments of the Brandenburg city of Lenzen and its districts are listed." Note that Lenzen (Elbe) is changed to Lenzen in the original translation; so, there is a named entity error. Because an entity in the original source sentence is changed to a different entity in the translation, the translation contains an error pertaining to Named Entities. So the answer is (D).
929
-
930
- Q: The following translations from German to English contain a particular error. That error will be one of the following types: Named Entities: An entity (names, places, locations, etc.) is changed to a different entity. Numerical Values: Numerical values (ordinals or cardinals), dates, and/or units are changed. Modifiers or Adjectives: The modifiers and adjectives pertaining to a noun are changed. Negation or Antonyms: Introduce or remove a negation or change comparatives to their antonyms. Facts: Trivial factual errors not pertaining to the above classes are introduced in the translations. Dropped Content: A significant clause in the translation is removed. Please identify that error. Source: Auf dieser Seite sind die Baudenkmäler der oberbayerischen Großen Kreisstadt Landsberg am Lech zusammengestellt.
931
- Translation: On this page are compiled the architectural monuments of the town of Landsberg am Lech.
932
- The translation contains an error pertaining to
933
- Options:
934
- (A) Modifiers or Adjectives
935
- (B) Numerical Values
936
- (C) Negation or Antonyms
937
- (D) Named Entities
938
- (E) Dropped Content
939
- (F) Facts
940
- A: Let's think step by step.
941
- We solve this question by first translating the source sentence to English and then by comparing our translation with the provided translation. According to Google Translate, the correct translation of the source sentence from German to English is "The monuments of the Upper Bavarian district town of Landsberg am Lech are compiled on this page." On the other hand, the provided translation is "On this page are compiled the architectural monuments of the town of Landsberg am Lech." Note that an important detail about the location of Landsberg am Lech is omitted in the original translation: The translation should have said "Upper Bavarian district town of Landsberg am Lech". Because a significant clause in the translation was removed, the translation contains an error pertaining to Dropped Content. So the answer is (E).
942
-
943
- Q: The following translations from German to English contain a particular error. That error will be one of the following types: Named Entities: An entity (names, places, locations, etc.) is changed to a different entity. Numerical Values: Numerical values (ordinals or cardinals), dates, and/or units are changed. Modifiers or Adjectives: The modifiers and adjectives pertaining to a noun are changed. Negation or Antonyms: Introduce or remove a negation or change comparatives to their antonyms. Facts: Trivial factual errors not pertaining to the above classes are introduced in the translations. Dropped Content: A significant clause in the translation is removed. Please identify that error. Source: Łeba ist eine Kleinstadt und ein Badeort im Powiat Lęborski der polnischen Woiwodschaft Pommern.
944
- Translation: Eba is not a small town and seaside resort in the Powiat Léborski county of the Pomeranian Voivodeship of Poland.
945
- The translation contains an error pertaining to
946
- Options:
947
- (A) Modifiers or Adjectives
948
- (B) Numerical Values
949
- (C) Negation or Antonyms
950
- (D) Named Entities
951
- (E) Dropped Content
952
- (F) Facts
953
- A: Let's think step by step.
954
- We solve this question by first translating the source sentence to English and then by comparing our translation with the provided translation. According to Google Translate, the correct translation of the source sentence from German to English is "Łeba is a small town and seaside resort in the Powiat Lęborski of the Polish Pomeranian Voivodeship." On the other hand, the provided translation is "Łeba is not a small town and seaside resort in the Powiat Léborski county of the Pomeranian Voivodeship of Poland." Note that the provided sentence says, "Łeba is not a small town ..." However, the translation should have been "Łeba is a small town ..." Because a negation is introduced at the beginning of the sentence and has fundamentally changed the meaning of the original source, the translation contains an error pertaining to Negation or Antonyms. So the answer is (C).""",
955
- "reasoning_about_colored_objects": """Answer extremely simple questions about the colors of objects on a surface.
956
-
957
- Q: On the nightstand, there is a red pencil, a purple mug, a burgundy keychain, a fuchsia teddy bear, a black plate, and a blue stress ball. What color is the stress ball?
958
- Options:
959
- (A) red
960
- (B) orange
961
- (C) yellow
962
- (D) green
963
- (E) blue
964
- (F) brown
965
- (G) magenta
966
- (H) fuchsia
967
- (I) mauve
968
- (J) teal
969
- (K) turquoise
970
- (L) burgundy
971
- (M) silver
972
- (N) gold
973
- (O) black
974
- (P) grey
975
- (Q) purple
976
- (R) pink
977
- A: Let's think step by step.
978
- According to this question, the color of the stress ball is blue. So the answer is (E).
979
-
980
- Q: On the table, you see a bunch of objects arranged in a row: a purple paperclip, a pink stress ball, a brown keychain, a green scrunchiephone charger, a mauve fidget spinner, and a burgundy pen. What is the color of the object directly to the right of the stress ball?
981
- Options:
982
- (A) red
983
- (B) orange
984
- (C) yellow
985
- (D) green
986
- (E) blue
987
- (F) brown
988
- (G) magenta
989
- (H) fuchsia
990
- (I) mauve
991
- (J) teal
992
- (K) turquoise
993
- (L) burgundy
994
- (M) silver
995
- (N) gold
996
- (O) black
997
- (P) grey
998
- (Q) purple
999
- (R) pink
1000
- A: Let's think step by step.
1001
- According to this question, the objects are arranged in a row, from left to right, as follows: (1) a purple paperclip, (2) a pink stress ball, (3) a brown keychain, (4) a green scrunchiephone charger, (5) a mauve fidget spinner, (6) a burgundy pen.
1002
- The stress ball is the second object on the list, namely (2). The object that is to the right of the stress ball corresponds to (3), which is a brown keychain.
1003
- The color of the keychain is brown. So the answer is (F).
1004
-
1005
- Q: On the nightstand, you see the following items arranged in a row: a teal plate, a burgundy keychain, a yellow scrunchiephone charger, an orange mug, a pink notebook, and a grey cup. How many non-orange items do you see to the left of the teal item?
1006
- Options:
1007
- (A) zero
1008
- (B) one
1009
- (C) two
1010
- (D) three
1011
- (E) four
1012
- (F) five
1013
- (G) six
1014
- A: Let's think step by step.
1015
- According to this question, the objects are arranged in a row, from left to right, as follows: (1) a teal plate, (2) a burgundy keychain, (3) a yellow scrunchiephone charger, (4) an orange mug, (5) a pink notebook, (6) a grey cup.
1016
- The teal plate is the first item, namely (1). There is no item to the left of the teal item.
1017
- The number of non-orange items to the left of the teal item is zero. So the answer is (A).""",
1018
- "multistep_arithmetic_two": """Solve multi-step arithmetic problems.
1019
-
1020
- Q: ((-5 + 9 * -4 - 0) * (4 + -7 + 0 * -5)) =
1021
- A: Let's think step by step.
1022
- Let’s recall that the order of operations in mathematics is as follows: (1) Parentheses, (2) exponents, (3) multiplication and division (from left to right), (4) addition and multiplication (from left to right). So, remember to always compute the expressions inside parentheses or brackets first.
1023
- This equation can be written as "A * B", where A = (-5 + 9 * -4 - 0) and B = (4 + -7 + 0 * -5).
1024
- Let's calculate A = (-5 + 9 * -4 - 0) = (-5 + (9 * -4) - 0) = (-5 + (-36) - 0) = (-5 + -36 - 0) = -5 - 36 = -41.
1025
- Let's calculate B = (4 + -7 + 0 * -5) = (4 + -7 + (0 * -5)) = (4 + -7 + 0) = (4 + -7) = (4 - 7) = -3.
1026
- Then, the final equation is A * B = -41 * -3 = (-61) * (-3) = 123. So the answer is 123.
1027
-
1028
- Q: ((-9 * 7 * 7 * -9) + (4 * -9 - 8 - -4)) =
1029
- A: Let's think step by step.
1030
- Let’s recall that the order of operations in mathematics is as follows: (1) Parentheses, (2) exponents, (3) multiplication and division (from left to right), (4) addition and multiplication (from left to right). So, remember to always compute the expressions inside parentheses or brackets first.
1031
- This equation can be written as "A + B", where A = (-9 * 7 * 7 * -9) and B = (4 * -9 - 8 - -4).
1032
- Let's calculate A = (-9 * 7 * 7 * -9) = ((-9 * 7) * (7 * -9)) = ((-63) * (-63)) = 3969.
1033
- Let's calculate B = (4 * -9 - 8 - (-4)) = ((4 * -9) - 8 - (-4)) = ((-36) - 8 - (-4)) = ((-36 - 8) - (-4)) = (-44 - (-4)) = -40.
1034
- Then, the final equation is A + B = 3969 + -40 = 3969 - 40 = 3929. So the answer is 3929.
1035
-
1036
- Q: ((-3 + 5 * 8 * -4) - (9 - 8 * -7 + -9)) =
1037
- A: Let's think step by step.
1038
- Let’s recall that the order of operations in mathematics is as follows: (1) Parentheses, (2) exponents, (3) multiplication and division (from left to right), (4) addition and multiplication (from left to right). So, remember to always compute the expressions inside parentheses or brackets first.
1039
- This equation can be written as "A - B", where A = (-3 + 5 * 8 * -4) and B = (9 - 8 * -7 + -9).
1040
- Let's calculate A = (-3 + 5 * 8 * -4) = (-3 + (5 * 8) * -4) = (-3 + (40) * -4) = (-3 + (40 * -4)) = (-3 + -160) = -163.
1041
- Let's calculate B = (9 - 8 * -7 + -9) = (9 - (8 * -7) + -9) = (9 - (-56) + -9) = ((9 - (-56)) + -9) = ((65) + -9)= (65 - 9) = 56.
1042
- Then, the final equation is A - B = -163 - 56 = -219. So the answer is -219.""",
1043
- "navigate": """Given a series of navigation instructions, determine whether one would end up back at the starting point.
1044
-
1045
- Q: If you follow these instructions, do you return to the starting point? Turn left. Turn around. Turn left. Take 7 steps. Take 2 steps. Take 4 steps. Take 8 steps.
1046
- Options:
1047
- - Yes
1048
- - No
1049
- A: Let's think step by step.
1050
- We start at the origin (0, 0), facing the positive y-axis.
1051
- (1) Turn left: (0, 0), facing the negative x-axis.
1052
- (2) Turn around: (0, 0), facing the positive x-axis.
1053
- (3) Turn left: (0, 0), facing the positive y-axis.
1054
- (4) Take 7 steps: (0, 7), facing the positive y-axis.
1055
- (5) Take 2 steps: (0, 9), facing the positive y-axis.
1056
- (6) Take 4 steps: (0, 13), facing the positive y-axis.
1057
- (7) Take 8 steps: (0, 21), facing the positive y-axis.
1058
- Since (0, 21) is not (0, 0), we are not where we started. So the answer is No.
1059
-
1060
- Q: If you follow these instructions, do you return to the starting point? Turn around. Take 1 step. Take 6 steps. Turn around. Take 6 steps. Take 9 steps. Take 1 step.
1061
- Options:
1062
- - Yes
1063
- - No
1064
- A: Let's think step by step.
1065
- We start at the origin (0, 0), facing the positive y-axis.
1066
- (1) Turn around: (0, 0), facing the negative y-axis.
1067
- (2) Take 1 step: (0, -1), facing the negative y-axis.
1068
- (3) Take 6 steps: (0, -7), facing the negative y-axis.
1069
- (4) Turn around: (0, -7), facing the positive y-axis.
1070
- (5) Take 6 steps: (0, -1), facing the positive y-axis.
1071
- (6) Take 9 steps: (0, 8), facing the positive y-axis.
1072
- (7) Take 1 step: (0, 9), facing the positive y-axis.
1073
- Since (0, 9) is not (0, 0), we are not where we started. So the answer is No.
1074
-
1075
- Q: If you follow these instructions, do you return to the starting point? Always face forward. Take 2 steps right. Take 9 steps left. Take 7 steps right.
1076
- Options:
1077
- - Yes
1078
- - No
1079
- A: Let's think step by step.
1080
- We start at the origin (0, 0), facing the positive y-axis.
1081
- (1) Always face forward: (0, 0), facing the positive y-axis.
1082
- (2) Take 2 steps right: (0, 2), facing the positive y-axis.
1083
- (3) Take 9 steps left: (0, -7), facing the positive y-axis.
1084
- (4) Take 7 steps right: (0, 7), facing the positive y-axis.
1085
- Since (0, 0) is (0, 0), we are indeed where we started. So the answer is Yes.""",
1086
- "dyck_languages": """Correctly close a Dyck-n word.
1087
-
1088
- Q: Complete the rest of the sequence, making sure that the parentheses are closed properly. Input: [ { [
1089
- A: Let's think step by step.
1090
- We should process each input one by one and keep track of the stack configuration.
1091
- 0: empty stack
1092
- 1: [ ; stack: [
1093
- 2: { ; stack: [ {
1094
- 3: [ ; stack: [ { [
1095
- Now, we have reached the end. The final stack is "[ { [".
1096
- We will need to pop out "[", "{", "[" one by one in that order.
1097
- So, we need "]", "}", "]". So the answer is ] } ].
1098
-
1099
- Q: Complete the rest of the sequence, making sure that the parentheses are closed properly. Input: < > ( ( [ [ ( { } ) [ < > ] ]
1100
- A: Let's think step by step.
1101
- We should process each input one by one and keep track of the stack configuration.
1102
- 0: empty stack
1103
- 1: < ; stack: <
1104
- 2: > ; stack: empty
1105
- 3: ( ; stack: (
1106
- 4: ( ; stack: ( (
1107
- 5: [ ; stack: ( ( [
1108
- 6: [ ; stack: ( ( [ [
1109
- 7: ( ; stack: ( ( [ [ (
1110
- 8: { ; stack: ( ( [ [ ( {
1111
- 9: } ; stack: ( ( [ [ (
1112
- 10: ) ; stack: ( ( [ [
1113
- 11: [ ; stack: ( ( [ [ [
1114
- 12: < ; stack: ( ( [ [ [ <
1115
- 13: > ; stack: ( ( [ [ [
1116
- 14: ] ; stack: ( ( [ [
1117
- 15: ] ; stack: ( ( [
1118
- Now, we have reached the end. The final stack is "( ( [".
1119
- We will need to pop out "[", "(", "(" one by one in that order.
1120
- So, we need "]", ")", ")". So the answer is ] ) ).
1121
-
1122
- Q: Complete the rest of the sequence, making sure that the parentheses are closed properly. Input: < [ < [ { < [ ] < { } > > } ] > { { ( ) } { < [ < > ] > }
1123
- A: Let's think step by step.
1124
- We should process each input one by one and keep track of the stack configuration.
1125
- 0: empty stack
1126
- 1: < ; stack: <
1127
- 2: [ ; stack: < [
1128
- 3: < ; stack: < [ <
1129
- 4: [ ; stack: < [ < [
1130
- 5: { ; stack: < [ < [ {
1131
- 6: < ; stack: < [ < [ { <
1132
- 7: [ ; stack: < [ < [ { < [
1133
- 8: ] ; stack: < [ < [ { <
1134
- 9: < ; stack: < [ < [ { < <
1135
- 10: { ; stack: < [ < [ { < < {
1136
- 11: } ; stack: < [ < [ { < <
1137
- 12: > ; stack: < [ < [ { <
1138
- 13: > ; stack: < [ < [ {
1139
- 14: } ; stack: < [ < [
1140
- 15: ] ; stack: < [ <
1141
- 16: > ; stack: < [
1142
- 17: { ; stack: < [ {
1143
- 18: { ; stack: < [ { {
1144
- 19: ( ; stack: < [ { { (
1145
- 20: ) ; stack: < [ { {
1146
- 21: } ; stack: < [ {
1147
- 22: { ; stack: < [ { {
1148
- 23: < ; stack: < [ { { <
1149
- 24: [ ; stack: < [ { { < [
1150
- 25: < ; stack: < [ { { < [ <
1151
- 26: > ; stack: < [ { { < [
1152
- 27: ] ; stack: < [ { { <
1153
- 28: > ; stack: < [ { {
1154
- 29: } ; stack: < [ {
1155
- Now, we have reached the end. The final stack is "< [ {".
1156
- We will need to pop out "{", "[", "<" one by one in that order.
1157
- So, we need "}", "]", ">". So the answer is } ] >.""",
1158
- "word_sorting": """Sort a list of words.
1159
 
1160
- Q: Sort the following words alphabetically: List: oven costume counterpart
1161
- A: Let's think step by step.
1162
- The first letter: "oven": "o" (15). "costume": "c" (3). "counterpart": "c" (3). We now have: (3) ["costume" ? "counterpart"] < (15) "oven". Now let's sort this subpart ["costume" ? "counterpart"] by looking at their second letters.
1163
- The second letter: "costume": "o" (15). "counterpart": "o" (15). We now have: (15) ["costume" ? "counterpart"]. Now let's sort this subpart ["costume" ? "counterpart"] by looking at their third letters.
1164
- The third letter: "costume": "s" (19). "counterpart": "u" (21). We now have: (19) "costume" < (21) "counterpart". Hence, we have ["costume" < "counterpart"] < "oven". So the answer is costume counterpart oven.
1165
 
1166
- Q: Sort the following words alphabetically: List: hypochlorite ponderosa phone credulity
1167
- A: Let's think step by step.
1168
- The first letter: "hypochlorite": "h" (8). "ponderosa": "p" (16). "phone": "p" (16). "credulity": "c" (3). We now have: (3) "credulity" < (8) "hypochlorite" < (16) ["ponderosa" ? "phone"]. Now let's sort this subpart ["ponderosa" ? "phone"] by looking at their second letters.
1169
- The second letter: "ponderosa": "o" (15). "phone": "h" (8). We now have: (8) "phone" < (15) "ponderosa". Hence, we have "credulity" < "hypochlorite" < ["phone" <"ponderosa"]. So the answer is credulity hypochlorite phone ponderosa.
1170
 
1171
- Q: Sort the following words alphabetically: List: newt arson parthia seismography mugho aspect census
1172
- A: Let's think step by step.
1173
- The first letter: "newt": "n" (14). "arson": "a" (1). "parthia": "p" (16). "seismography": "s" (19). "mugho": "m" (13). "aspect": "a" (1). "census": "c" (3). We now have: (1) ["arson" ? "aspect"] < (3) "census" < (13) "mugho" < (14) "newt" < (16) "parthia" < (19) "seismography". Now let's sort this subpart ["arson" ? "aspect"] by looking at their second letters.
1174
- The second letter: "arson": "r" (18). "aspect": "s" (19). We now have: (18) "arson" < (19) "aspect". Hence, we have ["arson" < "aspect"] < "census" < "mugho" < "newt" < "parthia" < "seismography". So the answer is arson aspect census mugho newt parthia seismography.""",
1175
- "sports_understanding": """Determine whether an artificially constructed sentence relating to sports is plausible or not.
1176
 
1177
- Q: Is the following sentence plausible? "Bam Adebayo scored a reverse layup in the Western Conference Finals."
1178
- A: Let's think step by step. Bam Adebayo is an American basketball player. Scoring a reverse layup in the Western Conference Finals is part of the NBA Finals. So the answer is yes.
1179
 
1180
- Q: Is the following sentence plausible? "Santi Cazorla scored a touchdown."
1181
- A: Let's think step by step. Santi Cazorla is a soccer player. Touchdown is part of American football and rugby. So the answer is no.
 
1182
 
1183
- Q: Is the following sentence plausible? "DeMar DeRozan was called for the goal tend."
1184
- A: Let's think step by step. DeMar DeRozan is an American basketball player. Goal tending is part of basketball. So the answer is yes.""",
1185
- "boolean_expressions": """Evaluate the result of a random Boolean expression.
1186
 
1187
- Q: not ( ( not not True ) ) is
1188
- A: Let's think step by step.
1189
- Remember that (i) expressions inside brackets are always evaluated first and that (ii) the order of operations from highest priority to lowest priority is "not", "and", "or", respectively.
1190
- We first simplify this expression "Z" as follows: "Z = not ( ( not not True ) ) = not ( ( A ) )" where "A = not not True".
1191
- Let's evaluate A: A = not not True = not (not True) = not False = True.
1192
- Plugging in A, we get: Z = not ( ( A ) ) = not ( ( True ) ) = not True = False. So the answer is False.
1193
 
1194
- Q: True and False and not True and True is
1195
- A: Let's think step by step.
1196
- Remember that (i) expressions inside brackets are always evaluated first and that (ii) the order of operations from highest priority to lowest priority is "not", "and", "or", respectively.
1197
- We first simplify this expression "Z" as follows: "Z = True and False and not True and True = A and B" where "A = True and False" and "B = not True and True".
1198
- Let's evaluate A: A = True and False = False.
1199
- Let's evaluate B: B = not True and True = not (True and True) = not (True) = False.
1200
- Plugging in A and B, we get: Z = A and B = False and False = False. So the answer is False.
1201
 
1202
- Q: not not ( not ( False ) ) is
1203
- A: Let's think step by step.
1204
- Remember that (i) expressions inside brackets are always evaluated first and that (ii) the order of operations from highest priority to lowest priority is "not", "and", "or", respectively.
1205
- We first simplify this expression "Z" as follows: "Z = not not ( not ( False ) ) = not not ( A )" where "A = not ( False )".
1206
- Let's evaluate A: A = not ( False ) = not False = True.
1207
- Plugging in A, we get: Z = not not ( A ) = not not (True) = not not False = True. So the answer is True.""",
1208
- "object_counting": """Questions that involve enumerating objects and asking the model to count them.
1209
 
1210
- Q: I have a blackberry, a clarinet, a nectarine, a plum, a strawberry, a banana, a flute, an orange, and a violin. How many fruits do I have?
1211
- A: Let's think step by step.
1212
- We first identify the fruits on the list and include their quantity in parentheses:
1213
- - blackberry (1)
1214
- - nectarine (1)
1215
- - plum (1)
1216
- - strawberry (1)
1217
- - banana (1)
1218
- - orange (1)
1219
- Now, let's add the numbers in parentheses: 1 + 1 + 1 + 1 + 1 + 1 = 6. So the answer is 6.
1220
 
1221
- Q: I have an orange, a raspberry, two peaches, a blackberry, an apple, a grape, a nectarine, and three plums. How many fruits do I have?
1222
- A: Let's think step by step.
1223
- We first identify the fruits on the list and include their quantity in parentheses:
1224
- - orange (1)
1225
- - raspberry (1)
1226
- - peaches (2)
1227
- - blackberry (1)
1228
- - apple (1)
1229
- - grape (1)
1230
- - nectarine (1)
1231
- - plums (3)
1232
- Now, let's add the numbers in parentheses: 1 + 1 + 2 + 1 + 1 + 1 + 1 + 3 = 11. So the answer is 11.
1233
 
1234
- Q: I have a lettuce head, a head of broccoli, an onion, a stalk of celery, two carrots, a garlic, and a yam. How many vegetables do I have?
1235
- A: Let's think step by step.
1236
- We first identify the vegetables on the list and include their quantity in parentheses:
1237
- - lettuce (1)
1238
- - broccoli (1)
1239
- - onion (1)
1240
- - celery (1)
1241
- - carrots (2)
1242
- - garlic (1)
1243
- - yam (1)
1244
- Now, let's add the numbers in parentheses: 1 + 1 + 1 + 1 + 2 + 1 + 1 = 8. So the answer is 8.""",
1245
- "formal_fallacies": """Distinguish deductively valid arguments from formal fallacies.
1246
 
1247
- Q: "It is not always easy to see who is related to whom -- and in which ways. The following argument pertains to this question: To begin with, Lesley is a close friend of Fernando. Moreover, being a close friend of Fernando or a schoolmate of Lowell is sufficient for being a great-grandfather of Leroy. It follows that Lesley is a great-grandfather of Leroy."
1248
- Is the argument, given the explicitly stated premises, deductively valid or invalid?
1249
- Options:
1250
- - valid
1251
- - invalid
1252
- A: Let's think step by step.
1253
- (1) Lesley is a close friend of Fernando: Lesley = friend(Fernando).
1254
- (2) Being a close friend of Fernando or a schoolmate of Lowell is sufficient for being a great-grandfather of Leroy: If X = friend(Fernando) OR SCHOOLMATE(Lowell), then X = great-grandfather(Leroy).
1255
- Hypothesis: Does it follow that Lesley is a great-grandfather of Leroy: Lesley = great-grandfather(Leroy)?
1256
- Let’s see whether the Hypothesis can be deduced from the arguments (1) and (2) by logical reasoning?
1257
- By (1), we have Lesley = friend(Fernando). By (2), we have if Lesley = friend(Fernando), then Lesley = great-grandfather(Leroy).
1258
- So, it is true that Lesley is a great-grandfather of Leroy. So the answer is valid.
1259
 
1260
- Q: "It is not always easy to see who is related to whom -- and in which ways. The following argument pertains to this question: Whoever is not a great-grandfather of Clyde is a stepbrother of Brian. Being an ancestor of Dana is sufficient for not being a great-grandfather of Clyde. We may conclude: Everyone who is an ancestor of Dana is a stepbrother of Brian, too."
1261
- Is the argument, given the explicitly stated premises, deductively valid or invalid?
1262
- Options:
1263
- - valid
1264
- - invalid
1265
- A: Let's think step by step.
1266
- (1) Whoever is not a great-grandfather of Clyde is a stepbrother of Brian: If X = NOT (great-grandfather(Clyde)), then X = stepbrother(Brian).
1267
- (2): Being an ancestor of Dana is sufficient for not being a great-grandfather of Clyde: If X = ancestor(Dana), X = NOT (great-grandfather(Clyde)).
1268
- Hypothesis: Does it follow that everyone who is an ancestor of Dana is a stepbrother of Brian, too: If X = ancestor(Dana), then X = stepbrother(Brian)?
1269
- Let’s see whether the Hypothesis can be deduced from the arguments (1) and (2) by logical reasoning?
1270
- By (2), we have if X = ancestor(Dana), X = NOT (great-grandfather(Clyde)).
1271
- Furthermore, by (1), we have if X = NOT (great-grandfather(Clyde)), then X = stepbrother(Brian).
1272
- By the transitive relation rule in first-order logic, we then have: if X = ancestor(Dana), then X = stepbrother(Brian).
1273
- So, it is true that everyone who is an ancestor of Dana is a stepbrother of Brian. So the answer is valid.
1274
 
1275
- Q: "It is not always easy to grasp who is consuming which products. The following argument pertains to this question: Every infrequent user of Paul Mitchell shampoo is either a rare consumer of Nioxin shampoo or a loyal buyer of Caress soap, or both. No regular consumer of Lush soap is a rare consumer of Nioxin shampoo and, in the same time, a loyal buyer of Caress soap. It follows that whoever is an infrequent user of Paul Mitchell shampoo is not a regular consumer of Lush soap."
1276
- Is the argument, given the explicitly stated premises, deductively valid or invalid?
1277
- Options:
1278
- - valid
1279
- - invalid
1280
- A: Let's think step by step.
1281
- (1) Every infrequent user of Paul Mitchell shampoo is either a rare consumer of Nioxin shampoo or a loyal buyer of Caress soap, or both: If X = infrequent-user(Paul Mitchell), then X = rare-consumer(Nioxin) OR X = loyal-buyer(Caress).
1282
- (2): No regular consumer of Lush soap is a rare consumer of Nioxin shampoo and a loyal buyer of Caress soap at the same time. If X = regular-consumer(Lush), then X = NOT (rare-consumer(Nioxin) AND loyal-buyer(Caress)).
1283
- Hypothesis: Does it follow that whoever is an infrequent user of Paul Mitchell shampoo is not a regular consumer of Lush soap: If X = infrequent-user(Paul Mitchell), then X = NOT (regular-consumer(Lush))?
1284
- Let’s see whether the Hypothesis can be deduced from the arguments (1) and (2) by logical reasoning?
1285
- By (1), we have if X = infrequent-user(Paul Mitchell), then X = rare-consumer(Nioxin) OR X = loyal-buyer(Caress). We need to consider both cases separately:
1286
- The case X = rare-consumer(Nioxin) does not appear in (2).
1287
- The case X = loyal-buyer(Caress) does not appear in (2), either.
1288
- So, from (1) and (2), we cannot necessarily deduce the Hypothesis. So the answer is invalid.""",
1289
- "causal_judgement": """Answer questions about causal attribution.
1290
 
1291
- Q: How would a typical person answer each of the following questions about causation?
1292
- Frank T., had an ongoing dispute with his neighbor over a stretch of land and one day decided to shoot his neighbor in the body. Frank T. had no experience with guns, his hand slipped on the barrel of the gun, and the shot went wild. Nonetheless, the bullet bounced off a large boulder several feet away and hit the neighbor's body, causing significant injury. Did Frank T. intentionally shoot his neighbor in the body?
1293
- Options:
1294
- - Yes
1295
- - No
1296
- A: Let's think step by step.
1297
- Here in this question, we are told that "Frank T. had no experience with guns, his hand slipped on the barrel of the gun, and the shot went wild." A typical person would assume that this passage suggests that Frank T. had no intention of shooting and injuring someone and that the bullet accidentally hit the neighbor's body; therefore, we conclude that Frank T. did not intentionally hit his neighbor. So the answer is No.
1298
 
1299
- Q: How would a typical person answer each of the following questions about causation?
1300
- Suzy and Billy are working on a project that is very important for our nation's security. The boss tells them both: "Be sure that you are here at exactly 9 am. It is absolutely essential that you arrive at that time." Both Billy and Suzy arrive at 9 am. As it happens, there was a motion detector installed in the room where they arrived. The motion detector was set up to be triggered if at least one person appeared in the room at the same time. So the motion detector went off. Did Billy cause the motion detector to go off?
1301
- Options:
1302
- - Yes
1303
- - No
1304
- A: Let's think step by step.
1305
- Here in this question, we are told that the boss ordered them both to arrive at the meeting room at the same time and that the motion detector was set up to be triggered if at least one person appeared in the room at the same time." A typical person would assume that the person probably meant to say the detector was set up to be triggered if "both persons" appeared in the room at the same time, not at least one person, since otherwise the phrase "at the same time" would not make much sense in that sentence. Because the motion detector went off, a typical person would therefore come to the conclusion that both Suzy and Billy triggered the motion detector to go off; hence, Billy did indeed cause the motion detector to go off. So the answer is Yes.
1306
 
1307
- Q: How would a typical person answer each of the following questions about causation?
1308
- George and his sister Lena reunite at their parents' house for Thanksgiving. Whereas George just got into medical school, Lena is unhappy in her marriage and recently lost her job. Over the course of the day, George and Lena get into a number of heated arguments. Later in the afternoon they play a game of darts. They split the first two games, and the third game is close until the end. Who will win comes down to George's last shot. If he hits a high point region, he wins; if he hits a low point region, Lena wins. George thinks of the difficult time Lena is having, and he really wants to let her win. He aims the dart at the low point region. He sets up his shot and the dart lands in the low point region. After his shot, Lena wins the game and is very happy. Did George hit the low point region intentionally?
1309
- Options:
1310
- - Yes
1311
- - No
1312
- A: Let's think step by step.
1313
- Here in this question, we are told that "He aims the dart at the low point region." A typical person might therefore think George did intentionally hit the low point region, because he wanted to lift up the spirit of his sister Lena. So the answer is Yes.""",
1314
- "web_of_lies": """Evaluate a random boolean function expressed as a word problem.
1315
 
1316
- Q: Question: Fidel tells the truth. Jerry says Fidel tells the truth. Vina says Jerry tells the truth. Millicent says Vina lies. Raymond says Millicent lies. Does Raymond tell the truth?
1317
- A: Let's think step by step.
1318
- (1) Fidel tells the truth. So, we know that Fidel tells the truth.
1319
- (2) Jerry says Fidel tells the truth. Since we know from (1) that Fidel tells the truth, if Jerry says that Fidel tells the truth, then Jerry tells the truth.
1320
- (3) Vina says Jerry tells the truth. Since we know from (2) that Jerry tells the truth, if Vina says Jerry tells the truth, then Vine tells the truth.
1321
- (4) Millicent says Vina lies. Since we know from (3) that Vina tells the truth, if Millicent says Vina lies, then Millicent lies.
1322
- (5) Raymond says Millicent lies. Since we know from (4) that Millicent lies, if Raymond says Millicent lies, then Raymond tells the truth.
1323
- Now, the question asks: Does Raymond tell the truth? We know from (5) that Raymond tells the truth. So the answer is Yes.
1324
 
1325
- Q: Question: Kristian lies. Millie says Kristian lies. Maybelle says Millie tells the truth. Fidel says Maybelle lies. Leda says Fidel lies. Does Leda tell the truth?
1326
- A: Let's think step by step.
1327
- (1) Kristian lies. So, we know that Kristian lies.
1328
- (2) Millie says Kristian lies. Since we know from (1) that Kristian lies, if Millie says Kristian lies, then Millie tells the truth.
1329
- (3) Maybelle says Millie tells the truth. Since we know from (2) that Millie tells the truth, if Maybelle says Millie tells the truth, then Maybelle tells the truth.
1330
- (4) Fidel says Maybelle lies. Since we know from (3) that Maybelle tells the truth, if Fidel says Maybelle lies, then Fidel lies.
1331
- (5) Leda says Fidel lies. Since we know from (4) that Fidel lies, if Leda says Fidel lies, then Leda tells the truth.
1332
- Now, the question asks: Does Leda tell the truth? We know from (5) that Leda tells the truth. So the answer is Yes.
1333
 
1334
- Q: Question: Kristian tells the truth. Michaela says Kristian lies. Raymond says Michaela tells the truth. Osvaldo says Raymond tells the truth. Jamey says Osvaldo tells the truth. Does Jamey tell the truth?
1335
- A: Let's think step by step.
1336
- (1) Kristian tells the truth. So, we know that Kristian tells the truth.
1337
- (2) Michaela says Kristian lies. Since we know from (1) that Kristian tells the truth, if Michaela says Kristian lies, then Michaela lies.
1338
- (3) Raymond says Michaela tells the truth. Since we know from (2) that Michaela lies, if Raymond says Michaela tells the truth, then Raymond lies.
1339
- (4) Osvaldo says Raymond tells the truth. Since we know from (3) that Raymond lies, if Osvaldo says Raymond tells the truth, then Osvaldo lies.
1340
- (5) Jamey says Osvaldo tells the truth. Since we know from (4) that Osvaldo lies, if Jamey says Osvaldo tells the truth, then Jamey lies.
1341
- Now, the question asks: Does Jamey tell the truth? We know from (5) that Jamey lies. So the answer is No.""",
1342
- }
1343
 
 
 
 
 
 
 
1344
 
1345
- def bbh_lib_prompt(category: str):
1346
- return icl_prompts[category]
 
 
 
 
 
 
1347
 
1348
 
1349
  if __name__ == "__main__":
 
2
  import re
3
  import numpy as np
4
  from typing import Any
 
 
5
 
6
  NUMERIC_IN_EN = r"(?:[\s=+-/<>($:\.\*\\])(?=\S)((?:0|(?:\d{1,3}(?:,\d{3})+(?=\D|$))|(?:\d+))(?:\.\d+)?%?)(?:(?![^\s=+-/>)$:\.\*\\])|(?=, ))"
7
  NUMERIC_IN_ZH = (
 
9
  )
10
 
11
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
12
  def extract_choice_zh(gen):
13
  # 答案是A | 选项是A | 应该选A选项
14
  res = re.search(
 
40
  def extract_choice(gen):
41
  # answer is A | choice is A | choose A
42
  res = re.search(
43
+ r"(?:(?:[Cc]hoose)|(?:(?:[Aa]nswer|[Cc]hoice)(?![^ABCD]{0,20}?(?:n't|not))[^ABCD]{0,10}?\b(?:|is|:|be))\b)[^ABCD]{0,20}?\b(A|B|C|D)\b",
44
  gen,
45
  )
46
 
47
  # A is correct | A is right
48
  if res is None:
49
  res = re.search(
50
+ r"\b(A|B|C|D)\b(?![^ABCD]{0,8}?(?:n't|not)[^ABCD]{0,5}?(?:correct|right))[^ABCD]{0,10}?\b(?:correct|right)\b",
51
  gen,
52
  )
53
 
54
  # straight answer: A
55
  if res is None:
56
+ res = re.search(r"^(A|B|C|D)(?:\.|,|:|$)", gen)
57
 
58
  # simply extract the first appearred letter
59
  if res is None:
60
+ res = re.search(r"(?<![a-zA-Z])(A|B|C|D)(?![a-zA-Z=])", gen)
61
 
62
  if res is None:
63
+ res = "A"
64
 
65
  if isinstance(res, str):
66
  return res
 
102
 
103
 
104
  def remove_boxed(s):
105
+ if "\\boxed " in s:
106
+ left = "\\boxed "
107
+ assert s[: len(left)] == left
108
+ return s[len(left) :]
 
 
 
109
 
110
+ left = "\\boxed{"
111
+
112
+ assert s[: len(left)] == left
113
+ assert s[-1] == "}"
114
+
115
+ return s[len(left) : -1]
116
 
117
 
118
  def last_boxed_only_string(string):
 
145
  return retval
146
 
147
 
148
+ def fix_sqrt(string):
149
+ if "\\sqrt" not in string:
150
+ return string
151
+ splits = string.split("\\sqrt")
152
+ new_string = splits[0]
153
+ for split in splits[1:]:
154
+ if split[0] != "{":
155
+ a = split[0]
156
+ new_substr = "\\sqrt{" + a + "}" + split[1:]
157
+ else:
158
+ new_substr = "\\sqrt" + split
159
+ new_string += new_substr
160
+ return new_string
161
+
162
+
163
+ def remove_right_units(string):
164
+ # "\\text{ " only ever occurs (at least in the val set) when describing units
165
+ if "\\text{ " in string:
166
+ splits = string.split("\\text{ ")
167
+ assert len(splits) == 2
168
+ return splits[0]
169
  else:
170
+ return string
171
+
172
+
173
+ def fix_fracs(string):
174
+ substrs = string.split("\\frac")
175
+ new_str = substrs[0]
176
+ if len(substrs) > 1:
177
+ substrs = substrs[1:]
178
+ for substr in substrs:
179
+ new_str += "\\frac"
180
+ if substr[0] == "{":
181
+ new_str += substr
182
+ else:
183
+ try:
184
+ assert len(substr) >= 2
185
+ except AssertionError:
186
+ return string
187
+ a = substr[0]
188
+ b = substr[1]
189
+ if b != "{":
190
+ if len(substr) > 2:
191
+ post_substr = substr[2:]
192
+ new_str += "{" + a + "}{" + b + "}" + post_substr
193
+ else:
194
+ new_str += "{" + a + "}{" + b + "}"
195
+ else:
196
+ if len(substr) > 2:
197
+ post_substr = substr[2:]
198
+ new_str += "{" + a + "}" + b + post_substr
199
+ else:
200
+ new_str += "{" + a + "}" + b
201
+ string = new_str
202
+ return string
203
+
204
+
205
+ def fix_a_slash_b(string):
206
+ if len(string.split("/")) != 2:
207
+ return string
208
+ a = string.split("/")[0]
209
+ b = string.split("/")[1]
210
+ try:
211
+ a = int(a)
212
+ b = int(b)
213
+ assert string == "{}/{}".format(a, b)
214
+ new_string = "\\frac{" + str(a) + "}{" + str(b) + "}"
215
+ return new_string
216
+ except Exception as e:
217
+ return string
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
218
 
 
 
 
 
 
219
 
220
+ def strip_string(string):
221
+ # linebreaks
222
+ string = string.replace("\n", "")
 
223
 
224
+ # remove inverse spaces
225
+ string = string.replace("\\!", "")
 
 
 
226
 
227
+ # replace \\ with \
228
+ string = string.replace("\\\\", "\\")
229
 
230
+ # replace tfrac and dfrac with frac
231
+ string = string.replace("tfrac", "frac")
232
+ string = string.replace("dfrac", "frac")
233
 
234
+ # remove \left and \right
235
+ string = string.replace("\\left", "")
236
+ string = string.replace("\\right", "")
237
 
238
+ # Remove circ (degrees)
239
+ string = string.replace("^{\\circ}", "")
240
+ string = string.replace("^\\circ", "")
 
 
 
241
 
242
+ # remove dollar signs
243
+ string = string.replace("\\$", "")
 
 
 
 
 
244
 
245
+ # remove units (on the right)
246
+ string = remove_right_units(string)
 
 
 
 
 
247
 
248
+ # remove percentage
249
+ string = string.replace("\\%", "")
250
+ string = string.replace("\%", "") # noqa: W605
 
 
 
 
 
 
 
251
 
252
+ # " 0." equivalent to " ." and "{0." equivalent to "{." Alternatively, add "0" if "." is the start of the string
253
+ string = string.replace(" .", " 0.")
254
+ string = string.replace("{.", "{0.")
255
+ # if empty, return empty string
256
+ if len(string) == 0:
257
+ return string
258
+ if string[0] == ".":
259
+ string = "0" + string
 
 
 
 
260
 
261
+ # to consider: get rid of e.g. "k = " or "q = " at beginning
262
+ if len(string.split("=")) == 2:
263
+ if len(string.split("=")[0]) <= 2:
264
+ string = string.split("=")[1]
 
 
 
 
 
 
 
 
265
 
266
+ # fix sqrt3 --> sqrt{3}
267
+ string = fix_sqrt(string)
 
 
 
 
 
 
 
 
 
 
268
 
269
+ # remove spaces
270
+ string = string.replace(" ", "")
 
 
 
 
 
 
 
 
 
 
 
 
271
 
272
+ # \frac1b or \frac12 --> \frac{1}{b} and \frac{1}{2}, etc. Even works with \frac1{72} (but not \frac{72}1). Also does a/b --> \\frac{a}{b}
273
+ string = fix_fracs(string)
 
 
 
 
 
 
 
 
 
 
 
 
 
274
 
275
+ # manually change 0.5 --> \frac{1}{2}
276
+ if string == "0.5":
277
+ string = "\\frac{1}{2}"
 
 
 
 
278
 
279
+ # NOTE: X/Y changed to \frac{X}{Y} in dataset, but in simple cases fix in case the model output is X/Y
280
+ # string = fix_a_slash_b(string)
 
 
 
 
 
281
 
282
+ return string
 
 
 
 
 
 
 
283
 
 
 
 
 
 
 
 
 
284
 
285
+ def get_answer(string):
286
+ try:
287
+ answer = remove_boxed(last_boxed_only_string(string))
288
+ # answer = strip_string(answer)
289
+ except Exception:
290
+ answer = string
291
+ return answer
 
292
 
 
 
 
 
 
 
 
 
 
293
 
294
+ def is_equiv(str1, str2, verbose=False):
295
+ if str1 is None and str2 is None:
296
+ print("WARNING: Both None")
297
+ return False
298
+ if str1 is None or str2 is None:
299
+ return False
300
 
301
+ try:
302
+ ss1 = strip_string(str1)
303
+ ss2 = strip_string(str2)
304
+ if verbose:
305
+ print(ss1, ss2)
306
+ return ss1 == ss2
307
+ except Exception:
308
+ return str1 == str2
309
 
310
 
311
  if __name__ == "__main__":