diff --git a/src/genbench/tasks/quantifier_understanding/__init__.py b/src/genbench/tasks/quantifier_understanding/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/src/genbench/tasks/quantifier_understanding/config.jsonnet b/src/genbench/tasks/quantifier_understanding/config.jsonnet new file mode 100644 index 0000000..72c8976 --- /dev/null +++ b/src/genbench/tasks/quantifier_understanding/config.jsonnet @@ -0,0 +1,50 @@ +{ + name: 'Quantifier Understanding', + description: 'The task evaluates generalization in the understanding of quantifiers. It aims to measure + how well can language models capture the semantics of logical quantifiers in language. + ', + keywords: [ + 'quantifiers', + 'LLM', + 'prompting', + 'semantics' + ], + + authors: [ + 'Leroy Wang', + 'Shane Steinert-Threlkeld' + ], + + data_source: { + type: 'manual', + test: 'https://raw.githubusercontent.com/lerow/genbench_cbt/quantifier_understanding/src/genbench/tasks/quantifier_understanding/test_data.jsonl', + }, + + has_validation_set: false, + has_train_set: false, + + task_type: 'free_form', + + evaluation_metrics: [ + { + hf_id: 'exact_match', + git_commit_sha: "758135da6a37ce962b7bc38c6dd5eab672d2b742", + best_score: 1.0, + } + ], + + preparation_strategies: { + // A recipe for preparing the model to perform the task by configuring its prompt. + // This recipe is suitable for generative LMs such as GPT-3, OPT, T5, etc. + // We provide a few options for configuring the prompt. But, the task creator can + // also provide a custom prompt preparation in the task's Python class. + prompt_based_testing: { + prompt_builder: { + instruction_zero_shot: '', // Left empty because the prompt is in the data + instruction_few_shot: '', // Left empty because the prompt is in the data + input_prefix: 'Q: ', + output_prefix: '\nA: ', + } + }, + }, +} diff --git a/src/genbench/tasks/quantifier_understanding/doc.md b/src/genbench/tasks/quantifier_understanding/doc.md new file mode 100644 index 0000000..f9c36dd --- /dev/null +++ b/src/genbench/tasks/quantifier_understanding/doc.md @@ -0,0 +1,24 @@ +# Quantifier Understanding + +The task evaluates generalization in the understanding of quantifiers. It aims to measure +how well can language models capture the semantics of logical quantifiers in natural language. It tests compositional and robustness generalisation. + + +## Examples + +Given a question about a quantifier, determine if the answer is true or false. + +``` +There are 10 tables. 7 of the tables are blue. 3 of the tables are red. Are less than half of the tables red? Answer with only one word, true or false. +``` + +## Data Source + +The test data is fully generated using rule-based methods. + +The data is hosted here [https://github.com/lerow/genbench_cbt/blob/quantifier_understanding/src/genbench/tasks/quantifier_understanding/test_data.jsonl]. + + +## GenBench eval card + +![GenBench Eval Card](eval_card.png) diff --git a/src/genbench/tasks/quantifier_understanding/eval_card.png b/src/genbench/tasks/quantifier_understanding/eval_card.png new file mode 100644 index 0000000..6d0adc2 Binary files /dev/null and b/src/genbench/tasks/quantifier_understanding/eval_card.png differ diff --git a/src/genbench/tasks/quantifier_understanding/task.py b/src/genbench/tasks/quantifier_understanding/task.py new file mode 100644 index 0000000..fd2d825 --- /dev/null +++ b/src/genbench/tasks/quantifier_understanding/task.py @@ -0,0 +1,43 @@ +import re +from typing import Any, Dict, List + +import datasets + +from genbench import Task +from genbench.utils.logging import get_logger + + +logger = get_logger(__name__) + + +class QuantifierUnderstandingTask(Task): + def parse_output(s: str) -> str: + # if true return 1 else return 0 + + s = s.strip().split() + + for token in s: + if len(token) < 7: + token = re.sub(r"[^a-zA-Z]", "", token).lower() + if token == "true": + return "true" + if token == "false": + return "false" + + return "false" + + def evaluate_predictions( + self, *, predictions: List[Dict[str, Any]] = None, gold: datasets.Dataset = None + ) -> float: + preds = [pred["target"] for pred in predictions] + gold_labels = [g["target"] for g in gold] + + count = 0 + total = len(preds) + + for n in range(total): + label = self.parse_output(preds[n]) + if label == gold_labels[n]: + count += 1 + + return count / total diff --git a/src/genbench/tasks/quantifier_understanding/test_data.jsonl b/src/genbench/tasks/quantifier_understanding/test_data.jsonl new file mode 100644 index 0000000..b6e961f --- /dev/null +++ b/src/genbench/tasks/quantifier_understanding/test_data.jsonl @@ -0,0 +1,100 @@ +{'input': 'There are 10 tables. 7 of the tables are blue. 3 of the tables are red. Are less than half of the tables red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 tables. 6 of the tables are blue. 4 of the tables are red. Are less than half of the tables red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 tables. 5 of the tables are blue. 5 of the tables are red. Are less than half of the tables red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 tables. 4 of the tables are blue. 6 of the tables are red. Are less than half of the tables red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 tables. 3 of the tables are blue. 7 of the tables are red. Are less than half of the tables red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 chairs. 7 of the chairs are blue. 3 of the chairs are red. Are less than half of the chairs red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 chairs. 6 of the chairs are blue. 4 of the chairs are red. Are less than half of the chairs red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 chairs. 5 of the chairs are blue. 5 of the chairs are red. Are less than half of the chairs red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 chairs. 4 of the chairs are blue. 6 of the chairs are red. Are less than half of the chairs red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 chairs. 3 of the chairs are blue. 7 of the chairs are red. Are less than half of the chairs red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 circles. 7 of the circles are blue. 3 of the circles are red. Are less than half of the circles red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 circles. 6 of the circles are blue. 4 of the circles are red. Are less than half of the circles red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 circles. 5 of the circles are blue. 5 of the circles are red. Are less than half of the circles red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 circles. 4 of the circles are blue. 6 of the circles are red. Are less than half of the circles red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 circles. 3 of the circles are blue. 7 of the circles are red. Are less than half of the circles red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 squares. 7 of the squares are blue. 3 of the squares are red. Are less than half of the squares red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 squares. 6 of the squares are blue. 4 of the squares are red. Are less than half of the squares red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 squares. 5 of the squares are blue. 5 of the squares are red. Are less than half of the squares red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 squares. 4 of the squares are blue. 6 of the squares are red. Are less than half of the squares red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 squares. 3 of the squares are blue. 7 of the squares are red. Are less than half of the squares red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 apples. 7 of the apples are blue. 3 of the apples are red. Are less than half of the apples red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 apples. 6 of the apples are blue. 4 of the apples are red. Are less than half of the apples red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 apples. 5 of the apples are blue. 5 of the apples are red. Are less than half of the apples red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 apples. 4 of the apples are blue. 6 of the apples are red. Are less than half of the apples red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 apples. 3 of the apples are blue. 7 of the apples are red. Are less than half of the apples red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 tables. 7 of the tables are blue. 3 of the tables are red. Are more than half of the tables red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 tables. 6 of the tables are blue. 4 of the tables are red. Are more than half of the tables red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 tables. 5 of the tables are blue. 5 of the tables are red. Are more than half of the tables red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 tables. 4 of the tables are blue. 6 of the tables are red. Are more than half of the tables red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 tables. 3 of the tables are blue. 7 of the tables are red. Are more than half of the tables red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 chairs. 7 of the chairs are blue. 3 of the chairs are red. Are more than half of the chairs red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 chairs. 6 of the chairs are blue. 4 of the chairs are red. Are more than half of the chairs red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 chairs. 5 of the chairs are blue. 5 of the chairs are red. Are more than half of the chairs red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 chairs. 4 of the chairs are blue. 6 of the chairs are red. Are more than half of the chairs red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 chairs. 3 of the chairs are blue. 7 of the chairs are red. Are more than half of the chairs red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 circles. 7 of the circles are blue. 3 of the circles are red. Are more than half of the circles red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 circles. 6 of the circles are blue. 4 of the circles are red. Are more than half of the circles red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 circles. 5 of the circles are blue. 5 of the circles are red. Are more than half of the circles red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 circles. 4 of the circles are blue. 6 of the circles are red. Are more than half of the circles red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 circles. 3 of the circles are blue. 7 of the circles are red. Are more than half of the circles red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 squares. 7 of the squares are blue. 3 of the squares are red. Are more than half of the squares red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 squares. 6 of the squares are blue. 4 of the squares are red. Are more than half of the squares red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 squares. 5 of the squares are blue. 5 of the squares are red. Are more than half of the squares red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 squares. 4 of the squares are blue. 6 of the squares are red. Are more than half of the squares red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 squares. 3 of the squares are blue. 7 of the squares are red. Are more than half of the squares red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 apples. 7 of the apples are blue. 3 of the apples are red. Are more than half of the apples red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 apples. 6 of the apples are blue. 4 of the apples are red. Are more than half of the apples red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 apples. 5 of the apples are blue. 5 of the apples are red. Are more than half of the apples red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 apples. 4 of the apples are blue. 6 of the apples are red. Are more than half of the apples red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 apples. 3 of the apples are blue. 7 of the apples are red. Are more than half of the apples red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 tables. 7 of the tables are blue. 3 of the tables are red. Are at least 4 of the tables red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 tables. 6 of the tables are blue. 4 of the tables are red. Are at least 4 of the tables red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 tables. 5 of the tables are blue. 5 of the tables are red. Are at least 4 of the tables red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 tables. 4 of the tables are blue. 6 of the tables are red. Are at least 4 of the tables red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 tables. 3 of the tables are blue. 7 of the tables are red. Are at least 4 of the tables red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 chairs. 7 of the chairs are blue. 3 of the chairs are red. Are at least 4 of the chairs red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 chairs. 6 of the chairs are blue. 4 of the chairs are red. Are at least 4 of the chairs red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 chairs. 5 of the chairs are blue. 5 of the chairs are red. Are at least 4 of the chairs red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 chairs. 4 of the chairs are blue. 6 of the chairs are red. Are at least 4 of the chairs red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 chairs. 3 of the chairs are blue. 7 of the chairs are red. Are at least 4 of the chairs red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 circles. 7 of the circles are blue. 3 of the circles are red. Are at least 4 of the circles red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 circles. 6 of the circles are blue. 4 of the circles are red. Are at least 4 of the circles red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 circles. 5 of the circles are blue. 5 of the circles are red. Are at least 4 of the circles red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 circles. 4 of the circles are blue. 6 of the circles are red. Are at least 4 of the circles red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 circles. 3 of the circles are blue. 7 of the circles are red. Are at least 4 of the circles red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 squares. 7 of the squares are blue. 3 of the squares are red. Are at least 4 of the squares red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 squares. 6 of the squares are blue. 4 of the squares are red. Are at least 4 of the squares red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 squares. 5 of the squares are blue. 5 of the squares are red. Are at least 4 of the squares red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 squares. 4 of the squares are blue. 6 of the squares are red. Are at least 4 of the squares red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 squares. 3 of the squares are blue. 7 of the squares are red. Are at least 4 of the squares red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 apples. 7 of the apples are blue. 3 of the apples are red. Are at least 4 of the apples red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 apples. 6 of the apples are blue. 4 of the apples are red. Are at least 4 of the apples red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 apples. 5 of the apples are blue. 5 of the apples are red. Are at least 4 of the apples red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 apples. 4 of the apples are blue. 6 of the apples are red. Are at least 4 of the apples red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 apples. 3 of the apples are blue. 7 of the apples are red. Are at least 4 of the apples red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 tables. 7 of the tables are blue. 3 of the tables are red. Are at most 4 of the tables red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 tables. 6 of the tables are blue. 4 of the tables are red. Are at most 4 of the tables red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 tables. 5 of the tables are blue. 5 of the tables are red. Are at most 4 of the tables red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 tables. 4 of the tables are blue. 6 of the tables are red. Are at most 4 of the tables red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 tables. 3 of the tables are blue. 7 of the tables are red. Are at most 4 of the tables red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 chairs. 7 of the chairs are blue. 3 of the chairs are red. Are at most 4 of the chairs red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 chairs. 6 of the chairs are blue. 4 of the chairs are red. Are at most 4 of the chairs red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 chairs. 5 of the chairs are blue. 5 of the chairs are red. Are at most 4 of the chairs red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 chairs. 4 of the chairs are blue. 6 of the chairs are red. Are at most 4 of the chairs red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 chairs. 3 of the chairs are blue. 7 of the chairs are red. Are at most 4 of the chairs red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 circles. 7 of the circles are blue. 3 of the circles are red. Are at most 4 of the circles red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 circles. 6 of the circles are blue. 4 of the circles are red. Are at most 4 of the circles red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 circles. 5 of the circles are blue. 5 of the circles are red. Are at most 4 of the circles red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 circles. 4 of the circles are blue. 6 of the circles are red. Are at most 4 of the circles red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 circles. 3 of the circles are blue. 7 of the circles are red. Are at most 4 of the circles red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 squares. 7 of the squares are blue. 3 of the squares are red. Are at most 4 of the squares red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 squares. 6 of the squares are blue. 4 of the squares are red. Are at most 4 of the squares red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 squares. 5 of the squares are blue. 5 of the squares are red. Are at most 4 of the squares red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 squares. 4 of the squares are blue. 6 of the squares are red. Are at most 4 of the squares red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 squares. 3 of the squares are blue. 7 of the squares are red. Are at most 4 of the squares red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 apples. 7 of the apples are blue. 3 of the apples are red. Are at most 4 of the apples red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 apples. 6 of the apples are blue. 4 of the apples are red. Are at most 4 of the apples red? Answer with only one word, true or false.', 'target': 'true'} +{'input': 'There are 10 apples. 5 of the apples are blue. 5 of the apples are red. Are at most 4 of the apples red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 apples. 4 of the apples are blue. 6 of the apples are red. Are at most 4 of the apples red? Answer with only one word, true or false.', 'target': 'false'} +{'input': 'There are 10 apples. 3 of the apples are blue. 7 of the apples are red. Are at most 4 of the apples red? Answer with only one word, true or false.', 'target': 'false'}