SemEval2010T8 / conversion_script.py
thagen's picture
current state
3311edc
Raw History Blame Contribute Delete
2.56 kB
#!/usr/bin/env python3
"""
Run this script as ./conversion_script.py to convert the UniCausal SemEval 2010 Task 8 files to HF-compatible parquet files.
Note: Only Cause-Effect relation pairs are retained from the original 9-way relation dataset.
No causal-candidate-extraction table: UniCausal's SemEval-2010 Task 8 CSVs
don't carry the span data this converter would need to build one directly.
Derived instead from the causality-identification table written just
above, via causalatee.data.utils.identification_batch_to_extraction --
keeps the two tables consistent by construction (extraction is exactly
"identification's entities, restricted to the ones backing an actual
relation").
"""
# 1) Install dependencies:
# pip install git+https://github.com/TheMrSheldon/causality-toolkit.git
# 2) Source files (fetched automatically via pandas):
# - https://raw.githubusercontent.com/tanfiona/UniCausal/refs/heads/main/data/splits/semeval2010t8_train.csv
# - https://raw.githubusercontent.com/tanfiona/UniCausal/refs/heads/main/data/splits/semeval2010t8_test.csv
from pathlib import Path
import pandas as pd
from causalatee.data.constants import Task
from causalatee.data.conversion import UniCausal2HF
from causalatee.data.utils import identification_batch_to_extraction
converter = UniCausal2HF({"train": "https://raw.githubusercontent.com/tanfiona/UniCausal/refs/heads/main/data/splits/semeval2010t8_train.csv",
"test": "https://raw.githubusercontent.com/tanfiona/UniCausal/refs/heads/main/data/splits/semeval2010t8_test.csv"}, Path.cwd(), grouped=False)
converter.convert(Task.CausalityDetection, "train")
converter.convert(Task.CausalityDetection, "test")
converter.convert(Task.CausalityIdentification, "train")
converter.convert(Task.CausalityIdentification, "test")
def _convert_extraction_from_identification(split: str) -> None:
identification = pd.read_parquet(f"./causality-identification/{split}.parquet")
batch = {"text": identification["text"].tolist(), "relations": identification["relations"].tolist()}
out = identification_batch_to_extraction(batch)
df = pd.DataFrame({
"index": [f"semeval2010t8_{split}_{i}" for i in range(len(out["text"]))],
"text": out["text"],
"entity": out["entity"],
}).set_index("index")
Path("./causal-candidate-extraction").mkdir(exist_ok=True)
df.to_parquet(f"./causal-candidate-extraction/{split}.parquet", engine="pyarrow")
_convert_extraction_from_identification("train")
_convert_extraction_from_identification("test")