root commited on
Commit
248821b
·
0 Parent(s):

Add PubMedCausal dataset (Adewole et al., arXiv 2605.28363)

Browse files
.gitattributes ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ *.7z filter=lfs diff=lfs merge=lfs -text
2
+ *.arrow filter=lfs diff=lfs merge=lfs -text
3
+ *.bin filter=lfs diff=lfs merge=lfs -text
4
+ *.bz2 filter=lfs diff=lfs merge=lfs -text
5
+ *.ckpt filter=lfs diff=lfs merge=lfs -text
6
+ *.ftz filter=lfs diff=lfs merge=lfs -text
7
+ *.gz filter=lfs diff=lfs merge=lfs -text
8
+ *.h5 filter=lfs diff=lfs merge=lfs -text
9
+ *.joblib filter=lfs diff=lfs merge=lfs -text
10
+ *.lfs.* filter=lfs diff=lfs merge=lfs -text
11
+ *.lz4 filter=lfs diff=lfs merge=lfs -text
12
+ *.mds filter=lfs diff=lfs merge=lfs -text
13
+ *.mlmodel filter=lfs diff=lfs merge=lfs -text
14
+ *.model filter=lfs diff=lfs merge=lfs -text
15
+ *.msgpack filter=lfs diff=lfs merge=lfs -text
16
+ *.npy filter=lfs diff=lfs merge=lfs -text
17
+ *.npz filter=lfs diff=lfs merge=lfs -text
18
+ *.onnx filter=lfs diff=lfs merge=lfs -text
19
+ *.ot filter=lfs diff=lfs merge=lfs -text
20
+ *.parquet filter=lfs diff=lfs merge=lfs -text
21
+ *.pb filter=lfs diff=lfs merge=lfs -text
22
+ *.pickle filter=lfs diff=lfs merge=lfs -text
23
+ *.pkl filter=lfs diff=lfs merge=lfs -text
24
+ *.pt filter=lfs diff=lfs merge=lfs -text
25
+ *.pth filter=lfs diff=lfs merge=lfs -text
26
+ *.rar filter=lfs diff=lfs merge=lfs -text
27
+ *.safetensors filter=lfs diff=lfs merge=lfs -text
28
+ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
29
+ *.tar.* filter=lfs diff=lfs merge=lfs -text
30
+ *.tar filter=lfs diff=lfs merge=lfs -text
31
+ *.tflite filter=lfs diff=lfs merge=lfs -text
32
+ *.tgz filter=lfs diff=lfs merge=lfs -text
33
+ *.wasm filter=lfs diff=lfs merge=lfs -text
34
+ *.xz filter=lfs diff=lfs merge=lfs -text
35
+ *.zip filter=lfs diff=lfs merge=lfs -text
36
+ *.zst filter=lfs diff=lfs merge=lfs -text
37
+ *tfevents* filter=lfs diff=lfs merge=lfs -text
38
+ # Audio files - uncompressed
39
+ *.pcm filter=lfs diff=lfs merge=lfs -text
40
+ *.sam filter=lfs diff=lfs merge=lfs -text
41
+ *.raw filter=lfs diff=lfs merge=lfs -text
42
+ # Audio files - compressed
43
+ *.aac filter=lfs diff=lfs merge=lfs -text
44
+ *.flac filter=lfs diff=lfs merge=lfs -text
45
+ *.mp3 filter=lfs diff=lfs merge=lfs -text
46
+ *.ogg filter=lfs diff=lfs merge=lfs -text
47
+ *.wav filter=lfs diff=lfs merge=lfs -text
48
+ # Image files - uncompressed
49
+ *.bmp filter=lfs diff=lfs merge=lfs -text
50
+ *.gif filter=lfs diff=lfs merge=lfs -text
51
+ *.png filter=lfs diff=lfs merge=lfs -text
52
+ *.tiff filter=lfs diff=lfs merge=lfs -text
53
+ # Image files - compressed
54
+ *.jpg filter=lfs diff=lfs merge=lfs -text
55
+ *.jpeg filter=lfs diff=lfs merge=lfs -text
56
+ *.webp filter=lfs diff=lfs merge=lfs -text
57
+ # Video files - compressed
58
+ *.mp4 filter=lfs diff=lfs merge=lfs -text
59
+ *.webm filter=lfs diff=lfs merge=lfs -text
.gitignore ADDED
@@ -0,0 +1,2 @@
 
 
 
