File size: 2,355 Bytes
52286fa
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
71
72
73
74
---
base_model: HuggingFaceTB/SmolLM2-135M
library_name: transformers
license: apache-2.0
language:
- en
pipeline_tag: text-generation
tags:
- course-assignment
- sft
---

# My first trained model -> SmolLM2-135M fine-tuned for grounded FAQ answers

The model reads a supplied fictional campus fact and answers in exactly two lines:

```text
Answer: <answer>
Source: <fact ID>
```

## Training

Single run of the provided trainer, `python train.py --steps 100 --output checkpoint`.
Full settings in `run_config.json`, per-update loss in `loss.csv`.

| Setting | Value |
| --- | --- |
| Base model | `HuggingFaceTB/SmolLM2-135M` |
| Hardware | NVIDIA GeForce RTX 4090 D |
| Updates | 100 (8 one-conversation micro-batches each) |
| Training conversations | 300 |
| Sequence length | 256 |
| Optimizer | AdamW, learning rate 2e-5, gradient clipping 1.0 |
| Loss | Conversation-balanced label smoothing, ε = 0.1, final assistant response only |
| Seed | 4221 |

Training loss: 3.204 (update 1) → 1.456 (update 100).

## Evaluation

20 held-out prompt framings, greedy decoding, 96-new-token cap.

| Model | Format pass | Grounded-format pass |
| --- | ---: | ---: |
| Base `SmolLM2-135M` | 0 / 20 | 0 / 20 |
| This checkpoint | 20 / 20 | 20 / 20 |

## Usage

The prompt format matches `encode_messages` in the assignment code: each message is
`Role:\n<content>`, non-assistant messages end with `\n`, and the prompt ends with
`Assistant:\n`.

```python
from transformers import AutoModelForCausalLM, AutoTokenizer

repo = "<centenohugo>/SFTChatBot-comp4221"
tokenizer = AutoTokenizer.from_pretrained(repo)
model = AutoModelForCausalLM.from_pretrained(repo)

prompt = (
    "System:\nUse the supplied fictional campus fact. Reply exactly two lines: Answer: "
    "followed by the answer, then Source: followed by its fact ID. Do not add any other text.\n"
    "User:\nFact [F001]: What is the booking limit for study room S01? 2 hours per booking.\n"
    "Question: What is the booking limit for study room S01?\n"
    "Assistant:\n"
)
ids = tokenizer(prompt, return_tensors="pt", add_special_tokens=False)
out = model.generate(**ids, max_new_tokens=96, do_sample=False,
                     eos_token_id=tokenizer.eos_token_id, pad_token_id=tokenizer.eos_token_id)
print(tokenizer.decode(out[0, ids["input_ids"].shape[1]:], skip_special_tokens=True))
```