Spaces:
Sleeping

decision-model / scripts /prepare_short_curriculum.py
xstard's picture
Implement encoder-only bilingual decision API and demo
b6ae5c2 verified
Raw History Blame Contribute Delete
6.7 kB
"""AI-authored, explicitly labeled short requests; all variants stay train-only.
No API calls. Families group paraphrases, languages and tone variants together.
"""
from pathlib import Path
import shutil
from decision_model.data import Ticket,DecisionExample,to_examples,read_jsonl,write_jsonl
# group, department, explicit-refund, Ukrainian, English. Neutral base clauses
# contain the main request; five explicit prefixes determine the ordinal tone.
BASES=[
('refund-general','billing',True,'Верніть мені гроші, будь ласка.','Please give me my money back.'),
('refund-general','billing',True,'Поверніть, будь ласка, оплату за замовлення.','Please refund the payment for my order.'),
('refund-general','billing',True,'Хочу отримати назад сплачені кошти.','I want the money I paid returned to me.'),
('refund-general','billing',True,'Прошу відшкодувати вартість покупки.','Please reimburse the cost of my purchase.'),
('refund-overcharge','billing',True,'Поверніть мені зайве списання на картку.','Send the excess charge back to my card.'),
('refund-overcharge','billing',True,'З мене двічі списали оплату. Поверніть зайве.','You charged me twice. Please return the extra payment.'),
('refund-vs-repair','billing',True,'Не ремонтуйте товар, поверніть гроші за нього.','Do not repair the product; give me a refund for it.'),
('refund-service','billing',True,'Прошу повернути кошти за ненадану послугу.','Please refund the service that was never provided.'),
('refund-status','billing',False,'Чи вже оброблено мій запит на повернення коштів?','Has my existing refund request been processed yet?'),
('refund-status','billing',False,'Мені потрібен статус повернення, а не нова заявка.','I need the refund status, not a new refund request.'),
('invoice-explanation','billing',False,'Я не прошу повертати кошти. Поясніть суму рахунку.','I am not asking for a refund. Explain the invoice amount.'),
('refund-policy','billing',False,'Які у вас правила повернення коштів?','What is your refund policy?'),
('export-fix','technical',False,'Я не прошу повернення коштів, виправте помилку експорту.','I am not asking for a refund; fix the broken export.'),
('application-fix','technical',False,'Не повертайте гроші. Потрібно полагодити застосунок.','Do not refund me. I need the application repaired.'),
('login-fix','technical',False,'Верніть не гроші, а можливість увійти в обліковий запис.','Restore my login access, not my money.'),
('report-fix','technical',False,'Застосунок завершує роботу, коли відкриваю звіт. Виправте це.','The app crashes when I open a report. Please fix it.'),
('login-fix','technical',False,'Посилання входу видає помилку. Допоможіть її усунути.','The login link returns an error. Please fix it.'),
('data-restore','technical',False,'Я не хочу грошей назад. Відновіть файли після збою.','I do not want my money back. Restore my files after the crash.'),
('device-fix','technical',False,'Товар не вмикається. Допоможіть його полагодити.','The device will not turn on. Help me repair it.'),
('save-fix','technical',False,'Програма зависає під час збереження. Потрібне виправлення.','The program freezes when saving. I need a fix.'),
('plan-pricing','sales',False,'Підкажіть ціну нової річної підписки.','What is the price of a new annual subscription?'),
('plan-pricing','sales',False,'Я не прошу повернення. Хочу придбати новий тариф.','I do not want a refund. I want to buy a new plan.'),
('license-pricing','sales',False,'Скільки коштують ще десять ліцензій?','How much do ten additional licenses cost?'),
('plan-pricing','sales',False,'Надішліть пропозицію на корпоративний пакет.','Send me a quote for the enterprise package.'),
('parcel-tracking','other',False,'Де зараз моя посилка?','Where is my parcel now?'),
('support-hours','other',False,'Підкажіть години роботи підтримки.','What are your support opening hours?'),
('profile-update','other',False,'Допоможіть змінити номер телефону в моєму профілі.','Help me change the phone number in my profile.'),
('complaint-procedure','other',False,'Як подати скаргу на якість обслуговування?','How do I file a complaint about service quality?'),
]
PREFIXES={
'uk':['','Я трохи незадоволений. ','Це мене дратує. ','Я в люті! ','Ви шахраї! '],
'en':['','I am slightly dissatisfied. ','This is frustrating. ','I am furious! ','You are scammers! '],
}
tickets=[]
for i,(group,department,refund,uk,en) in enumerate(BASES):
for level in range(5):
for lang,base in [('uk',uk),('en',en)]:
prefix=PREFIXES[lang][level]
if level==4 and i%2:
prefix=('Негайно зробіть це, інакше піду до конкурентів! ' if lang=='uk'
else 'Do this now or I will switch to your competitors! ')
tickets.append(Ticket(id=f'short-{i}-{level}:{lang}',group_id='short-authored-'+group,language=lang,
text=prefix+base,department=department,wants_refund=refund,frustration=level,
source='AI-authored short contrast curriculum, 2026-11-24',license='MIT',reviewed=True,
reviewer='Codex compositional rubric review (AI), 2026-11-24'))
out=Path('data/v2-short');out.mkdir(exist_ok=True)
write_jsonl(out/'short-tickets.jsonl',tickets)
original=read_jsonl('data/v2/train.jsonl',DecisionExample)
write_jsonl(out/'train.jsonl',original+[row for t in tickets for row in to_examples(t,augment=True)])
for name in ['validation','calibration']:
shutil.copyfile(f'data/v2/{name}.jsonl',out/f'{name}.jsonl')
print({'short_tickets':len(tickets),'authored_families':len({t.group_id for t in tickets}),
'total_training_questions':len(original)+len(tickets)*9,'test':'absent, never read'})