File size: 2,559 Bytes
0fe3281
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer, pipeline

def run_experiment(model_id):
    print(f"Loading model and tokenizer for {model_id}...")
    tokenizer = AutoTokenizer.from_pretrained(model_id)
    model = AutoModelForCausalLM.from_pretrained(
        model_id,
        torch_dtype=torch.bfloat16,
        device_map="auto"
    )
    
    pipe = pipeline(
        "text-generation",
        model=model,
        tokenizer=tokenizer
    )

    # Experiment Cases
    test_cases = [
        {
            "name": "Completion vs Instruction",
            "prompt": "Instruction: Tell me a short story about a robot who discovered coffee.\nStory:",
            "explanation": "Expected to see if it continues the 'Story:' or repeats the Instruction block."
        },
        {
            "name": "Logical Transitivity",
            "prompt": "If a cat is larger than a mouse, and a mouse is larger than an ant, then a cat is",
            "explanation": "Testing basic reasoning logic."
        },
        {
            "name": "Arithmetic Edge Case",
            "prompt": "Question: What is 123 multiplied by 456? Answer: ",
            "explanation": "Testing calculation ability for non-trivial numbers."
        },
        {
            "name": "Spatial Reasoning",
            "prompt": "There is a cup on the table. A book is on top of the cup. A pen is on top of the book. Where is the cup relative to the pen?",
            "explanation": "Testing awareness of spatial hierarchies."
        },
        {
            "name": "Niche Factuality",
            "prompt": "The capital of the fictional planet Xylophon is",
            "explanation": "Checking if it hallucinates a plausible-sounding name or stops."
        }
    ]

    print("\n--- Starting Experiments ---\n")
    for case in test_cases:
        print(f"Testing: {case['name']}")
        print(f"Prompt: {case['prompt']}")
        
        # We use a relatively low max_new_tokens for base model testing
        outputs = pipe(
            case['prompt'],
            max_new_tokens=50,
            do_sample=True,
            temperature=0.7,
            top_k=50,
            top_p=0.95
        )
        
        generated_text = outputs[0]['generated_text']
        print(f"Response: {generated_text}")
        print("-" * 30)

if __name__ == "__main__":
    # Using Falcon3-1B-Base as it fits the 6-month, 0.6B-6B parameter criteria
    run_experiment("tiiuae/Falcon3-1B-Base")