File size: 1,185 Bytes
6b3ffe8 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | """Inspect either XArch JSONL schema without loading the whole split into RAM."""
import argparse
import itertools
import json
from pathlib import Path
def iter_records(dataset_dir, split='train', view='functions'):
suffix = '.functions.jsonl' if view == 'functions' else '.jsonl'
path = Path(dataset_dir) / (split + suffix)
with path.open(encoding='utf-8') as stream:
for line in stream:
yield json.loads(line)
def main():
p = argparse.ArgumentParser(description=__doc__)
p.add_argument('--dataset-dir', required=True)
p.add_argument('--view', choices=['functions', 'pairs'], default='functions')
p.add_argument('--split', choices=['train', 'validation', 'test'], default='train')
p.add_argument('--limit', type=int, default=2)
args = p.parse_args()
for record in itertools.islice(iter_records(args.dataset_dir, args.split, args.view), args.limit):
example = dict(record)
for name in ['text', 'query', 'positive']:
if name in example:
example[name] = example[name][:240]
print(json.dumps(example, indent=2, ensure_ascii=False))
if __name__ == '__main__':
main()
|