1
+ __pycache__/
2
+ *.pyc
README.md ADDED
@@ -0,0 +1,57 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # PubMedCausal
2
+
3
+ Causal relation extraction corpus from PubMed abstracts.
4
+
5
+ **Paper:** Adewole et al. (2025). *PubMedCausal: A Biomedical Causal Relation Extraction Corpus.*
6
+ arXiv:2605.28363
7
+
8
+ **Source:** https://github.com/josiahpaul07/PubMedCausal_Exp
9
+
10
+ ## Statistics
11
+
12
+ | Split | Sentences | Causal | Non-causal | Pairs |
13
+ |-------|-----------|--------|------------|-------|
14
+ | Train | 15,000 | 1,972 | 13,028 | ~3,900 |
15
+ | Test | 15,000 | 1,973 | 13,027 | ~2,600 |
16
+
17
+ Pairs are typed along two dimensions:
18
+ - **Causality:** Explicit / Implicit
19
+ - **Sententiality:** Intra-sentential / Inter-sentential
20
+
21
+ No countercausal annotations — all relations map to `Relation.Procausal`.
22
+
23
+ ## Conversion
24
+
25
+ Data is fetched directly from GitHub at conversion time; no local download is needed.
26
+
27
+ ```bash
28
+ python conversion_script.py
29
+ ```
30
+
31
+ Produces three task parquets per split under this directory:
32
+
33
+ ```
34
+ causality-detection/
35
+ causal-candidate-extraction/
36
+ causality-identification/
37
+ ```
38
+
39
+ ## Known limitation — unresolvable spans in the identification task
40
+
41
+ PubMedCausal sometimes records the **canonical / normalised form** of a span rather
42
+ than the exact surface text from the sentence. For example:
43
+
44
+ ```
45
+ sentence: "...thus precluding practice and placebo effects..."
46
+ effect annotation: "precludes practice" ← lemmatised, does not match
47
+ ```
48
+
49
+ Because the identification task requires inserting `<e1>…</e1>` markers at exact
50
+ character positions, pairs where either span cannot be located verbatim are
51
+ **skipped** during conversion. The conversion script prints a warning for each
52
+ skipped pair and a summary count at the end.
53
+
54
+ This affects **1,078 train pairs and 997 test pairs** (roughly 28% of intra-sentential
55
+ pairs), predominantly Implicit-causality annotations where the annotator wrote the
56
+ inferred proposition rather than the surface string. The detection and extraction
57
+ tasks are unaffected.
causal-candidate-extraction/test.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9d65538c601ea00d446b7278253f5f2b417d6094582643dfb5a403c6abf75e39
3
+ size 390911
causal-candidate-extraction/train.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:44be6164e44111693bd607ef0db3d7411a595cf7eea43d7615982e0c3e05db93
3
+ size 395699
causality-detection/test.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:c49989d5dd782d478922b311e6831cf2bbedef8ce0a1dad5ed14ab370f8c9393
3
+ size 2640494
causality-detection/train.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e17f4f2f5516342b8bf2c3d7b967b41cfaa93a9302b2c554cf02dfb0fae4adbf
3
+ size 2652258
causality-identification/test.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2ff6c2f29a7f89010fe06e7497e41341fc52206f4e0a9f747f8bb00657ef7393
3
+ size 307507
causality-identification/train.parquet ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:74f72ebb25ae506b838b5f85c0f0ad0b45d921e94e4a2c8edbdff43f3b2abddb
3
+ size 312738
conversion_script.py ADDED
@@ -0,0 +1,190 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+
3
+ """
4
+ Convert PubMedCausal to HF-compatible parquet files, loading data directly from GitHub.
5
+
6
+ PubMedCausal (Adewole et al., 2025; arXiv:2605.28363):
7
+ 30K paragraph-level rows from PubMed abstracts; 3,945 causal sentences with
8
+ 6,491 annotated cause-effect pairs. Pairs are typed as Explicit/Implicit and
9
+ Intra/Inter-sentential. No countercausal labels.
10
+
11
+ Source files (fetched at runtime — no local download needed):
12
+ Detection: detection_train.json / detection_test.json
13
+ {"s/n": int, "sentence": str, "label": 0|1}
14
+ Extraction: extraction_combined/train.json / extraction_combined/test.json
15
+ {"s/n": int, "sentence": str, "pairs": [{"cause", "effect",
16
+ "sententiality", "causality"}], "num_pairs": int}
17
+
18
+ Note: inter-sentential pairs (sententiality="Inter") are included in detection
19
+ and extraction but skipped for identification, as cause and effect may not
20
+ both appear in the single sentence string.
21
+ """
22
+
23
+ import json
24
+ import urllib.request
25
+ from pathlib import Path
26
+
27
+ import pandas as pd
28
+
29
+ from ctk.data.constants import ClassLabel, Relation, Task
30
+ from ctk.data.conversion._converter import FormatConverter
31
+
32
+ _BASE = "https://raw.githubusercontent.com/josiahpaul07/PubMedCausal_Exp/main/PUBMEDCAUSAL/data/prepared"
33
+
34
+ _DETECTION_URLS = {
35
+ "train": f"{_BASE}/detection_train.json",
36
+ "test": f"{_BASE}/detection_test.json",
37
+ }
38
+
39
+ _EXTRACTION_URLS = {
40
+ "train": f"{_BASE}/extraction_combined/train.json",
41
+ "test": f"{_BASE}/extraction_combined/test.json",
42
+ }
43
+
44
+
45
+ def _fetch(url: str) -> list[dict]:
46
+ with urllib.request.urlopen(url) as resp:
47
+ return json.load(resp)
48
+
49
+
50
+ def _find_span(text: str, span: str) -> tuple[int, int] | None:
51
+ """Return (start, end) of span in text; case-insensitive fallback."""
52
+ idx = text.find(span)
53
+ if idx == -1:
54
+ idx = text.lower().find(span.lower())
55
+ return (idx, idx + len(span)) if idx != -1 else None
56
+
57
+
58
+ class PubMedCausal2HF(FormatConverter):
59
+ def __init__(self, target: Path) -> None:
60
+ super().__init__(target)
61
+
62
+ def _convert(self, task: str, split: str) -> pd.DataFrame:
63
+ dispatch = {
64
+ Task.CausalityDetection: self._convert_detection,
65
+ Task.CausalCandidateExtraction: self._convert_extraction,
66
+ Task.CausalityIdentification: self._convert_identification,
67
+ }
68
+ return dispatch[task](split)
69
+
70
+ def _convert_detection(self, split: str) -> pd.DataFrame:
71
+ rows = [
72
+ {"index": f"pubmedcausal_{r['s/n']}", "text": r["sentence"], "label": int(r["label"])}
73
+ for r in _fetch(_DETECTION_URLS[split])
74
+ ]
75
+ return pd.DataFrame(rows).set_index("index")
76
+
77
+ def _convert_extraction(self, split: str) -> pd.DataFrame:
78
+ rows = []
79
+ for rec in _fetch(_EXTRACTION_URLS[split]):
80
+ text = rec["sentence"]
81
+ seen: set[tuple[int, int]] = set()
82
+ spans: list[list[int]] = []
83
+ for pair in rec.get("pairs", []):
84
+ for span_text in (pair["cause"], pair["effect"]):
85
+ offsets = _find_span(text, span_text)
86
+ if offsets and offsets not in seen:
87
+ seen.add(offsets)
88
+ spans.append(list(offsets))
89
+ rows.append({"index": f"pubmedcausal_{rec['s/n']}", "text": text, "entity": spans})
90
+ return pd.DataFrame(rows).set_index("index")
91
+
92
+ def _convert_identification(self, split: str) -> pd.DataFrame:
93
+ rows = []
94
+ skipped_pairs = 0
95
+ for rec in _fetch(_EXTRACTION_URLS[split]):
96
+ text = rec["sentence"]
97
+ intra = [p for p in rec.get("pairs", []) if p.get("sententiality") == "Intra"]
98
+ if not intra:
99
+ continue
100
+
101
+ # Only keep pairs where both spans can be located verbatim in the sentence.
102
+ # PubMedCausal sometimes records canonical/normalised span text that differs
103
+ # from the surface form (e.g. "precludes X" vs "precluding X"), making exact
104
+ # insertion of entity markers impossible. Such pairs are dropped here and
105
+ # counted in the summary printed after conversion.
106
+ resolvable = []
107
+ for pair in intra:
108
+ cause_loc = _find_span(text, pair["cause"])
109
+ effect_loc = _find_span(text, pair["effect"])
110
+ if cause_loc is None or effect_loc is None:
111
+ skipped_pairs += 1
112
+ print(
113
+ f" [skip] s/n={rec['s/n']}: span not found in sentence\n"
114
+ f" cause: {pair['cause']!r}\n"
115
+ f" effect: {pair['effect']!r}\n"
116
+ f" sentence: {text!r}",
117
+ flush=True,
118
+ )
119
+ continue
120
+ resolvable.append((pair, cause_loc, effect_loc))
121
+
122
+ if not resolvable:
123
+ continue
124
+
125
+ # Assign stable entity IDs to the resolved spans only.
126
+ span_to_id: dict[str, int] = {}
127
+ for pair, _, __ in resolvable:
128
+ for span_text in (pair["cause"], pair["effect"]):
129
+ if span_text not in span_to_id:
130
+ span_to_id[span_text] = len(span_to_id) + 1
131
+
132
+ relations = [
133
+ {
134
+ "relationship": int(Relation.Procausal),
135
+ "first": f"e{span_to_id[p['cause']]}",
136
+ "second": f"e{span_to_id[p['effect']]}",
137
+ }
138
+ for p, _, __ in resolvable
139
+ ]
140
+
141
+ located: list[tuple[int, int, str]] = [
142
+ (*offsets, f"e{span_to_id[span_text]}")
143
+ for span_text, offsets in (
144
+ (p["cause"], cause_loc) for p, cause_loc, _ in resolvable
145
+ )
146
+ ] + [
147
+ (*offsets, f"e{span_to_id[span_text]}")
148
+ for span_text, offsets in (
149
+ (p["effect"], effect_loc) for p, _, effect_loc in resolvable
150
+ )
151
+ ]
152
+ # Deduplicate (same span may appear in multiple pairs).
153
+ seen_locs: set[tuple[int, int]] = set()
154
+ unique_located = []
155
+ for start, end, tag in located:
156
+ if (start, end) not in seen_locs:
157
+ seen_locs.add((start, end))
158
+ unique_located.append((start, end, tag))
159
+
160
+ marked = text
161
+ for start, end, tag in sorted(unique_located, key=lambda x: x[0], reverse=True):
162
+ marked = marked[:start] + f"<{tag}>" + marked[start:end] + f"</{tag}>" + marked[end:]
163
+
164
+ rows.append({"index": f"pubmedcausal_{rec['s/n']}", "text": marked, "relations": relations})
165
+
166
+ if skipped_pairs:
167
+ print(f" [{split}] skipped {skipped_pairs} pair(s) where a span could not be located in the sentence.")
168
+
169
+ if not rows:
170
+ return pd.DataFrame(columns=["text", "relations"]).rename_axis("index")
171
+ return pd.DataFrame(rows).set_index("index")
172
+
173
+
174
+ if __name__ == "__main__":
175
+ here = Path(__file__).parent
176
+ converter = PubMedCausal2HF(here)
177
+
178
+ for split in ("train", "test"):
179
+ print(f"Converting {split}...")
180
+ converter.convert(Task.CausalityDetection, split)
181
+ converter.convert(Task.CausalCandidateExtraction, split)
182
+ converter.convert(Task.CausalityIdentification, split)
183
+
184
+ print("\nDone. Parquet files written to:")
185
+ for task in ("causality-detection", "causal-candidate-extraction", "causality-identification"):
186
+ for split in ("train", "test"):
187
+ p = here / task / f"{split}.parquet"
188
+ if p.exists():
189
+ df = pd.read_parquet(p)
190
+ print(f" {p.relative_to(here)} ({len(df):,} rows)")