Datasets:
Tasks:
Text Classification
Modalities:
Text
Formats:
parquet
Languages:
English
Size:
10K - 100K
Tags:
causality
File size: 2,562 Bytes
10dd756 3311edc 10dd756 31b6727 10dd756 31b6727 10dd756 3311edc 10dd756 31b6727 10dd756 3311edc | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 | #!/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")
|