somasekhar-dev commited on
Commit
66b9bb5
Β·
verified Β·
1 Parent(s): 9fe597e

sep18_round2: 5-tool schema-conditioned redesign, verified 50-test head-to-head (Action-correct 68%->86%, Args-exact 68.6%->91.4% vs previous checkpoint)

Browse files
Files changed (2) hide show
  1. README.md +109 -70
  2. model.safetensors +1 -1
README.md CHANGED
@@ -17,46 +17,67 @@ tags:
17
 
18
  A 272.7M-parameter Hindi-English model fine-tuned into a **small action
19
  model** for banking/NBFC customer service: given a user utterance
20
- (English, Hindi, Hinglish, or Hindi-English code-mixed), it decides which
21
- of 41 predefined banking actions (if any) to invoke and extracts the
22
- arguments β€” it does not try to be a general chatbot or answer open-domain
23
- questions as its primary job.
24
 
25
- This checkpoint (`gc_v2`) is the current best available candidate, not a
26
- final version β€” see **Status and limitations** below. This repository
27
- will be updated in place as the model improves; the link will stay the
28
- same across updates.
29
 
30
  ## What it does
31
 
32
  ```
33
- User: Mera outstanding loan amount kitna hai?
34
- Assistant: {"tool": "get_loan_balance", "arguments": {"loan_type": "personal"}}
 
 
 
 
 
 
 
 
 
 
 
 
 
35
 
36
- User: Block my card ending 7788, it was stolen
37
- Assistant: {"tool": "block_card", "arguments": {"card_last4": "7788", "reason": "stolen"}}
 
 
 
 
38
 
39
- User: What if I closed my personal loan early?
40
- Assistant: {"tool": null}
41
- ```
 
 
42
 
43
- It also handles **multi-turn slot-filling** (asking a clarifying question
44
- when a required argument is missing, then resolving the tool call from
45
- the follow-up answer) and is trained to **not** fire an action on
46
- hypothetical, past-tense, or third-person framings of a request.
 
 
 
47
 
48
- The tool schema (41 tools across 9 categories: account info, loans,
49
- transactions, payments/EMI, profile/KYC, cards, disputes, service
50
- requests, loan lifecycle) is not passed in-context β€” the model was
51
- trained via supervised fine-tuning directly on `(utterance β†’ tool call)`
52
- pairs, not schema-conditioned generation. It does not need a system
53
- prompt listing the tools.
 
 
54
 
55
  ## Architecture
56
 
57
- Same base architecture as `somasekhar-dev/NextToken-model-1`, pretrained
58
- separately on Hindi + English only, then fully fine-tuned (not LoRA) for
59
- tool-calling:
60
 
61
  | | |
62
  |---|---|
@@ -64,11 +85,18 @@ tool-calling:
64
  | Attention | GQA β€” 16 query heads, 4 KV heads |
65
  | Normalization | RMSNorm + per-head QK-norm |
66
  | FFN | SwiGLU |
67
- | Context length | 2048 (training examples are short, well under this) |
68
  | Tokenizer | [`sarvamai/sarvam-1`](https://huggingface.co/sarvamai/sarvam-1), vocab 68,096 |
69
 
70
  ## Usage
71
 
 
 
 
 
 
 
 
72
  ```python
73
  from transformers import AutoModelForCausalLM, AutoTokenizer
74
  import torch
@@ -76,55 +104,66 @@ import torch
76
  model = AutoModelForCausalLM.from_pretrained("somasekhar-dev/NextToken-model-2")
77
  tokenizer = AutoTokenizer.from_pretrained("somasekhar-dev/NextToken-model-2")
78
 
79
- prompt = "User: Mera outstanding loan amount kitna hai?\nAssistant: "
80
- ids = tokenizer(prompt, return_tensors="pt", add_special_tokens=False).input_ids
81
- out = model.generate(ids, max_new_tokens=60, do_sample=False,
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
82
  eos_token_id=tokenizer.eos_token_id, pad_token_id=tokenizer.pad_token_id)
83
- print(tokenizer.decode(out[0, ids.shape[1]:], skip_special_tokens=True))
 
84
  ```
85
 
86
- **Prompt format matters for correctness**: examples were tokenized with
87
- each `User:`/`Assistant:` segment encoded separately and concatenated
88
- (not the merged string re-tokenized as one call) β€” a real train/inference
89
- mismatch was found and fixed during development. Building the prompt as a
90
- plain Python f-string and tokenizing it in one call (as in the example
91
- above) works correctly for a fresh single-turn prompt; if you're
92
- extending this into a real multi-turn application, replicate the
93
- segment-wise tokenization convention rather than concatenating raw
94
- strings across turns.
95
-
96
  ## Training
97
 
98
- Full fine-tune (not LoRA) off a Hindi-English pretrained base, using
99
- synthetically generated data (teacher model: a self-hosted Gemma-4-12B).
100
- ~8,600 training examples across banking tool-calling (positive, negative,
101
- and multi-turn examples) plus a general-capability slice (~1,900
102
- examples: continuation, QA, summarization, instruction-following) added
103
- specifically to reduce a failure mode where the model tried to invoke a
104
- banking tool on prompts unrelated to banking.
 
105
 
106
  ## Status and limitations
107
 
108
- Being upfront about what's actually verified vs. still weak, rather than
109
- overstating readiness:
110
-
111
- - **Negative-suppression is inconsistent** for past-tense ("I already
112
- updated my address...") and third-person ("can someone else...")
113
- phrasings β€” sometimes correctly refuses to act, sometimes doesn't.
114
- Hypothetical framings ("what if I closed my loan early") are refused
115
- reliably.
116
- - **Free-text argument values are unreliable** β€” e.g. asked to update an
117
- email address, the model sometimes generates a plausible-looking but
118
- wrong value instead of copying the literal string from the utterance.
119
- - **General-capability handling is improved but not fully robust** β€” the
120
- model used to fire a banking tool on any prompt at all (including
121
- "continue this story..."); that's now mostly fixed, but content
122
- quality on genuinely non-banking prompts (general knowledge, open-ended
123
- writing) is still weak, and the fix isn't 100% reliable.
 
 
124
  - **Any state-changing action should be confirmed before executing**,
125
- not trusted blindly from a single model output β€” this applies
126
- regardless of the two points above, since no model this size will ever
127
- be perfectly reliable at intent-suppression for financial actions.
128
  - Conversion to this `Qwen3ForCausalLM` checkpoint was verified
129
  numerically (100% argmax agreement vs. the original training-format
130
- checkpoint on random inputs, plus a full save/reload round-trip).
 
 
17
 
18
  A 272.7M-parameter Hindi-English model fine-tuned into a **small action
19
  model** for banking/NBFC customer service: given a user utterance
20
+ (English, Hindi, Hinglish, or Hindi-English code-mixed) and a system
21
+ prompt listing the available tools, it decides whether one applies and
22
+ extracts the arguments.
 
23
 
24
+ This checkpoint (`sep18_round2`) replaces the earlier `gc_v2` checkpoint
25
+ and is a substantial redesign, not an incremental update β€” see
26
+ **What changed** below. **Updated in place** β€” this repository tracks the
27
+ current best checkpoint; check back for updates.
28
 
29
  ## What it does
30
 
31
  ```
32
+ System: You are a banking assistant for an Indian NBFC. Today's date is 2026-09-18 (Friday).
33
+ Given the user's message, decide whether one of the tools below applies. If it does, call it:
34
+ reply with a short natural-language line if appropriate, followed by a JSON object
35
+ {"tool": "<name>", "arguments": {...}} on its own line. Only use arguments that are stated in
36
+ the conversation or can be computed from today's date -- never invent a value. If no tool
37
+ applies, reply in natural language only, or with {"tool": null} if a bare JSON response is expected.
38
+
39
+ Available tools:
40
+ {"name": "get_recent_transactions", "description": "Last N transactions", ...}
41
+ {"name": "set_autopay", "description": "Enable/disable automatic EMI deduction", ...}
42
+ ...
43
+
44
+ User: home loan ki abhi chinta mat karo -- bas recent transactions dikha do.
45
+ Assistant: {"tool": "get_recent_transactions", "arguments": {}}
46
+ ```
47
 
48
+ Unlike the previous checkpoint, **the tool schema is shown in the system
49
+ prompt every time** (JSON-Schema-style, one line per tool) β€” the model is
50
+ schema-conditioned, not relying on having memorized a fixed 41-tool list
51
+ from training alone. It also handles multi-turn slot-filling (asking a
52
+ clarifying question when a required argument is missing) and is trained
53
+ to suppress hypothetical/past-tense/third-person framings.
54
 
55
+ ## What changed vs. the previous checkpoint (`gc_v2`)
56
+
57
+ Deliberately narrowed scope for reliability: **5 tools + no-tool** (down
58
+ from 41 β€” the full 41-tool schema alone is 3,359 tokens, more than this
59
+ model's useful context budget can absorb well). Alongside the narrowing:
60
 
61
+ | | Previous | This checkpoint |
62
+ |---|---|---|
63
+ | Prompt format | Bare `User:/Assistant:`, tools never shown | System prompt with tool schemas + reference date, shown every example |
64
+ | Argument values | Teacher free-generated utterance + values together | Canonical values generated first; teacher only rephrases around them |
65
+ | Negative examples | Single literal-string target `{"tool": null}` | Real natural-language replies, 6 distinct negative types |
66
+ | Train/test split | Row-level random | Stratified by template ID β€” tests unseen phrasing, not just unseen numbers |
67
+ | Training visibility | Single before/after loss number | Per-epoch train+val loss, best-checkpoint auto-save, automatic overfitting diagnosis |
68
 
69
+ **50-test head-to-head result** (same 50 prompts, each model in its own native format):
70
+
71
+ | Metric | Previous (41 tools) | This checkpoint (5 tools) |
72
+ |---|---|---|
73
+ | JSON validity | 98.0% | **100.0%** |
74
+ | Action-correct (call vs. no-call) | 68.0% | **86.0%** |
75
+ | Tool-correct | 85.7% | **91.4%** |
76
+ | Args-exact | 68.6% | **91.4%** |
77
 
78
  ## Architecture
79
 
80
+ Same base architecture as `somasekhar-dev/NextToken-model-1`:
 
 
81
 
82
  | | |
83
  |---|---|
 
85
  | Attention | GQA β€” 16 query heads, 4 KV heads |
86
  | Normalization | RMSNorm + per-head QK-norm |
87
  | FFN | SwiGLU |
88
+ | Context length | 2048 |
89
  | Tokenizer | [`sarvamai/sarvam-1`](https://huggingface.co/sarvamai/sarvam-1), vocab 68,096 |
90
 
91
  ## Usage
92
 
93
+ **Tokenize each message segment separately and concatenate β€” do not
94
+ re-tokenize a merged prompt string.** A real train/inference tokenization
95
+ mismatch was found and fixed earlier in this project (merging the string
96
+ before tokenizing can shift the last context token vs. what the model
97
+ was actually trained on); the example below replicates the verified-correct
98
+ convention and was checked against a real training example before publishing:
99
+
100
  ```python
101
  from transformers import AutoModelForCausalLM, AutoTokenizer
102
  import torch
 
104
  model = AutoModelForCausalLM.from_pretrained("somasekhar-dev/NextToken-model-2")
105
  tokenizer = AutoTokenizer.from_pretrained("somasekhar-dev/NextToken-model-2")
106
 
107
+ system_prompt = (
108
+ "You are a banking assistant for an Indian NBFC. Today's date is 2026-09-18 (Friday).\n"
109
+ "Given the user's message, decide whether one of the tools below applies. If it does, "
110
+ "call it: reply with a short natural-language line if appropriate, followed by a JSON "
111
+ "object {\"tool\": \"<name>\", \"arguments\": {...}} on its own line. Only use arguments "
112
+ "that are stated in the conversation or can be computed from today's date -- never invent "
113
+ "a value. If no tool applies, reply in natural language only, or with {\"tool\": null} if "
114
+ "a bare JSON response is expected.\n\n"
115
+ "Available tools:\n"
116
+ '{"name": "get_recent_transactions", "description": "Last N transactions", '
117
+ '"parameters": {"type": "object", "properties": {"count": {"type": "integer"}}, "required": []}}'
118
+ )
119
+ user_utterance = "home loan ki abhi chinta mat karo -- bas recent transactions dikha do."
120
+
121
+ segments = [f"System: {system_prompt}\n", f"User: {user_utterance}\n", "Assistant: "]
122
+ ids = []
123
+ for seg in segments:
124
+ ids.extend(tokenizer.encode(seg, add_special_tokens=False))
125
+ ids_t = torch.tensor([ids])
126
+
127
+ out = model.generate(ids_t, max_new_tokens=60, do_sample=False,
128
  eos_token_id=tokenizer.eos_token_id, pad_token_id=tokenizer.pad_token_id)
129
+ print(tokenizer.decode(out[0][ids_t.shape[1]:], skip_special_tokens=True))
130
+ # -> {"tool": "get_recent_transactions", "arguments": {}}
131
  ```
132
 
 
 
 
 
 
 
 
 
 
 
133
  ## Training
134
 
135
+ Full fine-tune (not LoRA) off the Hindi-English pretrained base. ~4,914
136
+ examples (`kashyap/task-1/dataset.jsonl`) covering 5 tools + no-tool,
137
+ balanced at ~16.7% each of 6 classes, split by template ID (not by row)
138
+ so held-out examples test generalization to unseen phrasing. Canonical
139
+ argument values generated first (`entity_gen.py`), with the teacher model
140
+ only rephrasing natural language around them β€” the teacher can never
141
+ invent an argument value, which was a real failure mode in the previous
142
+ checkpoint.
143
 
144
  ## Status and limitations
145
 
146
+ Being upfront about what's actually verified vs. still open:
147
+
148
+ - Verified via a same-prompt 50-example head-to-head against the previous
149
+ checkpoint (see table above) β€” not yet validated against a larger,
150
+ independently-generated test set the way the previous checkpoint's
151
+ 200-scenario comparison was.
152
+ - Narrowed to 5 tools deliberately; does not cover the other ~36 tools
153
+ the previous (worse-performing) checkpoint attempted.
154
+ - The system-prompt-with-schema format means correctness depends on
155
+ the exact tool-schema JSON given in-context matching training
156
+ formatting closely β€” schemas very different in style from training
157
+ are unverified.
158
+ - Loss curves alone were actively misleading during this project's own
159
+ development (a "good" loss looked wrong on real inference; a
160
+ rising-val-loss curve looked like overfitting but real testing showed
161
+ the later checkpoint was actually better) β€” always validate against
162
+ real generated output, not the reported loss, before trusting a
163
+ checkpoint.
164
  - **Any state-changing action should be confirmed before executing**,
165
+ not trusted blindly from a single model output.
 
 
166
  - Conversion to this `Qwen3ForCausalLM` checkpoint was verified
167
  numerically (100% argmax agreement vs. the original training-format
168
+ checkpoint on random inputs, plus a full save/reload round-trip, plus
169
+ an independent check here against one real training example).
model.safetensors CHANGED
@@ -1,3 +1,3 @@
1
  version https://git-lfs.github.com/spec/v1
2
- oid sha256:9a4a3dd177a032821882cabca340c2c174e102e442f0ac29605105b9103f76a9
3
  size 1091141072
 
1
  version https://git-lfs.github.com/spec/v1
2
+ oid sha256:3ac1836c97c6d261128648e55f199cfb15848bd87937ee526e30a188ee27f0eb
3
  size 1091141072