Download tools/explode.py from llamaindex/ExtractBench-results: direct link, hf CLI and curl.
- Browser
- Download file 2.6 kB
-
https://huggingface.co/datasets/llamaindex/ExtractBench-results/resolve/main/tools/explode.py
- Command line
-
hf download hf://datasets/llamaindex/ExtractBench-results/tools/explode.py
-
curl -L -o explode.py https://huggingface.co/datasets/llamaindex/ExtractBench-results/resolve/main/tools/explode.py
2.6 kB
| #!/usr/bin/env python3 | |
| """Turn published results JSONL back into the per-document layout the public | |
| evaluators read, so ``parse-bench run <pipeline> --skip_inference`` or | |
| ``extract-bench run <pipeline> --skip_inference`` scores them without any | |
| inference. | |
| python tools/explode.py --benchmark parsebench results/<pipeline> output/<pipeline> | |
| Writes ``output/<pipeline>/<category>/<stem>.result.json`` and a minimal | |
| ``_metadata.json``. Python 3.9+, standard library only. | |
| """ | |
| import argparse | |
| import json | |
| import os | |
| import sys | |
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | |
| from hfresults_common import BENCHMARKS, group_dir_for, metadata_for, read_jsonl, record_stem # noqa: E402 | |
| def main() -> int: | |
| parser = argparse.ArgumentParser(description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) | |
| parser.add_argument("--benchmark", required=True, choices=sorted(BENCHMARKS)) | |
| parser.add_argument("results_dir", help="results/<pipeline> folder holding <category>.jsonl files") | |
| parser.add_argument("output_dir", help="output/<pipeline> folder to create") | |
| parser.add_argument("--provider", default=None, help="provider name for _metadata.json (default: pipeline)") | |
| args = parser.parse_args() | |
| spec = BENCHMARKS[args.benchmark] | |
| pipeline = os.path.basename(os.path.normpath(args.results_dir)) | |
| os.makedirs(args.output_dir, exist_ok=True) | |
| written = {} | |
| for category in spec["categories"]: | |
| path = os.path.join(args.results_dir, category + ".jsonl") | |
| if not os.path.exists(path): | |
| continue | |
| group_dir = os.path.join(args.output_dir, group_dir_for(args.benchmark, category)) | |
| os.makedirs(group_dir, exist_ok=True) | |
| count = 0 | |
| for _number, _line, record in read_jsonl(path): | |
| _group, stem = record_stem(record) | |
| target = os.path.join(group_dir, stem + ".result.json") | |
| with open(target, "w", encoding="utf-8") as fh: | |
| json.dump(record, fh, ensure_ascii=False) | |
| count += 1 | |
| written[category] = count | |
| if not written: | |
| print("no <category>.jsonl files found in %s" % args.results_dir, file=sys.stderr) | |
| return 1 | |
| with open(os.path.join(args.output_dir, "_metadata.json"), "w", encoding="utf-8") as fh: | |
| json.dump(metadata_for(pipeline, args.provider, spec["product_type"]), fh, indent=2) | |
| for category, count in written.items(): | |
| print("%s: %d documents" % (category, count)) | |
| print("wrote %s" % args.output_dir) | |
| return 0 | |
| if __name__ == "__main__": | |
| sys.exit(main()) | |