Clean public dataset card
Browse files- README.md +8 -43
- prepare_dataset.py +0 -147
- upload_dataset.py +0 -50
README.md
CHANGED
|
@@ -50,19 +50,16 @@ foodon = dataset.filter(lambda row: row["ontology"] == "foodon")
|
|
| 50 |
|
| 51 |
## Data Structure
|
| 52 |
|
| 53 |
-
|
| 54 |
|
| 55 |
```text
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
├──
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
│ └── dataset_summary.json
|
| 64 |
-
├── prepare_dataset.py
|
| 65 |
-
└── upload_dataset.py
|
| 66 |
```
|
| 67 |
|
| 68 |
JSONL columns:
|
|
@@ -79,38 +76,6 @@ JSONL columns:
|
|
| 79 |
|
| 80 |
Additional aggregate metadata is stored in `metadata/dataset_summary.json`. It is intentionally kept outside `data/` so that the Hugging Face dataset viewer only parses the JSONL data files.
|
| 81 |
|
| 82 |
-
## Preparation
|
| 83 |
-
|
| 84 |
-
From the repository root:
|
| 85 |
-
|
| 86 |
-
```bash
|
| 87 |
-
python huggingface/prepare_dataset.py \
|
| 88 |
-
--input prompt_learning_dataset.zip \
|
| 89 |
-
--output huggingface/data
|
| 90 |
-
```
|
| 91 |
-
|
| 92 |
-
## Upload
|
| 93 |
-
|
| 94 |
-
Authenticate first:
|
| 95 |
-
|
| 96 |
-
```bash
|
| 97 |
-
export HF_TOKEN=<your_hugging_face_token>
|
| 98 |
-
```
|
| 99 |
-
|
| 100 |
-
Then upload:
|
| 101 |
-
|
| 102 |
-
```bash
|
| 103 |
-
python huggingface/upload_dataset.py --repo-id Hui97/LLMOwlR
|
| 104 |
-
```
|
| 105 |
-
|
| 106 |
-
The public dataset URL is:
|
| 107 |
-
|
| 108 |
-
```text
|
| 109 |
-
https://huggingface.co/datasets/Hui97/LLMOwlR
|
| 110 |
-
```
|
| 111 |
-
|
| 112 |
-
Override the target with `--repo-id` or `HF_REPO_ID` if the dataset should live under a different Hugging Face namespace.
|
| 113 |
-
|
| 114 |
## Citation
|
| 115 |
|
| 116 |
```bibtex
|
|
|
|
| 50 |
|
| 51 |
## Data Structure
|
| 52 |
|
| 53 |
+
Repository files:
|
| 54 |
|
| 55 |
```text
|
| 56 |
+
README.md
|
| 57 |
+
data/
|
| 58 |
+
├── foodon.jsonl
|
| 59 |
+
├── go-plus.jsonl
|
| 60 |
+
└── snomedCT.jsonl
|
| 61 |
+
metadata/
|
| 62 |
+
└── dataset_summary.json
|
|
|
|
|
|
|
|
|
|
| 63 |
```
|
| 64 |
|
| 65 |
JSONL columns:
|
|
|
|
| 76 |
|
| 77 |
Additional aggregate metadata is stored in `metadata/dataset_summary.json`. It is intentionally kept outside `data/` so that the Hugging Face dataset viewer only parses the JSONL data files.
|
| 78 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 79 |
## Citation
|
| 80 |
|
| 81 |
```bibtex
|
prepare_dataset.py
DELETED
|
@@ -1,147 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
import argparse
|
| 3 |
-
import json
|
| 4 |
-
import re
|
| 5 |
-
import zipfile
|
| 6 |
-
from collections import defaultdict
|
| 7 |
-
from pathlib import Path
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
QUERY_RE = re.compile(r"^prompt_learning_dataset/([^/]+)/(d(\d+))/(query_(.+)_d\d+(?:_owl)?\.json)$")
|
| 11 |
-
|
| 12 |
-
|
| 13 |
-
def load_json_from_zip(zip_file, member):
|
| 14 |
-
with zip_file.open(member) as handle:
|
| 15 |
-
return json.loads(handle.read().decode("utf-8"))
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
def build_index_lookup(zip_file, ontology):
|
| 19 |
-
lookup = {}
|
| 20 |
-
prefix = f"prompt_learning_dataset/{ontology}/"
|
| 21 |
-
|
| 22 |
-
for member in zip_file.namelist():
|
| 23 |
-
if not member.startswith(prefix) or not member.endswith("justification_index.json"):
|
| 24 |
-
continue
|
| 25 |
-
index_data = load_json_from_zip(zip_file, member)
|
| 26 |
-
for rel_path, indices in index_data.items():
|
| 27 |
-
lookup[rel_path] = indices
|
| 28 |
-
|
| 29 |
-
stats_member = f"{prefix}all_length_statistics.json"
|
| 30 |
-
if stats_member in zip_file.namelist():
|
| 31 |
-
stats = load_json_from_zip(zip_file, stats_member)
|
| 32 |
-
for mode_data in stats.values():
|
| 33 |
-
for length_data in mode_data.values():
|
| 34 |
-
paths = length_data.get("paths", [])
|
| 35 |
-
just_ids = length_data.get("just_ids", [])
|
| 36 |
-
for rel_path, indices in zip(paths, just_ids):
|
| 37 |
-
lookup.setdefault(rel_path, indices)
|
| 38 |
-
|
| 39 |
-
return lookup
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
def iter_rows(zip_path):
|
| 43 |
-
with zipfile.ZipFile(zip_path) as zip_file:
|
| 44 |
-
members = [
|
| 45 |
-
member
|
| 46 |
-
for member in zip_file.namelist()
|
| 47 |
-
if member.startswith("prompt_learning_dataset/")
|
| 48 |
-
and "__MACOSX" not in member
|
| 49 |
-
and member.endswith(".json")
|
| 50 |
-
]
|
| 51 |
-
ontologies = sorted({member.split("/")[1] for member in members if len(member.split("/")) > 2})
|
| 52 |
-
index_by_ontology = {
|
| 53 |
-
ontology: build_index_lookup(zip_file, ontology)
|
| 54 |
-
for ontology in ontologies
|
| 55 |
-
}
|
| 56 |
-
|
| 57 |
-
for member in sorted(members):
|
| 58 |
-
match = QUERY_RE.match(member)
|
| 59 |
-
if not match:
|
| 60 |
-
continue
|
| 61 |
-
|
| 62 |
-
ontology, distance_dir, atomic_distance, filename = match.group(1), match.group(2), int(match.group(3)), match.group(4)
|
| 63 |
-
rel_path = f"{distance_dir}/{filename}"
|
| 64 |
-
sample = load_json_from_zip(zip_file, member)
|
| 65 |
-
indices = index_by_ontology.get(ontology, {}).get(rel_path)
|
| 66 |
-
axioms = sample.get("axioms", [])
|
| 67 |
-
correct_axioms = []
|
| 68 |
-
if isinstance(indices, list):
|
| 69 |
-
correct_axioms = [
|
| 70 |
-
axioms[index]
|
| 71 |
-
for index in indices
|
| 72 |
-
if isinstance(index, int) and 0 <= index < len(axioms)
|
| 73 |
-
]
|
| 74 |
-
|
| 75 |
-
yield {
|
| 76 |
-
"ontology": ontology,
|
| 77 |
-
"atomic_distance": atomic_distance,
|
| 78 |
-
"query_id": filename.split("_d")[0].replace("query_", ""),
|
| 79 |
-
"format": "owl" if filename.endswith("_owl.json") else "natural_language",
|
| 80 |
-
"query": sample.get("query", ""),
|
| 81 |
-
"axioms": axioms,
|
| 82 |
-
"correct_axiom_indices": indices,
|
| 83 |
-
"correct_axioms": correct_axioms,
|
| 84 |
-
"source_path": member,
|
| 85 |
-
}
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
def write_jsonl(path, rows):
|
| 89 |
-
with path.open("w", encoding="utf-8") as handle:
|
| 90 |
-
for row in rows:
|
| 91 |
-
handle.write(json.dumps(row, ensure_ascii=False) + "\n")
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
def main():
|
| 95 |
-
parser = argparse.ArgumentParser(description="Prepare LLMOwlR data for Hugging Face Datasets.")
|
| 96 |
-
parser.add_argument("--input", default="prompt_learning_dataset.zip", help="Source prompt dataset zip")
|
| 97 |
-
parser.add_argument("--output", default="huggingface/data", help="Output folder for JSONL files")
|
| 98 |
-
parser.add_argument(
|
| 99 |
-
"--summary-output",
|
| 100 |
-
default=None,
|
| 101 |
-
help="Output path for dataset summary metadata. Defaults to <output parent>/metadata/dataset_summary.json",
|
| 102 |
-
)
|
| 103 |
-
args = parser.parse_args()
|
| 104 |
-
|
| 105 |
-
zip_path = Path(args.input)
|
| 106 |
-
output_dir = Path(args.output)
|
| 107 |
-
summary_path = (
|
| 108 |
-
Path(args.summary_output)
|
| 109 |
-
if args.summary_output
|
| 110 |
-
else output_dir.parent / "metadata" / "dataset_summary.json"
|
| 111 |
-
)
|
| 112 |
-
if not zip_path.is_file():
|
| 113 |
-
raise FileNotFoundError(f"Input zip not found: {zip_path}")
|
| 114 |
-
|
| 115 |
-
output_dir.mkdir(parents=True, exist_ok=True)
|
| 116 |
-
rows_by_ontology = defaultdict(list)
|
| 117 |
-
for row in iter_rows(zip_path):
|
| 118 |
-
rows_by_ontology[row["ontology"]].append(row)
|
| 119 |
-
|
| 120 |
-
summary = {
|
| 121 |
-
"source": str(zip_path),
|
| 122 |
-
"ontologies": {},
|
| 123 |
-
"total_rows": 0,
|
| 124 |
-
}
|
| 125 |
-
|
| 126 |
-
for ontology, rows in sorted(rows_by_ontology.items()):
|
| 127 |
-
rows.sort(key=lambda row: (row["atomic_distance"], row["format"], row["query_id"]))
|
| 128 |
-
output_path = output_dir / f"{ontology}.jsonl"
|
| 129 |
-
write_jsonl(output_path, rows)
|
| 130 |
-
summary["ontologies"][ontology] = {
|
| 131 |
-
"rows": len(rows),
|
| 132 |
-
"file": output_path.name,
|
| 133 |
-
"atomic_distances": sorted({row["atomic_distance"] for row in rows}),
|
| 134 |
-
"formats": sorted({row["format"] for row in rows}),
|
| 135 |
-
}
|
| 136 |
-
summary["total_rows"] += len(rows)
|
| 137 |
-
|
| 138 |
-
summary_path.parent.mkdir(parents=True, exist_ok=True)
|
| 139 |
-
with summary_path.open("w", encoding="utf-8") as handle:
|
| 140 |
-
json.dump(summary, handle, ensure_ascii=False, indent=2)
|
| 141 |
-
|
| 142 |
-
print(f"Wrote {summary['total_rows']} rows to {output_dir}")
|
| 143 |
-
print(f"Wrote summary metadata to {summary_path}")
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
if __name__ == "__main__":
|
| 147 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
upload_dataset.py
DELETED
|
@@ -1,50 +0,0 @@
|
|
| 1 |
-
#!/usr/bin/env python3
|
| 2 |
-
import argparse
|
| 3 |
-
import os
|
| 4 |
-
from pathlib import Path
|
| 5 |
-
|
| 6 |
-
try:
|
| 7 |
-
from huggingface_hub import HfApi
|
| 8 |
-
except ModuleNotFoundError as exc:
|
| 9 |
-
raise SystemExit(
|
| 10 |
-
"Missing dependency: huggingface_hub. "
|
| 11 |
-
"Install the project dependencies first with `python -m pip install -r requirements.txt`."
|
| 12 |
-
) from exc
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
def main():
|
| 16 |
-
parser = argparse.ArgumentParser(description="Upload the prepared LLMOwlR dataset to Hugging Face.")
|
| 17 |
-
parser.add_argument("--repo-id", default=os.environ.get("HF_REPO_ID"), help="Dataset repo id, e.g. Hui97/LLMOwlR")
|
| 18 |
-
parser.add_argument("--folder", default="huggingface", help="Folder to upload")
|
| 19 |
-
parser.add_argument("--private", action="store_true", help="Create the dataset repo as private")
|
| 20 |
-
parser.add_argument("--commit-message", default="Upload LLMOwlR prompt learning dataset")
|
| 21 |
-
args = parser.parse_args()
|
| 22 |
-
|
| 23 |
-
if not args.repo_id:
|
| 24 |
-
raise SystemExit("Provide --repo-id or set HF_REPO_ID.")
|
| 25 |
-
|
| 26 |
-
folder = Path(args.folder)
|
| 27 |
-
data_dir = folder / "data"
|
| 28 |
-
if not (folder / "README.md").is_file():
|
| 29 |
-
raise FileNotFoundError(f"Dataset card not found: {folder / 'README.md'}")
|
| 30 |
-
if not data_dir.is_dir() or not any(data_dir.glob("*.jsonl")):
|
| 31 |
-
raise FileNotFoundError(
|
| 32 |
-
f"Prepared JSONL files not found in {data_dir}. Run huggingface/prepare_dataset.py first."
|
| 33 |
-
)
|
| 34 |
-
|
| 35 |
-
api = HfApi()
|
| 36 |
-
api.create_repo(repo_id=args.repo_id, repo_type="dataset", private=args.private, exist_ok=True)
|
| 37 |
-
api.upload_folder(
|
| 38 |
-
repo_id=args.repo_id,
|
| 39 |
-
repo_type="dataset",
|
| 40 |
-
folder_path=str(folder),
|
| 41 |
-
commit_message=args.commit_message,
|
| 42 |
-
ignore_patterns=["__pycache__/*", "*.pyc", ".DS_Store", "data/dataset_summary.json"],
|
| 43 |
-
delete_patterns=["data/dataset_summary.json"],
|
| 44 |
-
)
|
| 45 |
-
|
| 46 |
-
print(f"Uploaded dataset to https://huggingface.co/datasets/{args.repo_id}")
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
if __name__ == "__main__":
|
| 50 |
-
main()
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|