File size: 2,150 Bytes
bcda557 | 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 | import random, json
random.seed(42)
def make_example():
t=random.choice(['add','subtract','multiply','compare','sequence','logic'])
if t=='add':
a,b=random.randint(1,99),random.randint(1,99); c=a+b
return {'question':f'What is {a} plus {b}?','answer':f'{a} plus {b} equals {c}. The answer is {c}.'}
if t=='subtract':
a,b=random.randint(1,99),random.randint(1,a if False else 99)
if b>a:a,b=b,a
c=a-b
return {'question':f'What is {a} minus {b}?','answer':f'Subtract {b} from {a}. The answer is {c}.'}
if t=='multiply':
a,b=random.randint(2,12),random.randint(2,12); c=a*b
return {'question':f'What is {a} times {b}?','answer':f'Multiply {a} by {b}. The answer is {c}.'}
if t=='compare':
a,b=random.randint(1,100),random.randint(1,100)
larger=max(a,b)
return {'question':f'Which number is larger, {a} or {b}?','answer':f'Compare {a} and {b}. {larger} is larger.'}
if t=='sequence':
start=random.randint(0,30); step=random.randint(1,10); seq=[start+i*step for i in range(4)]; nxt=seq[-1]+step
return {'question':f'Find the next number in this sequence: {seq[0]}, {seq[1]}, {seq[2]}, {seq[3]}.','answer':f'The sequence increases by {step} each time. The next number is {nxt}.'}
# simple valid deductive patterns
animal=random.choice(['cats','birds','robots','students','flowers']); category=random.choice(['mammals','living things','machines','objects'])
if animal=='cats': category='mammals'
if animal=='birds': category='animals'
if animal=='robots': category='machines'
if animal=='students': category='people'
if animal=='flowers': category='plants'
return {'question':f'All {animal} are {category}. A thing is a {animal}. What can we conclude?','answer':f'All {animal} belong to the group {category}. Therefore, the thing is a {category}.'}
if __name__=='__main__':
with open('dataset.jsonl','w',encoding='utf8') as f:
for _ in range(12000): f.write(json.dumps(make_example(),ensure_ascii=False)+'\n')
print('Created 12,000 original synthetic examples in dataset.jsonl')
|