Text Generation
Transformers
Safetensors
Hindi
English
qwen3
indic
small-language-model
tool-calling
function-calling
banking
conversational
text-generation-inference
Instructions to use somasekhar-dev/NextToken-model-2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use somasekhar-dev/NextToken-model-2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="somasekhar-dev/NextToken-model-2") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("somasekhar-dev/NextToken-model-2") model = AutoModelForCausalLM.from_pretrained("somasekhar-dev/NextToken-model-2", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use somasekhar-dev/NextToken-model-2 with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "somasekhar-dev/NextToken-model-2" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "somasekhar-dev/NextToken-model-2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/somasekhar-dev/NextToken-model-2
- SGLang
How to use somasekhar-dev/NextToken-model-2 with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "somasekhar-dev/NextToken-model-2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "somasekhar-dev/NextToken-model-2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "somasekhar-dev/NextToken-model-2" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "somasekhar-dev/NextToken-model-2", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use somasekhar-dev/NextToken-model-2 with Docker Model Runner:
docker model run hf.co/somasekhar-dev/NextToken-model-2
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- README.md +109 -70
- 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)
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
questions as its primary job.
|
| 24 |
|
| 25 |
-
This checkpoint (`
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
|
| 30 |
## What it does
|
| 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 |
## Architecture
|
| 56 |
|
| 57 |
-
Same base architecture as `somasekhar-dev/NextToken-model-1`
|
| 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
|
| 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 |
-
|
| 80 |
-
|
| 81 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 82 |
eos_token_id=tokenizer.eos_token_id, pad_token_id=tokenizer.pad_token_id)
|
| 83 |
-
print(tokenizer.decode(out[0
|
|
|
|
| 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
|
| 99 |
-
|
| 100 |
-
~
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
|
|
|
| 105 |
|
| 106 |
## Status and limitations
|
| 107 |
|
| 108 |
-
Being upfront about what's actually verified vs. still
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
|
|
|
|
|
|
| 124 |
- **Any state-changing action should be confirmed before executing**,
|
| 125 |
-
not trusted blindly from a single model output
|
| 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:
|
| 3 |
size 1091141072
|
|
|
|
| 1 |
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3ac1836c97c6d261128648e55f199cfb15848bd87937ee526e30a188ee27f0eb
|
| 3 |
size 1091141072
|