Add md2d index + mapping + corpus
Browse files- .gitattributes +2 -0
- index/e5_Flat.index +3 -0
- index/emb_e5.memmap +3 -0
- mapping.json +0 -0
- md2d.jsonl +0 -0
- process_corpus.py +78 -0
.gitattributes
CHANGED
|
@@ -58,3 +58,5 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 58 |
# Video files - compressed
|
| 59 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 60 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
| 58 |
# Video files - compressed
|
| 59 |
*.mp4 filter=lfs diff=lfs merge=lfs -text
|
| 60 |
*.webm filter=lfs diff=lfs merge=lfs -text
|
| 61 |
+
index/e5_Flat.index filter=lfs diff=lfs merge=lfs -text
|
| 62 |
+
index/emb_e5.memmap filter=lfs diff=lfs merge=lfs -text
|
index/e5_Flat.index
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:edc7c08bb66f9fffb084014e1efafb7ce78182b330bacd94871eb492566fb644
|
| 3 |
+
size 31374381
|
index/emb_e5.memmap
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:839b9cd05bcc1253476276b8c5ea9712109bc4d95ee354ec9a3e24bc46538129
|
| 3 |
+
size 31374336
|
mapping.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
md2d.jsonl
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
process_corpus.py
ADDED
|
@@ -0,0 +1,78 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python3
|
| 2 |
+
import argparse
|
| 3 |
+
import json
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
|
| 6 |
+
def iter_spans(obj):
|
| 7 |
+
"""
|
| 8 |
+
Yield dicts that look like spans with fields:
|
| 9 |
+
title, id_sp, text_sec
|
| 10 |
+
Works whether the JSON is a dict-of-dicts (with numeric keys) or nested.
|
| 11 |
+
"""
|
| 12 |
+
if isinstance(obj, dict):
|
| 13 |
+
# Detect a span record
|
| 14 |
+
if all(k in obj for k in ("title", "id_sp", "text_sec")):
|
| 15 |
+
yield obj
|
| 16 |
+
# Otherwise, recurse into values
|
| 17 |
+
for v in obj.values():
|
| 18 |
+
yield from iter_spans(v)
|
| 19 |
+
elif isinstance(obj, list):
|
| 20 |
+
for v in obj:
|
| 21 |
+
yield from iter_spans(v)
|
| 22 |
+
|
| 23 |
+
def main():
|
| 24 |
+
ap = argparse.ArgumentParser(description="Build ID mapping and unique content from multidoc2dial spans.")
|
| 25 |
+
ap.add_argument("--input", required=True, help="Path to multidoc2dial_doc.json")
|
| 26 |
+
ap.add_argument("--mapping_out", default="mapping.json", help="Output path for mapping dict (JSON)")
|
| 27 |
+
ap.add_argument("--contents_out", default="contents.jsonl", help="Output path for contents (JSONL)")
|
| 28 |
+
# If you ever need a different base suffix than '#1_0', change here:
|
| 29 |
+
ap.add_argument("--base_suffix", default="#1_0", help="Suffix to append after title before _<id_sp>")
|
| 30 |
+
args = ap.parse_args()
|
| 31 |
+
|
| 32 |
+
input_path = Path(args.input)
|
| 33 |
+
with input_path.open("r", encoding="utf-8") as f:
|
| 34 |
+
data = json.load(f)
|
| 35 |
+
|
| 36 |
+
# Dedup by exact text_sec (after strip)
|
| 37 |
+
text_to_int = {} # normalized text_sec -> int_id
|
| 38 |
+
next_id = 1
|
| 39 |
+
|
| 40 |
+
# Mapping from full key -> int_id
|
| 41 |
+
key_to_int = {} # "<title>#1_0_<id_sp>" -> int_id
|
| 42 |
+
|
| 43 |
+
# For writing contents.jsonl only once per unique int_id
|
| 44 |
+
seen_int_ids = set()
|
| 45 |
+
|
| 46 |
+
# First pass: assign int IDs by text_sec
|
| 47 |
+
for span in iter_spans(data):
|
| 48 |
+
title = span["title"].strip()
|
| 49 |
+
id_sp = str(span["id_sp"]).strip()
|
| 50 |
+
text_sec = span["text_sec"].strip()
|
| 51 |
+
|
| 52 |
+
full_key = f"{title}{args.base_suffix}_{id_sp}"
|
| 53 |
+
|
| 54 |
+
if text_sec not in text_to_int:
|
| 55 |
+
text_to_int[text_sec] = next_id
|
| 56 |
+
next_id += 1
|
| 57 |
+
|
| 58 |
+
int_id = text_to_int[text_sec]
|
| 59 |
+
key_to_int[full_key] = int_id
|
| 60 |
+
|
| 61 |
+
# Write mapping.json
|
| 62 |
+
with open(args.mapping_out, "w", encoding="utf-8") as f:
|
| 63 |
+
json.dump(key_to_int, f, ensure_ascii=False, indent=2)
|
| 64 |
+
|
| 65 |
+
# Write contents.jsonl (one line per unique text_sec)
|
| 66 |
+
# Ensure stable order by int_id
|
| 67 |
+
# Invert text_to_int to {int_id: text_sec}
|
| 68 |
+
int_to_text = {v: k for k, v in text_to_int.items()}
|
| 69 |
+
with open(args.contents_out, "w", encoding="utf-8") as f:
|
| 70 |
+
for int_id in sorted(int_to_text.keys()):
|
| 71 |
+
obj = {"id": int_id, "contents": int_to_text[int_id]}
|
| 72 |
+
f.write(json.dumps(obj, ensure_ascii=False) + "\n")
|
| 73 |
+
|
| 74 |
+
print(f"Wrote {len(key_to_int):,} mappings to {args.mapping_out}")
|
| 75 |
+
print(f"Wrote {len(int_to_text):,} unique contents to {args.contents_out}")
|
| 76 |
+
|
| 77 |
+
if __name__ == "__main__":
|
| 78 |
+
main()
|