TensorGreed commited on
Commit
ed500a3
·
verified ·
1 Parent(s): 802dd8f

Qwen2.5-1.5B passage reader for IRS Publication 17 (2025), trained with BrewSLM (run #162, seed 44)

Browse files
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ tokenizer.json filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,155 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ base_model: Qwen/Qwen2.5-1.5B-Instruct
4
+ language:
5
+ - en
6
+ pipeline_tag: text-generation
7
+ library_name: transformers
8
+ tags:
9
+ - retrieval-augmented-generation
10
+ - question-answering
11
+ - lora
12
+ - merged
13
+ - brewslm
14
+ ---
15
+
16
+ # Qwen2.5-1.5B passage reader for IRS Publication 17 (2025)
17
+
18
+ This is `Qwen/Qwen2.5-1.5B-Instruct`, fine-tuned with LoRA (merged into the weights) to answer questions about
19
+ IRS Publication 17 (*Your Federal Income Tax*, 2025) **from passages you retrieve and put in the prompt**.
20
+ It cites the passages it used (`[1]`, `[2]`, …), and says it doesn't know when they don't hold the answer.
21
+
22
+ > **For education only.** This model is a demonstration of a training method. It is not a tax expert, and it makes no
23
+ > claim to subject-matter expertise. It is not tax, legal or financial advice. It can be wrong, even when it cites a
24
+ > passage. Don't rely on it for any real tax decision: read the publication itself, or ask a qualified professional.
25
+
26
+ It is a reader, not a knowledge base: without passages it scores 0.18 on its own test set. Use it behind a retriever
27
+ over Publication 17. It knows nothing about other years, other publications or your situation.
28
+
29
+ **Trained with [BrewSLM](https://brewslm.com)**, a platform for building small language models from your own
30
+ documents. Every step below (data generation, filtering, training, evaluation, packaging) ran through it. The story
31
+ behind this model:
32
+ [*IRS Publication 17: the fine-tune lost, retrieval won*](https://brewslm.com/blog-irs-pub17-fine-tune-lost-retrieval-won.html)
33
+ (the first attempt), and more on the [BrewSLM blog](https://brewslm.com/blog.html). Non-commercial showcase; no warranty.
34
+
35
+ ## Result
36
+
37
+ 157 held-out test questions, scored by a local judge model (`gemma4:12b`) as correct / partial / wrong against an
38
+ answer key (score = correct + ½ partial, averaged). Every arm gets the same retrieval: top-3, 600-character passages,
39
+ no reranker.
40
+
41
+ | | Test score (correct / partial / wrong) |
42
+ |---|---|
43
+ | Base Qwen2.5-1.5B-Instruct + passages (the bar) | 0.570 (82 / 15 / 60) |
44
+ | **This model + passages** | **0.688 (100 / 16 / 41)** |
45
+ | This model, no passages | 0.185 |
46
+ | Base, no passages | 0.073 |
47
+
48
+ Compared row by row with the bar on the same 157 questions, this model is better on 32, worse on 12 and the same on 113:
49
+ +0.118, 95% CI +0.054 to +0.182.
50
+
51
+ **How much to trust that number:**
52
+
53
+ - **The pass rule was written before any model was scored.** The test and validation sets were frozen and
54
+ checksummed first. Three seeds were trained on identical data. The seed with the best *validation* score is
55
+ published here (this one, seed 44). The rule required it to beat the bar with a CI lower bound above 0, and at
56
+ least 2 of the 3 seeds to beat the bar too.
57
+ - **All three seeds beat the bar, but by different margins.**
58
+
59
+ | Seed | Test score | Paired difference vs bar (95% CI) | Validation score |
60
+ |---|---|---|---|
61
+ | 42 | 0.637 | +0.067 (+0.003 to +0.131) | 0.710 |
62
+ | 43 | 0.659 | +0.089 (+0.026 to +0.152) | 0.704 |
63
+ | **44 (this model)** | **0.688** | **+0.118 (+0.054 to +0.182)** | **0.723** |
64
+
65
+ Averaged over the three seeds, the gain is +0.091 (CI +0.028 to +0.155). Seed 42 only just cleared the bar. The
66
+ spread between seeds is about as large as the weakest seed's gain, so expect roughly +0.07 to +0.12, not exactly
67
+ +0.118.
68
+ - **What the claim covers:** this model reads retrieved Publication 17 passages better than its base model does, on
69
+ questions written by the same model family that wrote its training data (see below). It says nothing about general
70
+ tax competence, or how it does on questions written by people.
71
+ - **Retrieval is the ceiling.** The retriever found the right passage for 123 of the 157 test questions, the same
72
+ for every arm. 28 of this model's 41 wrong answers are questions where the passage wasn't retrieved.
73
+ - **The judge is one model.** `gemma4:12b` judged everything and also filtered the training answers (below), so its
74
+ preferences are built into both the data and the score.
75
+
76
+ ## How the data was made
77
+
78
+ Everything was generated locally with open-weight models served by Ollama. No cloud model was used at any step,
79
+ including the test and validation sets.
80
+
81
+ - **Source:** IRS Publication 17 (2025) PDF, cleaned (page headers and footers removed) and split into 1,064 passages.
82
+ - **Questions and reference answers:** `gpt-oss:120b` wrote 3 question / answer pairs per passage (3,187 pairs). Questions
83
+ that pointed at "the passage" instead of standing alone were rewritten or dropped (60 rewritten, 9 stripped).
84
+ - **Test and validation sets:** 157 questions each, written by `gpt-oss:120b`. Each answer had to be quotable from its
85
+ source passage. No question is shared between train, validation and test, and test and validation share no source
86
+ passage.
87
+ - **Training answers:** for each training question, `gpt-oss:120b` answered from the same top-3 retrieved passages the
88
+ model sees at inference time. That is why the targets cite passages and sometimes say "I don't know" (272 answers do).
89
+ - **Filter:** `gemma4:12b` graded every training answer against its reference answer. Only answers graded **correct**
90
+ were kept. Partial answers were dropped as well as wrong ones.
91
+ - **Critique and revise:** each answer the filter dropped got one revision round. `gpt-oss:120b` critiqued it, the same
92
+ model rewrote it, and `gemma4:12b` re-graded the rewrite and had the final say. Of 628 dropped answers, 242 were fixed
93
+ and kept. The other 386 stayed out: 317 were still graded partial or wrong, and 69 revisions became "I don't know"
94
+ answers. **Some training answers are therefore revisions written under critique by `gpt-oss:120b`, not first drafts.**
95
+ - **Training set:** 2,779 passage-prompt rows (question + 3 retrieved passages → teacher answer), seed 44.
96
+
97
+ ## Training
98
+
99
+ LoRA r 16, alpha 32, dropout 0.05, on all attention and MLP projections. bf16, AdamW, learning rate 2e-4 decaying
100
+ to 0, effective batch 16, loss on the answer tokens only, max sequence length 2048 (the longest row is 1,919 tokens).
101
+ 2 epochs, 348 steps, final train loss 0.446, eval loss 0.531. Trained on one NVIDIA GB10. The adapter was merged into
102
+ the base weights in fp32.
103
+
104
+ ## Prompt format
105
+
106
+ The model was trained on Qwen's chat template. The **system message** holds the numbered passages and the instruction,
107
+ and the **user message** is the question. Keep this layout; other layouts were never trained or tested.
108
+
109
+ ```
110
+ Passages from this project's documents:
111
+ [1] (p17-2025.pdf · passage 386) <passage text>
112
+
113
+ [2] (p17-2025.pdf · passage 211) <passage text>
114
+
115
+ [3] (p17-2025.pdf · passage 115) <passage text>
116
+ Answer the user's next question using only these passages and cite the passage numbers you used, like [1]. If the passages don't contain the answer, say you don't know.
117
+ ```
118
+
119
+ ```python
120
+ from transformers import AutoModelForCausalLM, AutoTokenizer
121
+ import torch
122
+
123
+ repo = "TensorGreed/brewslm-pub17-passage-reader"
124
+ tok = AutoTokenizer.from_pretrained(repo)
125
+ model = AutoModelForCausalLM.from_pretrained(repo, torch_dtype=torch.bfloat16, device_map="auto")
126
+
127
+ passages = ["...", "...", "..."] # top-3 retrieved Publication 17 passages, ~600 characters each
128
+ system = "Passages from this project's documents:\n" + "\n\n".join(
129
+ f"[{i}] (p17-2025.pdf · passage {i}) {p}" for i, p in enumerate(passages, 1)
130
+ ) + ("\nAnswer the user's next question using only these passages and cite the passage numbers you used, "
131
+ "like [1]. If the passages don't contain the answer, say you don't know.")
132
+ messages = [{"role": "system", "content": system},
133
+ {"role": "user", "content": "Who must file a 2025 return?"}]
134
+ inputs = tok.apply_chat_template(messages, add_generation_prompt=True, return_tensors="pt").to(model.device)
135
+ out = model.generate(inputs, max_new_tokens=256, do_sample=False)
136
+ print(tok.decode(out[0, inputs.shape[1]:], skip_special_tokens=True))
137
+ ```
138
+
139
+ ## Limitations
140
+
141
+ - Trained and tested on one document. Publication 17 for 2025 only; tax rules change every year.
142
+ - Training and test questions come from the same generator (`gpt-oss:120b`), so the test measures in-distribution
143
+ reading, not robustness to how people phrase things.
144
+ - It can still misread a passage that holds the answer: 13 of its 41 wrong test answers.
145
+ - Educational demonstration only, with no claim to tax expertise. Not tax, legal or financial advice. Check answers
146
+ against the publication itself, or ask a qualified professional.
147
+
148
+ ## Citation
149
+
150
+ Trained and evaluated with [BrewSLM](https://brewslm.com) ([blog](https://brewslm.com/blog.html)). If you reuse the
151
+ method, a link back is appreciated.
152
+
153
+ ## License
154
+
155
+ Apache 2.0, the base model's license. IRS Publication 17 is a work of the U.S. government and in the public domain.
chat_template.jinja ADDED
@@ -0,0 +1,54 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {%- if tools %}
2
+ {{- '<|im_start|>system\n' }}
3
+ {%- if messages[0]['role'] == 'system' %}
4
+ {{- messages[0]['content'] }}
5
+ {%- else %}
6
+ {{- 'You are Qwen, created by Alibaba Cloud. You are a helpful assistant.' }}
7
+ {%- endif %}
8
+ {{- "\n\n# Tools\n\nYou may call one or more functions to assist with the user query.\n\nYou are provided with function signatures within <tools></tools> XML tags:\n<tools>" }}
9
+ {%- for tool in tools %}
10
+ {{- "\n" }}
11
+ {{- tool | tojson }}
12
+ {%- endfor %}
13
+ {{- "\n</tools>\n\nFor each function call, return a json object with function name and arguments within <tool_call></tool_call> XML tags:\n<tool_call>\n{\"name\": <function-name>, \"arguments\": <args-json-object>}\n</tool_call><|im_end|>\n" }}
14
+ {%- else %}
15
+ {%- if messages[0]['role'] == 'system' %}
16
+ {{- '<|im_start|>system\n' + messages[0]['content'] + '<|im_end|>\n' }}
17
+ {%- else %}
18
+ {{- '<|im_start|>system\nYou are Qwen, created by Alibaba Cloud. You are a helpful assistant.<|im_end|>\n' }}
19
+ {%- endif %}
20
+ {%- endif %}
21
+ {%- for message in messages %}
22
+ {%- if (message.role == "user") or (message.role == "system" and not loop.first) or (message.role == "assistant" and not message.tool_calls) %}
23
+ {{- '<|im_start|>' + message.role + '\n' + message.content + '<|im_end|>' + '\n' }}
24
+ {%- elif message.role == "assistant" %}
25
+ {{- '<|im_start|>' + message.role }}
26
+ {%- if message.content %}
27
+ {{- '\n' + message.content }}
28
+ {%- endif %}
29
+ {%- for tool_call in message.tool_calls %}
30
+ {%- if tool_call.function is defined %}
31
+ {%- set tool_call = tool_call.function %}
32
+ {%- endif %}
33
+ {{- '\n<tool_call>\n{"name": "' }}
34
+ {{- tool_call.name }}
35
+ {{- '", "arguments": ' }}
36
+ {{- tool_call.arguments | tojson }}
37
+ {{- '}\n</tool_call>' }}
38
+ {%- endfor %}
39
+ {{- '<|im_end|>\n' }}
40
+ {%- elif message.role == "tool" %}
41
+ {%- if (loop.index0 == 0) or (messages[loop.index0 - 1].role != "tool") %}
42
+ {{- '<|im_start|>user' }}
43
+ {%- endif %}
44
+ {{- '\n<tool_response>\n' }}
45
+ {{- message.content }}
46
+ {{- '\n</tool_response>' }}
47
+ {%- if loop.last or (messages[loop.index0 + 1].role != "tool") %}
48
+ {{- '<|im_end|>\n' }}
49
+ {%- endif %}
50
+ {%- endif %}
51
+ {%- endfor %}
52
+ {%- if add_generation_prompt %}
53
+ {{- '<|im_start|>assistant\n' }}
54
+ {%- endif %}
config.json ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "Qwen2ForCausalLM"
4
+ ],
5
+ "attention_dropout": 0.0,
6
+ "bos_token_id": 151643,
7
+ "dtype": "bfloat16",
8
+ "eos_token_id": 151645,
9
+ "hidden_act": "silu",
10
+ "hidden_size": 1536,
11
+ "initializer_range": 0.02,
12
+ "intermediate_size": 8960,
13
+ "layer_types": [
14
+ "full_attention",
15
+ "full_attention",
16
+ "full_attention",
17
+ "full_attention",
18
+ "full_attention",
19
+ "full_attention",
20
+ "full_attention",
21
+ "full_attention",
22
+ "full_attention",
23
+ "full_attention",
24
+ "full_attention",
25
+ "full_attention",
26
+ "full_attention",
27
+ "full_attention",
28
+ "full_attention",
29
+ "full_attention",
30
+ "full_attention",
31
+ "full_attention",
32
+ "full_attention",
33
+ "full_attention",
34
+ "full_attention",
35
+ "full_attention",
36
+ "full_attention",
37
+ "full_attention",
38
+ "full_attention",
39
+ "full_attention",
40
+ "full_attention",
41
+ "full_attention"
42
+ ],
43
+ "max_position_embeddings": 32768,
44
+ "max_window_layers": 21,
45
+ "model_type": "qwen2",
46
+ "num_attention_heads": 12,
47
+ "num_hidden_layers": 28,
48
+ "num_key_value_heads": 2,
49
+ "pad_token_id": null,
50
+ "rms_norm_eps": 1e-06,
51
+ "rope_parameters": {
52
+ "rope_theta": 1000000.0,
53
+ "rope_type": "default"
54
+ },
55
+ "sliding_window": null,
56
+ "tie_word_embeddings": true,
57
+ "transformers_version": "5.2.0",
58
+ "use_cache": true,
59
+ "use_sliding_window": false,
60
+ "vocab_size": 151936
61
+ }
generation_config.json ADDED
@@ -0,0 +1,14 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "bos_token_id": 151643,
3
+ "do_sample": true,
4
+ "eos_token_id": [
5
+ 151645,
6
+ 151643
7
+ ],
8
+ "pad_token_id": 151643,
9
+ "repetition_penalty": 1.1,
10
+ "temperature": 0.7,
11
+ "top_k": 20,
12
+ "top_p": 0.8,
13
+ "transformers_version": "5.2.0"
14
+ }
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:2b91f1a5fd13998df1b023405db3e7bc0d61b9ddd0d7c6d944d9bcc1e891b686
3
+ size 3087467144
tokenizer.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3fd169731d2cbde95e10bf356d66d5997fd885dd8dbb6fb4684da3f23b2585d8
3
+ size 11421892
tokenizer_config.json ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "add_prefix_space": false,
3
+ "backend": "tokenizers",
4
+ "bos_token": null,
5
+ "clean_up_tokenization_spaces": false,
6
+ "eos_token": "<|im_end|>",
7
+ "errors": "replace",
8
+ "extra_special_tokens": [
9
+ "<|im_start|>",
10
+ "<|im_end|>",
11
+ "<|object_ref_start|>",
12
+ "<|object_ref_end|>",
13
+ "<|box_start|>",
14
+ "<|box_end|>",
15
+ "<|quad_start|>",
16
+ "<|quad_end|>",
17
+ "<|vision_start|>",
18
+ "<|vision_end|>",
19
+ "<|vision_pad|>",
20
+ "<|image_pad|>",
21
+ "<|video_pad|>"
22
+ ],
23
+ "is_local": true,
24
+ "model_max_length": 131072,
25
+ "pad_token": "<|endoftext|>",
26
+ "split_special_tokens": false,
27
+ "tokenizer_class": "Qwen2Tokenizer",
28
+ "unk_token": null
29
+ }