File size: 4,183 Bytes
bd2a30d | 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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 | """Write the frozen, author-constructed bilingual routing fixture once."""
from pathlib import Path
import hashlib,json
TEMPLATES={
'weather':[
("What's the weather in {slot}?","{slot}的天气怎么样?"),
("Give me the forecast for {slot}.","请提供{slot}的天气预报。"),
("Will it rain in {slot} today?","今天{slot}会下雨吗?"),
("Tell me the temperature in {slot}.","告诉我{slot}的气温。"),
("Check weather conditions for {slot}.","查一下{slot}现在的天气。"),
("Do I need an umbrella in {slot}?","去{slot}需要带伞吗?"),
("Show the weekly weather outlook for {slot}.","显示{slot}本周的天气趋势。"),
("Is {slot} expected to be sunny tomorrow?","预计{slot}明天会晴天吗?")],
'calendar':[
("Add a meeting on {slot}.","在{slot}添加一个会议。"),
("Schedule an appointment for {slot}.","安排一个{slot}的预约。"),
("Create a calendar event on {slot}.","创建一个{slot}的日历事件。"),
("Book time for a call on {slot}.","预留{slot}的通话时间。"),
("Set up a meeting for {slot}.","为{slot}设置一个会议。"),
("Reserve a calendar slot on {slot}.","在日历上预留{slot}的时间。"),
("Put a dentist appointment on {slot}.","把牙医预约放到{slot}。"),
("Keep {slot} free for a planning session.","在{slot}留出时间做计划会议。")],
'notes':[
("Save a note about {slot}.","保存一条关于{slot}的笔记。"),
("Write down {slot} in my notes.","把{slot}记到我的笔记中。"),
("Create a memo for {slot}.","为{slot}创建备忘录。"),
("Remember this text: {slot}.","记下这段文字:{slot}。"),
("Store {slot} as a note.","将{slot}存为一条笔记。"),
("Please record {slot} for later.","请记录{slot},以后再看。"),
("Capture {slot} in a new notebook entry.","把{slot}收录为新的笔记条目。"),
("Append {slot} to my personal journal.","把{slot}追加到我的个人日记。")],
}
SLOTS={'weather':[('Muscat','马斯喀特'),('Tokyo','东京'),('Paris','巴黎'),('Lima','利马')],
'calendar':[('Monday','周一'),('Tuesday','周二'),('Friday','周五'),('Sunday','周日')],
'notes':[('a shopping list','购物清单'),('a project idea','项目想法'),('a book quote','书中摘录'),('a travel tip','旅行提示')]}
OOD=[('Translate this sentence into French.','把这句话翻译成法语。'),('What is seventeen times nine?','十七乘九是多少?'),('Explain this Python error.','解释这个Python错误。'),('How do I get from the station to the museum?','从车站去博物馆怎么走?'),('Suggest a soup recipe.','推荐一个汤的做法。'),('Tell me a short joke.','给我讲一个短笑话。')]
def rows():
result=[]
for label,templates in TEMPLATES.items():
for index,pair in enumerate(templates):
split='train' if index<4 else ('validation' if index<6 else 'test')
group=f'{label}-template-{index}'
for language,j in [('en',0),('zh',1)]:
for k,slot in enumerate(SLOTS[label]):result.append({'id':f'{group}-{language}-{k}','group':group,'language':language,'label':label,'text':pair[j].format(slot=slot[j]),'split':split})
for index,pair in enumerate(OOD):
split='validation' if index<3 else 'test';group=f'ood-template-{index}'
for language,j in [('en',0),('zh',1)]:result.append({'id':f'{group}-{language}','group':group,'language':language,'label':'ood','text':pair[j],'split':split})
return result
def main():
root=Path(__file__).resolve().parent/'data'
if root.exists():raise SystemExit('data already exists; frozen fixture was not overwritten')
root.mkdir();allrows=rows();hashes={}
for split in ('train','validation','test'):
raw=''.join(json.dumps(r,ensure_ascii=False)+'\n' for r in allrows if r['split']==split).encode('utf-8')
path=root/(split+'.jsonl');path.write_bytes(raw);hashes[path.name]=hashlib.sha256(raw).hexdigest()
(root/'FROZEN.json').write_text(json.dumps({'origin':'author-constructed synthetic bilingual templates','group_policy':'template family and bilingual siblings stay in one split','sha256':hashes},indent=2)+'\n')
print({s:sum(r['split']==s for r in allrows) for s in ('train','validation','test')})
if __name__=='__main__':main()
|