RobotAgentBench-TrainingData / language /validate_language.py
Wr3ck1Am's picture
Add files using upload-large-folder tool
0c2daed verified
Raw History Blame Contribute Delete
7.04 kB
#!/usr/bin/env python3
"""Meaningful language integrity checks, independently of format/physics checks."""
from pathlib import Path
import json, re, importlib.util
P=Path(__file__).resolve().parent
spec=importlib.util.spec_from_file_location('normalize',P/'normalize_language.py');m=importlib.util.module_from_spec(spec);spec.loader.exec_module(m)
checks=[]
def check(name,condition):
checks.append({'check':name,'passed':bool(condition)})
if not condition:raise AssertionError(name)
M=json.loads((P/'exact_instruction_map.json').read_text())
for s,r in M.items():
n=m.normalize_instruction(s)
check('strict_exact:'+s[:60],not m.audit_instruction(n) and n==r['normalized_instruction'])
check('idempotent:'+s[:60],m.normalize_instruction(n)==n)
check('orange_and_blue_are_distinct',m.normalize_instruction('Pick up gatorade_m.')=='Pick up orange sports drink.' and m.normalize_instruction('Pick up gatorade_t.')=='Pick up blue sports drink.')
for unknown in ['Pick up Gatorade.','Pick up /World/Assets/CoffeeTable/UnknownItem.','Pick up unknown_asset_41.','请做一个未提供翻译的任务。']:
try:m.normalize_instruction(unknown)
except m.LanguageNormalizationError:check('unresolved_rejected:'+unknown,True)
else:check('unresolved_rejected:'+unknown,False)
check('known_prim_wrapper_resolved',m.normalize_instruction('Pick up /World/RoomEpisode/CakeYellow/Asset/Object.')=='Pick up yellow pastry.')
nested={'people':['No coffee for the children.',{'restriction':'Do not serve snacks containing peanuts.','age':[3,6]}],'goals':('Pick up gatorade_m.','Leave gatorade_t in place.'),'optional':None,'count':2}
out=m.normalize_context(nested)
check('nested_context_types_and_all_leaves_preserved',list(out)==list(nested) and out['people']==nested['people'] and out['optional'] is None and out['count']==2 and isinstance(out['goals'],tuple) and out['goals']==('Pick up orange sports drink.','Leave blue sports drink in place.'))
long_open=json.loads((P/'long_open_language.json').read_text())['episodes']
for r in long_open:
n=r['normalized_instruction']
if r['task_kind']=='open' and r.get('context_provenance')!='proposed_after_execution_not_original_user_intent':check('recorded_context_materialized:'+r['episode_id'],n.startswith('Context:\n') and '\n\nGoal:\n' in n)
if r.get('context_provenance')=='proposed_after_execution_not_original_user_intent':check('posthoc_context_provenance_only:'+r['episode_id'],r['training_context'] is None and r['source_delivered_posthoc_context']==r['source_context'] and bool(r['normalized_delivered_posthoc_context']) and not n.startswith('Context:'))
if r['source_id']=='tidy_coffee_table_v3':
src=r['source_instruction'].split('桌上有',1)[1].split(',把它们',1)[0]
expected=re.findall(r'\d+',src)
actual=re.findall(r'\d+',n.split('It has ',1)[1].split('.',1)[0])
check('quantities_preserved:'+r['episode_id'],expected==actual)
check('goals_and_protected_items_preserved:'+r['episode_id'],all(s in n for s in ['general waste bin','recycling bin','storage basket','drawer back','TV cabinet','unopened']) and 'drawer closed' not in n)
alltext='\n'.join(r['normalized_instruction'] for r in long_open)
check('guest_preferences_and_negation_preserved',all(s in alltext for s in ['ages 3 and 6','must not be served coffee or cola','cannot drink alcohol','do not serve any snacks containing peanuts','must be put out of view']))
E=json.loads((P/'episode_instruction_map.json').read_text())
for key,r in E.items():
if r['source_id']!='long_pack6_choose4':continue
n=m.normalize_instruction(r['source_instruction'],episode_id=key)
check('bag_archive_executed_object_list:'+key,all(o in n for o in r['executed_semantic_objects']) and len(r['executed_semantic_objects'])==4)
check('bag_request_authority_truthful:'+key,':requested_objects' not in ' '.join(r['evidence']) and ((r['preexecution_goal_authority_verified'] is True and r.get('original_input_long_job') and r.get('requested_objects')==r['executed_objects']) or (r['preexecution_goal_authority_verified'] is False and 'requested_objects' not in r)))
check('ten_bag_episode_specific_maps',sum(r['source_id']=='long_pack6_choose4' for r in E.values())==10)
try:m.normalize_instruction(next(iter(E.values()))['source_instruction'])
except m.LanguageNormalizationError:check('generic_bag_instruction_cannot_silently_drop_object_list',True)
else:check('generic_bag_instruction_cannot_silently_drop_object_list',False)
meal_path=P/'meal_diagnostic_language.json'
if meal_path.exists():
meal=json.loads(meal_path.read_text())['episodes']
check('ten_meal_current_language_records',len(meal)==10)
for r in meal:
check('meal_no_invented_context_or_oracle:'+r['episode_id'],r['source_context'] is None and r['training_context'] is None and r['current_instruction_origin']=='user_adopted_delivery_entry_scope' and r['historical_source_success_flag'] is False and r['current_task_scope_status']=='passed' and r['release_role']=='train_candidate' and not any(x in r['normalized_instruction'].lower() for x in ['cutlery','knife','fork','failed','successful']) and m.compose_training_instruction(r['source_instruction'],episode_id=r['episode_id'])==r['normalized_instruction'])
bench20_path=P/'bench20_ready5_language.json'
if bench20_path.exists():
rows=json.loads(bench20_path.read_text())['episodes']
check('five_current_l05_structured_requests',len(rows)==5)
for r in rows:
check('l05_preexecution_goal_without_route_or_oracle:'+r['episode_id'],r['preexecution_goal_authority_verified'] is True and r['original_episode_instruction_missing'] is True and r['is_exact_owner_natural_language_utterance'] is False and r['training_context'] is None and r['normalized_instruction']==r['source_instruction'] and r['normalized_instruction'].startswith('Find the ') and not any(s in r['normalized_instruction'] for s in ['sofa','kitchen','coffee table','not found','successful','failed']))
guest_probe=P/'CURRENT_REQUEST_GUEST10_AND_PACK_ROOTS.json'
if guest_probe.exists():
rows=json.loads(guest_probe.read_text())['guest']
check('guest_current_recipe_ten',len(rows)==10)
for r in rows:
check('guest_current_recipe_and_delivered_text_match:'+r['episode_id'],all(r.get(k) is True for k in ['recipe_matches_delivered_snapshot','context_matches_selected','instruction_matches_selected','situation_matches_selected']))
report={'schema':'robotagentbench.semantic_language_validation.v1','checks':len(checks),'passed':sum(c['passed'] for c in checks),'all_passed':all(c['passed'] for c in checks),'details':checks,'limitations':['Lexical and preservation checks do not approve physical quality or owner acceptance.','Episode-specific bag maps require the source episode_id; a missing identifier is rejected.','Post-hoc Serve Tidy contexts retain source context_provenance; language does not turn them into preregistered scenarios.']}
(P/'LANGUAGE_VALIDATION.json').write_text(json.dumps(report,ensure_ascii=False,indent=2)+'\n')
print(json.dumps({k:v for k,v in report.items() if k!='details'},ensure_ascii=False,indent=2))