File size: 2,218 Bytes
bf8fbca
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
65
66
67
68
69
70
#!/usr/bin/env python3
"""
Augment reasoning data with additional examples.
"""
import json
import random
import sys
from pathlib import Path


def generate_examples(num_samples: int = 100):
    """Generate synthetic reasoning examples."""
   operators = [
        ("+", lambda a, b: a + b, "add"),
        ("-", lambda a, b: a - b, "subtract"),
        ("Γ—", lambda a, b: a * b, "multiply"),
    ]
    
    examples = []
    for i in range(num_samples):
        op_func, op_name = random.choice(operators)
        a = random.randint(1, 100)
        b = random.randint(1, 20)
        result = op_func(a, b)
        
        example = {
            "id": f"reasoning_{i+100:03d}",
            "problem": f"What is {a} {op_name} {b}?",
            "steps": [
                {"step": 1, "description": f"Apply {op_name}", "result": str(result)},
                {"step": 2, "description": "Verify", "result": "βœ“"},
                {"step": 3, "description": "Final answer", "result": str(result)},
            ],
            "final_answer": str(result),
        }
        examples.append(example)
    
    return examples


def augment_data(input_file: str, output_file: str, num_new: int = 100):
    """Augment existing data with new examples."""
    input_path = Path(input_file)
    
    # Read existing
    existing = []
    if input_path.exists():
        with open(input_path) as f:
            for line in f:
                existing.append(json.loads(line))
    
    # Generate new
    new_examples = generate_examples(num_new)
    
    # Write combined
    output_path = Path(output_file)
    output_path.parent.mkdir(parents=True, exist_ok=True)
    
    with open(output_path, "w") as f:
        for item in existing + new_examples:
            f.write(json.dumps(item, ensure_ascii=False) + "\n")
    
    print(f"Saved {len(existing) + len(new_examples)} examples to {output_file}")


if __name__ == "__main__":
    input_file = sys.argv[1] if len(sys.argv) > 1 else "data/brain/reasoning_steps.jsonl"
    output_file = sys.argv[2] if len(sys.argv) > 2 else "data/brain/reasoning_steps.jsonl"
    num_new = int(sys.argv[3]) if len(sys.argv) > 3 else 100
    augment_data(input_file, output_file, num_new)