jumplander commited on
Commit
98b3aef
·
verified ·
1 Parent(s): 62d4b6b

Upload tools/validate_jsonl.py

Browse files
Files changed (1) hide show
  1. tools/validate_jsonl.py +30 -0
tools/validate_jsonl.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ import json, sys
3
+ from pathlib import Path
4
+
5
+ required = ['id','dataset','version','split','language','domain','scenario_type','raw_user_message','normalized_user_intent','intent','constraints','ambiguity','expected_model_behavior','bad_model_behavior','ideal_response','evaluation','metadata']
6
+
7
+ def validate(path):
8
+ errors = 0
9
+ total = 0
10
+ with open(path, 'r', encoding='utf-8') as f:
11
+ for line_no, line in enumerate(f, 1):
12
+ total += 1
13
+ try:
14
+ obj = json.loads(line)
15
+ except Exception as e:
16
+ print(f'JSON error at line {line_no}: {e}')
17
+ errors += 1
18
+ continue
19
+ missing = [k for k in required if k not in obj]
20
+ if missing:
21
+ print(f'Missing {missing} at line {line_no}')
22
+ errors += 1
23
+ print(f'Validated {total} records from {path}. Errors: {errors}')
24
+ return errors
25
+
26
+ if __name__ == '__main__':
27
+ if len(sys.argv) < 2:
28
+ print('Usage: python tools/validate_jsonl.py data/train.jsonl')
29
+ raise SystemExit(1)
30
+ raise SystemExit(validate(sys.argv[1]))