| |
|
|
| """ |
| Run this script as ./conversion_script.py to convert the UniCausal CTB files to HF-compatible parquet files. |
| |
| No causal-candidate-extraction table: UniCausal's CTB 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"). |
| """ |
|
|
| |
| |
| |
| |
| |
|
|
| 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/ctb_train.csv", |
| "test": "https://raw.githubusercontent.com/tanfiona/UniCausal/refs/heads/main/data/splits/ctb_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"ctb_{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") |
|
|