fengshore04's picture
Upload folder using huggingface_hub
832f0f6 verified
Raw History Blame Contribute Delete
1.72 kB
"""Shared dataset paths, task identities, and JSON output."""
import hashlib
import json
import os
from pathlib import Path
import tempfile
ROOT = Path(__file__).resolve().parents[1]
CATEGORIES = {
'VSS': {'comparative_selection', 'npc_search'},
'IGC': {'deliver_report', 'dialogue_handoff', 'distributed_information'},
'IRA': {'conditional_instruction', 'instruction_revision'},
'MST': {'spatial_memory_return', 'state_tracking'},
'SARE': {'constraint_route', 'door_traversal', 'multi_stage_route'},
}
def read(path):
return json.loads(Path(path).read_text(encoding='utf-8'))
def digest(path):
return hashlib.sha256(Path(path).read_bytes()).hexdigest()
def write(path, value):
path = Path(path)
path.parent.mkdir(parents=True, exist_ok=True)
fd, name = tempfile.mkstemp(prefix='.' + path.name, dir=path.parent)
try:
with os.fdopen(fd, 'w', encoding='utf-8') as stream:
json.dump(value, stream, ensure_ascii=False, indent=2, allow_nan=False)
stream.write('\n')
os.replace(name, path)
finally:
if os.path.exists(name):
os.unlink(name)
def definitions():
return {p.stem: read(p) for p in sorted((ROOT / 'subtasks').glob('*.json'))}
def canonical_id(value):
if not isinstance(value, str):
raise ValueError('Missing task ID')
aliases = read(ROOT / 'eval/task_aliases.json')
value = aliases.get(value, value)
if not (ROOT / 'data' / (value + '.json')).is_file() or Path(value).name != value:
raise ValueError('Unrecognized task ID: ' + value)
return value
def category(task_type):
return next(key for key, types in CATEGORIES.items() if task_type in types)