Download src/macjev/v4data/classa_isarcasm_train.py from VTN-TokenFactory/Telasap-0.8B-v1.0: direct link, hf CLI and curl.
- Browser
- Download file 4.59 kB
-
https://huggingface.co/VTN-TokenFactory/Telasap-0.8B-v1.0/resolve/main/src/macjev/v4data/classa_isarcasm_train.py
- Command line
-
hf download hf://VTN-TokenFactory/Telasap-0.8B-v1.0/src/macjev/v4data/classa_isarcasm_train.py
-
curl -L -o classa_isarcasm_train.py https://huggingface.co/VTN-TokenFactory/Telasap-0.8B-v1.0/resolve/main/src/macjev/v4data/classa_isarcasm_train.py
4.59 kB
| """Class A ingest: iSarcasmEval task A English TRAIN (upstream iabufarha/iSarcasmEval, MIT; mirror tlam25/iSarcasm_taskA | |
| train.csv, apache-2.0) -> noul sarcastic/literal rows (criteria flipped 50%), choice "which version is sarcastic" | |
| (tweet vs the author's own non-sarcastic rephrase), choice "which rhetorical device". test/val never read. | |
| Run: PYTHONPATH=src .venv/bin/python -m macjev.v4data.classa_isarcasm_train""" | |
| from __future__ import annotations | |
| import argparse, csv | |
| from ..download import fetch | |
| from ..paths import ROOT | |
| from . import ingest_common as C | |
| NAME = "isarcasm_train" | |
| OUT_DIR = ROOT / "data" / "synth-v4" / "classA" / NAME | |
| REPO, FILE = "tlam25/iSarcasm_taskA", "train.csv" | |
| SOURCE = "iabufarha/iSarcasmEval task A en (train; mirror tlam25/iSarcasm_taskA)" | |
| LICENSE = "mit" | |
| DEVICES = {"sarcasm": "sarcasm: saying the opposite of what is meant to mock or criticise", | |
| "irony": "irony: an outcome or statement contrary to what is expected", | |
| "satire": "satire: ridicule of people, institutions or society", | |
| "understatement": "understatement: presenting something as far smaller than it is", | |
| "overstatement": "overstatement: exaggerating for effect", | |
| "rhetorical_question": "rhetorical question: a question asked for effect, not for an answer"} | |
| def main(argv=None): | |
| ap = argparse.ArgumentParser(); a = ap.parse_args(argv) | |
| got = fetch(REPO, [FILE]) | |
| with open(got["files"][FILE], encoding="utf-8-sig") as f: | |
| data = list(csv.DictReader(f)) | |
| rows = [] | |
| for i, r in enumerate(data): | |
| text = (r.get("org_tweet") or r.get("tweet") or "").strip() | |
| if len(text) < 8: | |
| continue | |
| sarc = r.get("sarcastic") == "1" | |
| gid = f"isarcasm:{r.get('tweet_id') or i}" | |
| split = C.split_for(gid) | |
| rng = C.rng_for(NAME, i) | |
| prov = {"dataset": REPO, "revision": got["revision"], "file": FILE, "line": i, "source_id": r.get("tweet_id"), "source_split": "train"} | |
| flip = rng.random() < 0.5 | |
| ins = "The author means the text literally (no sarcasm)." if flip else "The text is sarcastic." | |
| valid = ["true" if ((not sarc) if flip else sarc) else "false"] | |
| rows.append(C.make(id=f"v4A_isarcasm/train/{i}/noul", group_id=gid, split=split, source=SOURCE, category="v4A_isarcasm", | |
| lang="en", license=LICENSE, state={"text": text}, question={"t": "noul", "ins": ins, "crit": None}, valid=valid, | |
| provenance=prov, component="di_language", family="isarcasm_detect", label_method="source_label", di=[C.di_id("iSarcasmEval")])) | |
| reph = (r.get("rephrase") or "").strip() | |
| if sarc and len(reph) >= 8 and reph.lower() != text.lower(): | |
| a_first = rng.random() < 0.5 | |
| crit = {"A": text if a_first else reph, "B": reph if a_first else text} | |
| rows.append(C.make(id=f"v4A_isarcasm/train/{i}/pair", group_id=gid, split=split, source=SOURCE, category="v4A_isarcasm", | |
| lang="en", license=LICENSE, state={"version_A": crit["A"], "version_B": crit["B"]}, | |
| question={"t": "choice", "ins": "One version is sarcastic and the other says the same thing literally. Which version is the sarcastic one?", "crit": {"A": "version A", "B": "version B"}}, | |
| valid=["A" if a_first else "B"], provenance=prov, component="di_language", family="isarcasm_detect", label_method="source_label", di=[C.di_id("iSarcasmEval")])) | |
| flags = [d for d in DEVICES if r.get(d) == "1"] | |
| if sarc and flags: | |
| rows.append(C.make(id=f"v4A_isarcasm/train/{i}/device", group_id=gid, split=split, source=SOURCE, category="v4A_isarcasm", | |
| lang="en", license=LICENSE, state={"text": text}, | |
| question={"t": "choice", "ins": "Which rhetorical device does the text use?", "crit": dict(DEVICES)}, | |
| valid=flags, provenance=prov, component="di_language", family="isarcasm_detect", label_method="source_label", di=[C.di_id("iSarcasmEval")])) | |
| C.finish(OUT_DIR, rows, builder="macjev.v4data.classa_isarcasm_train-v1", source=SOURCE, license=LICENSE, | |
| license_evidence="github.com/iabufarha/iSarcasmEval LICENSE (MIT, 2022 Ibrahim Abu Farha); mirror card apache-2.0", | |
| splits_used=["train"], forbidden_splits=["val", "test"], data_class="A", class_A_benchmark=C.di_id("iSarcasmEval"), | |
| extra={"revision": got["revision"]}) | |
| if __name__ == "__main__": | |
| main() | |