Tablinum-2: the Lite-Beam engram, release 2 (card, code, recipes, 9 released tables)
901f964 verified Download code/ecfr_dolma.py from tablinum/tablinum-2: direct link, hf CLI and curl.
- Browser
- Download file 1.26 kB
-
https://huggingface.co/datasets/tablinum/tablinum-2/resolve/main/code/ecfr_dolma.py
- Command line
-
hf download hf://datasets/tablinum/tablinum-2/code/ecfr_dolma.py
-
curl -L -o ecfr_dolma.py https://huggingface.co/datasets/tablinum/tablinum-2/resolve/main/code/ecfr_dolma.py
1.26 kB
| """ecfr_dolma.py ECFR-titleN.xml OUT.json.gz (10-27) - govinfo eCFR bulk XML -> dolma json.gz for dolma_chunk.py doc: one doc per | |
| SECTION (DIV8), title "N CFR § x.y Heading" (research/finance.md: questions name the citation, so BM25 needs it in the passage), | |
| text = its paragraphs. Public domain.""" | |
| import sys, re, json, gzip | |
| import xml.etree.ElementTree as ET | |
| src, dst = sys.argv[1:3] | |
| tn = re.search(r"title-?(\d+)", src).group(1) | |
| txt = lambda e: re.sub(r"\s+", " ", "".join(e.itertext())).strip() | |
| n, part = 0, "" | |
| with gzip.open(dst + ".tmp", "wt") as f: | |
| for ev, e in ET.iterparse(src, events=("end",)): | |
| if e.tag.startswith("DIV") and e.get("TYPE") == "PART": | |
| e.clear(); continue | |
| if e.tag.startswith("DIV") and e.get("TYPE") == "SECTION": | |
| h = e.find("HEAD"); head = txt(h) if h is not None else e.get("N", "") | |
| body = "\n".join(txt(p) for p in e.iter() if p.tag in ("P", "FP", "NOTE", "EXTRACT") and txt(p)) | |
| if len(body.split()) >= 20: | |
| f.write(json.dumps({"id": f"ecfr{tn}-{n}", "text": body, "metadata": {"title": f"{tn} CFR {head}"[:160]}}) + "\n"); n += 1 | |
| e.clear() | |
| import os # noqa: E402 | |
| os.replace(dst + ".tmp", dst) | |
| print(src, "sections", n, flush=True) | |