Unverified Commit e9b938f2 authored by Hailey Schoelkopf's avatar Hailey Schoelkopf Committed by GitHub
Browse files

Merge pull request #711 from baberabb/big-refactor-logiqav2

[Refactor] logiqav2
parents 321aef35 8591f089
group:
- multiple_choice
task: logiqa
dataset_path: EleutherAI/logiqa
dataset_name: logiqa
output_type: multiple_choice
training_split: train
validation_split: validation
test_split: test
doc_to_choice: "{{options}}"
doc_to_text: !function utils_logiqa.doc_to_text
doc_to_target: !function utils_logiqa.doc_to_target
doc_to_decontamination_query: "{{context}}"
should_decontaminate: true
metric_list:
- metric: acc
aggregation: mean
higher_is_better: true
- metric: acc_norm
aggregation: mean
higher_is_better: true
# Copied from Master
def doc_to_text(doc) -> str:
"""
Passage: <passage>
Question: <question>
Choices:
A. <choice1>
B. <choice2>
C. <choice3>
D. <choice4>
Answer:
"""
choices = ["a", "b", "c", "d"]
prompt = "Passage: " + doc["context"] + "\n"
prompt += "Question: " + doc["question"] + "\nChoices:\n"
for choice, option in zip(choices, doc["options"]):
prompt += f"{choice.upper()}. {option}\n"
prompt += "Answer:"
return prompt
def doc_to_target(doc) -> int:
choices = ["a", "b", "c", "d"]
return choices.index(doc["label"].strip())
# LogiQA 2.0
### Paper
LogiQA 2.0 — An Improved Dataset for Logical Reasoning in Natural Language Understanding https://ieeexplore.ieee.org/document/10174688
The dataset is an amendment and re-annotation of LogiQA in 2020, a large-scale logical reasoning reading comprehension dataset adapted from the Chinese Civil Service Examination. This new version has an increased data size, the texts are refined with manual translation by professionals, and improved by removing items with distinctive cultural features like Chinese idioms.
Furthermore, a two-way natural language inference (NLI) task is introduced, resulting in 35k premise-hypothesis pairs with gold labels, making it the first large-scale NLI dataset for complex logical reasoning
Homepage: https://github.com/csitfun/LogiQA2.0
### Citation
```bibtex
@ARTICLE{10174688,
author={Liu, Hanmeng and Liu, Jian and Cui, Leyang and Teng, Zhiyang and Duan, Nan and Zhou, Ming and Zhang, Yue},
journal={IEEE/ACM Transactions on Audio, Speech, and Language Processing},
title={LogiQA 2.0 — An Improved Dataset for Logical Reasoning in Natural Language Understanding},
year={2023},
volume={},
number={},
pages={1-16},
doi={10.1109/TASLP.2023.3293046}}
```
### Subtasks
`logiqa2_zh`: The original dataset in Chinese.
`logiqa2_NLI`: The NLI version of the dataset converted from the MRC version.
`logieval`: Prompt based; https://github.com/csitfun/LogiEval
The subtasks have not been verified yet.
### Checklist
* [x] Is the task an existing benchmark in the literature?
* [x] Have you referenced the original paper that introduced the task?
* [x] If yes, does the original paper provide a reference implementation?
* [x] The original paper does not. There is another implementation of this task, but it designed for instruction tuned models: https://github.com/csitfun/LogiEval
If other tasks on this dataset are already supported:
* [x] Is the "Main" variant of this task clearly denoted?
* [x] Have you provided a short sentence in a README on what each new variant adds / evaluates?
* [ ] Have you noted which, if any, published evaluation setups are matched by this variant?
group:
- greedy_until
task: logieval
dataset_path: baber/logiqa2
dataset_name: logieval
output_type: greedy_until
training_split: train
test_split: test
# Instructions + {content}
doc_to_text: "Instructions: You will be presented with a passage and a question about that passage. There are four options to be chosen from, you need to choose the only correct option to answer that question. If the first option is right, you generate the answer 'A', if the second option is right, you generate the answer 'B', if the third option is right, you generate the answer 'C', if the fourth option is right, you generate the answer 'D'. Read the question and options thoroughly and select the correct answer from the four answer labels. Read the passage thoroughly to ensure you know what the passage entails.\n{{content}}"
doc_to_target: "{{ideal}}"
metric_list:
- metric: exact_match
aggregation: mean
higher_is_better: true
generation_kwargs:
do_sample: false
num_fewshot: 1
filter_list:
- name: "get-answer"
filter:
- function: "regex"
# starts with A-D excluding leading spaces
# original implementation uses a.startswith(b)
# https://github.com/openai/evals/blob/305b237cdb3884c7ddb6a5d12cb184a83551fcba/evals/api.py#L84
regex_pattern: "^\\s*([A-D])"
- function: "take_first"
group:
- multiple_choice
task: logiqa2
dataset_path: baber/logiqa2
dataset_name: logiqa2
output_type: multiple_choice
training_split: train
validation_split: validation
test_split: test
doc_to_choice: "{{options}}"
doc_to_text: !function utils_logiqa2.doc_to_text
doc_to_target: "{{answer}}"
doc_to_decontamination_query: "{{context}}"
should_decontaminate: false
metric_list:
- metric: acc
aggregation: mean
higher_is_better: true
- metric: acc_norm
aggregation: mean
higher_is_better: true
# Copied from Master
def doc_to_text(doc) -> str:
"""
Passage: <passage>
Question: <question>
A. <choice1>
B. <choice2>
C. <choice3>
D. <choice4>
Answer:
"""
choices = ["a", "b", "c", "d"]
prompt = "Passage: " + doc["text"] + "\n"
prompt += "Question: " + doc["question"] + "\n"
for choice, option in zip(choices, doc["options"]):
prompt += f"{choice.upper()}. {option}\n"
prompt += "Answer:"
return prompt
# # https://github.com/csitfun/LogiQA2.0/blob/main/logiqa2nli/nli-prompt.py
# def doc_to_textNLI(doc):
# maj_premise = ' '.join(list(doc['major_premise']))
# min_premise = ' '.join(list(doc['minor_premise']))
# hypo = doc['conclusion']
# prompt_input = "Given the fact: " + maj_premise + ' ' + min_premise + " Does it follow that: " + hypo + " Yes or no?"
# return prompt_input
......@@ -92,7 +92,7 @@ class TestNewTasks:
if task.has_test_docs()
else list(islice(task.validation_docs(), limit))
)
if "multiple_choice" in task._config.group:
if "multiple_choice" in task._config.output_type:
_array = [task.doc_to_choice(doc) for doc in arr]
# assert all(len(x) == 4 for x in _array)
assert all(isinstance(x, list) for x in _array)
......@@ -106,8 +106,8 @@ class TestNewTasks:
else list(islice(task.validation_docs(), limit))
)
_array_target = [task.doc_to_target(doc) for doc in arr]
assert all(isinstance(label, int) for label in _array_target)
assert len(_array_target) == limit if limit else True
if task._config.output_type == "multiple_choice":
assert all(isinstance(label, int) for label in _array_target)
# _array_text = [task.doc_to_text(doc) for doc in arr]
# Not working
# assert all(tgt[0] == " " or txt[-1] == "\n" if len(txt) != 0 else True for txt, tgt in zip(_array_text, _array_target))
......@@ -116,6 +116,7 @@ class TestNewTasks:
task_class().build_all_requests(rank=1, limit=limit, world_size=1)
assert task_class.instances is not None
# ToDO: Add proper testing
def test_construct_requests(self, task_class, limit):
task = task_class()
arr = (
......@@ -124,5 +125,5 @@ class TestNewTasks:
else list(islice(task.validation_docs(), limit))
)
requests = [task.construct_requests(doc, task.doc_to_text(doc)) for doc in arr]
assert all(isinstance(doc, list) for doc in requests)
# assert all(isinstance(doc, list) for doc in requests)
assert len(requests) == limit if limit else True
......@@ -83,7 +83,7 @@ def test_create_choices(task_class, limit):
if task.has_test_docs()
else list(islice(task.validation_docs(), limit))
)
if "multiple_choice" in task._config.group:
if "multiple_choice" in task._config.output_type:
_array = [task.doc_to_choice(doc) for doc in arr]
# assert all(len(x) == 4 for x in _array)
assert all(isinstance(x, list) for x in _array)
......@@ -98,8 +98,8 @@ def test_doc_to_target(task_class, limit):
else list(islice(task.validation_docs(), limit))
)
_array_target = [task.doc_to_target(doc) for doc in arr]
assert all(isinstance(label, int) for label in _array_target)
assert len(_array_target) == limit if limit else True
if task._config.output_type == "multiple_choice":
assert all(isinstance(label, int) for label in _array_target)
# _array_text = [task.doc_to_text(doc) for doc in arr]
# Not working
# assert all(tgt[0] == " " or txt[-1] == "\n" if len(txt) != 0 else True for txt, tgt in zip(_array_text, _array_target))
......@@ -110,6 +110,7 @@ def test_build_all_requests(task_class, limit):
assert task_class.instances is not None
# ToDO: Add proper testing
def test_construct_requests(task_class, limit):
task = task_class()
arr = (
......@@ -118,7 +119,7 @@ def test_construct_requests(task_class, limit):
else list(islice(task.validation_docs(), limit))
)
requests = [task.construct_requests(doc, task.doc_to_text(doc)) for doc in arr]
assert all(isinstance(doc, list) for doc in requests)
# assert all(isinstance(doc, list) for doc in requests)
assert len(requests) == limit if limit else True
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment