-
Notifications
You must be signed in to change notification settings - Fork 156
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of github.com:UKGovernmentBEIS/inspect_ai
- Loading branch information
Showing
22 changed files
with
606 additions
and
72 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
# CommonsenseQA: A Question Answering Challenge Targeting Commonsense Knowledge | ||
|
||
[CommonsenseQA](https://arxiv.org/pdf/1811.00937) is a dataset designed to evaluate commonsense reasoning capabilities in natural language processing models. It consists of 12,247 multiple-choice questions that require background knowledge and commonsense to answer correctly. The dataset was constructed using CONCEPTNET, a graph-based knowledge base, where crowd-workers authored questions with complex semantics to challenge existing AI models. | ||
|
||
## Execution | ||
Here is an example from the dataset: | ||
``` | ||
Question: Where can I stand on a river to see water falling without getting wet? | ||
Options: | ||
A) Waterfall | ||
B) Bridge | ||
C) Valley | ||
D) Stream | ||
E) Bottom | ||
``` | ||
The model is required to choose the correct answer from the given options. In this case, the correct answer is B) Bridge. | ||
|
||
## Evaluation | ||
The model is prompted with the question and 5 options as input and required to choose one option by generating the corresponding answer choice A, B, C, D or E. The prompt tempate is based on the multiple choice template in OpenAI's [simple evals](https://github.com/openai/simple-evals/blob/main/mmlu_eval.py). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
""" | ||
CommonsenseQA: A Question Answering Challenge Targeting Commonsense Knowledge | ||
Alon Talmor, Jonathan Herzig, Nicholas Lourie, Jonathan Berant | ||
https://arxiv.org/pdf/1811.00937v2 | ||
# eval w/ 500 randomly selected samples | ||
inspect eval commonsense_qa.py --limit 500 | ||
""" | ||
|
||
from inspect_ai import Task, task | ||
from inspect_ai.dataset import Sample | ||
from inspect_ai.dataset._sources.hf import hf_dataset | ||
from inspect_ai.model._generate_config import GenerateConfig | ||
from inspect_ai.scorer import choice | ||
from inspect_ai.solver import multiple_choice | ||
|
||
|
||
@task | ||
def commonsense_qa(): | ||
dataset = hf_dataset( | ||
path="tau/commonsense_qa", | ||
split="validation", | ||
sample_fields=record_to_sample, | ||
trust=True, | ||
shuffle=True, | ||
) | ||
|
||
return Task( | ||
dataset=dataset, | ||
plan=multiple_choice(), | ||
scorer=choice(), | ||
config=GenerateConfig(temperature=0), | ||
) | ||
|
||
|
||
def record_to_sample(record): | ||
return Sample( | ||
input=record["question"], | ||
choices=[ | ||
str(record["choices"]["text"][0]), | ||
str(record["choices"]["text"][1]), | ||
str(record["choices"]["text"][2]), | ||
str(record["choices"]["text"][3]), | ||
str(record["choices"]["text"][4]), | ||
], | ||
target=record["answerKey"], | ||
metadata={"question_concept": record["question_concept"]}, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,3 @@ | ||
TASK_FILE_ATTR = "__task_file__" | ||
TASK_RUN_DIR_ATTR = "__task_run_dir__" | ||
TASK_SRC_DIR_ATTR = "__task_src_dir__" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.