|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
"""data loading scripts for the CREPE dataset""" |
|
|
|
|
|
import csv |
|
import json |
|
import pandas as pd |
|
import os |
|
|
|
import datasets |
|
|
|
|
|
|
|
_CITATION = """\ |
|
@inproceedings{ |
|
zhang-etal-2023-causal, |
|
title = "Causal Reasoning About Entities and Events in Procedural Texts", |
|
author = "Li Zhang and Hainiu Xu and Yue Yang and Shuyan Zhou and Weiqiu You and Manni Arora and Chris Callison-Burch" |
|
booktitle = "Findings of the Association for Computational Linguistics: EACL 2023", |
|
year = "2023", |
|
address = "Dubrovnik, Croatia", |
|
publisher = "Association for Computational Linguistics", |
|
url = "https://arxiv.org/pdf/2301.10896.pdf" |
|
abstract = "Entities and events have long been regarded as the crux of machine reasoning. Procedural texts have received increasing attention due to the dynamic nature of involved entities and events. Existing work has focused either on entity state tracking (e.g., the temperature of a pan) or on counterfactual event reasoning (e.g., how likely am I to burn myself by touching the pan), while these two tasks are tightly intertwined. In this work, we propose CREPE, the first benchmark on causal reasoning about event plausibility based on entity states. We experiment with strong large language models and show that most models, including GPT3, perform close to chance at .30 F1, lagging far behind the human performance of .87 F1. Inspired by the finding that structured representations such as programming languages benefit event reasoning as a prompt to code language models such as Codex, we creatively inject the causal relations between entities and events through intermediate variables and boost the performance to .67 to .72 F1. Our proposed event representation not only allows for knowledge injection but also marks the first successful attempt of chain-of-thought reasoning with code language models." |
|
} |
|
""" |
|
|
|
|
|
_DESCRIPTION = """\ |
|
The CREPE dataset is designed for causal reasoning on entities and events in procedural texts. |
|
CREPE is the first benchmark on causal reasoning about event plausibility based on entity states |
|
""" |
|
|
|
_HOMEPAGE = "https://huggingface.co/datasets/zharry29/CREPE" |
|
|
|
_LICENSE = "cc-by-4.0" |
|
|
|
|
|
|
|
_URLS = { |
|
"development": "https://huggingface.co/datasets/zharry29/CREPE/blob/main/crepe_train.json", |
|
"testing": "https://huggingface.co/datasets/zharry29/CREPE/blob/main/crepe_test.json", |
|
} |
|
|
|
|
|
class CREPE(datasets.GeneratorBasedBuilder): |
|
"""Dataset for causal reasoning about entities and events in procedural texts.""" |
|
|
|
VERSION = datasets.Version("1.1.0") |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BUILDER_CONFIGS = [ |
|
datasets.BuilderConfig(name="development", version=VERSION, description="This part of my dataset covers a first domain"), |
|
datasets.BuilderConfig(name="testing", version=VERSION, description="This part of my dataset covers a second domain"), |
|
] |
|
|
|
DEFAULT_CONFIG_NAME = "development" |
|
|
|
def _info(self): |
|
|
|
features = datasets.Features( |
|
{ |
|
"goal": datasets.Value("string"), |
|
"steps": datasets.Value("list"), |
|
"event": datasets.Value("string"), |
|
"event_answer": datasets.Value("list"), |
|
"entity": datasets.Value("string"), |
|
"entity_answer": datasets.Value("list") |
|
} |
|
) |
|
return datasets.DatasetInfo( |
|
|
|
description=_DESCRIPTION, |
|
|
|
features=features, |
|
|
|
|
|
|
|
|
|
homepage=_HOMEPAGE, |
|
|
|
license=_LICENSE, |
|
|
|
citation=_CITATION, |
|
) |
|
|
|
def _split_generators(self, dl_manager): |
|
|
|
|
|
|
|
|
|
|
|
urls = _URLS[self.config.name] |
|
data_dir = dl_manager.download_and_extract(urls) |
|
return [ |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TRAIN, |
|
|
|
gen_kwargs={ |
|
"filepath": os.path.join(data_dir, "crepe_train.json"), |
|
"split": "development", |
|
}, |
|
), |
|
datasets.SplitGenerator( |
|
name=datasets.Split.TEST, |
|
|
|
gen_kwargs={ |
|
"filepath": os.path.join(data_dir, "crepe_test.json"), |
|
"split": "test" |
|
}, |
|
), |
|
] |
|
|
|
|
|
def _generate_examples(self, filepath, split): |
|
|
|
with open(filepath, encoding="utf-8") as f: |
|
for key, row in enumerate(f): |
|
data = pd.read_csv(row) |
|
|
|
yield key, { |
|
"goal": data['goal'], |
|
"steps": data['steps'], |
|
"event": data["event"], |
|
"event_answer": data["event_answer"], |
|
"entity": data['entity'], |
|
"entity_answer": data['entity_answer'] |
|
} |