ameforge commited on
Commit
c15adb0
·
verified ·
1 Parent(s): 18974a3

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +141 -0
README.md ADDED
@@ -0,0 +1,141 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ - fr
5
+ library_name: transformers
6
+ pipeline_tag: text-generation
7
+ tags:
8
+ - structured-generation
9
+ - function-calling
10
+ - tool-use
11
+ - json
12
+ - edge
13
+ - offline
14
+ - robotics
15
+ - iot
16
+ - agentic
17
+ - small-language-model
18
+ model-index:
19
+ - name: SAM-G
20
+ results:
21
+ - task:
22
+ type: structured-action-generation
23
+ name: Instruction-to-JSON (10 domains, zero-shot)
24
+ metrics:
25
+ - type: json_valid
26
+ value: 100
27
+ name: Valid JSON (%)
28
+ - type: exact_match
29
+ value: 76
30
+ name: Exact match (%)
31
+ - type: exact_match_fr
32
+ value: 77
33
+ name: Exact match, French (%)
34
+ - task:
35
+ type: text-generation
36
+ name: Language modeling (FineWeb-Edu held-out)
37
+ metrics:
38
+ - type: bits_per_byte
39
+ value: 1.179
40
+ name: Bits per byte
41
+ ---
42
+
43
+ # SAM-G
44
+
45
+ **SAM-G** is a 30.3M-parameter dual-mode language model for **offline structured
46
+ action generation**. Given a natural-language instruction it emits compact,
47
+ schema-valid JSON for ten domains; given a question it emits free text. Mode
48
+ selection is learned, not prompted. Built by **AMEFORGE** for robotics, IoT and
49
+ embedded deployment where hosted-LLM APIs are too costly, too slow, or
50
+ unavailable.
51
+
52
+ - **Parameters:** 30.3M · **Footprint:** 121 MB fp32 (~30 MB int8)
53
+ - **Context:** 1024 tokens · **Languages:** English, French (actions)
54
+ - **Throughput:** ~235 tok/s, 16 ms first-token (single GPU); runs on a
55
+ Raspberry-Pi-class CPU
56
+ - **Released:** model weights + inference tokenizer. Training pipeline, data
57
+ generators and architecture are proprietary.
58
+
59
+ ## Two modes
60
+
61
+ | Input | Model emits |
62
+ |---|---|
63
+ | `turn on the kitchen lamp` | `[ACTION] {"domain":"home","op":"set_state","params":{"device":"lamp","name":"kitchen","state":"on"}}` |
64
+ | `what is a mutex` | `[CHAT] A mutex is a lock that allows one thread at a time.` |
65
+
66
+ Domains: `ros`, `http`, `mqtt`, `db`, `workflow`, `ecommerce`, `vehicle`,
67
+ `home`, `cal`, `file`.
68
+
69
+ ## Benchmark
70
+
71
+ SAM-G is evaluated **zero-shot** in its native format; baselines run **3-shot**
72
+ through their chat template with a system instruction. `bpb` is tokenizer-fair
73
+ (per-token perplexity is not comparable across vocabularies). `exact/M` =
74
+ action exact-match per million parameters — the efficiency axis.
75
+
76
+ | Model | Params | bpb ↓ | JSON valid % | Exact % | Exact FR % | Cloze % | MB | tok/s | exact/M ↑ |
77
+ |---|---|---|---|---|---|---|---|---|---|
78
+ | **SAM-G** | **30.3M** | 1.179 | **100** | **76** | **77** | 83 | **121** | **235** | **2.51** |
79
+ | Pythia-70M | 70M | 1.674 | 2 | 0 | 0 | 75 | 141 | 120 | 0.00 |
80
+ | Qwen2.5-0.5B-Instruct | 494M | 0.814 | 99 | 25 | 7 | 96 | 988 | 27 | 0.05 |
81
+ | SmolLM2-360M-Instruct | 362M | 0.812 | 96 | 14 | 0 | 96 | 724 | 21 | 0.04 |
82
+ | Qwen2.5-1.5B-Instruct | 889M | 0.753 | 98 | 21 | 0 | 96 | 444* | 13 | 0.02 |
83
+
84
+ <sub>*Qwen2.5-1.5B loaded in 4-bit. Larger general models lead on bits-per-byte
85
+ and cloze (they are 12–30× bigger and trained for general knowledge); SAM-G
86
+ leads decisively on structured action, French actions, footprint, speed, and
87
+ exact-match per parameter. Notably Qwen2.5-1.5B scores *below* Qwen2.5-0.5B on
88
+ action exact-match — capability here comes from domain specialization, not
89
+ scale.</sub>
90
+
91
+ ## Per-domain exact match (%)
92
+
93
+ | ros | http | mqtt | db | workflow | ecommerce | vehicle | home | cal | file |
94
+ |---|---|---|---|---|---|---|---|---|---|
95
+ | 0 | 100 | 100 | 100 | 60 | 100 | 100 | 50 | 80 | 60 |
96
+
97
+ All general baselines score 0 on most domains, succeeding only partially on the
98
+ most generic ones (home, cal). `ros` (floating-point fields) is SAM-G's weakest
99
+ schema and benefits most from additional training data.
100
+
101
+ ## Usage
102
+
103
+ ```python
104
+ import sentencepiece as spm, torch
105
+ # Load the released inference tokenizer (samg_tokenizer.model) and weights.
106
+ sp = spm.SentencePieceProcessor(); sp.Load("samg_tokenizer.model")
107
+
108
+ prompt = "publish 21.5 on sensors/temp qos 1 [ACTION]"
109
+ ids = torch.tensor([sp.EncodeAsIds(prompt)])
110
+ # greedy-decode with your loaded model until EOS, then sp.DecodeIds(...)
111
+ # -> {"domain":"mqtt","op":"publish","params":{"topic":"sensors/temp","payload":21.5,"qos":1}}
112
+ ```
113
+
114
+ Always parse output as JSON and validate against your schema before execution.
115
+
116
+ ## Intended use
117
+
118
+ On-device home automation; NL→ROS robot command layers; MQTT fleet gateways;
119
+ offline vehicle commands; NL-to-SQL on embedded databases; workflow triggers;
120
+ and the structured tool-calling stage of agentic pipelines — as a drop-in
121
+ replacement or a fast router ahead of a larger hosted model.
122
+
123
+ ## Limitations
124
+
125
+ - Not a general assistant: factual knowledge and open-ended reasoning are
126
+ limited at this scale; larger general models lead on bits-per-byte and cloze.
127
+ - French covers actions, not extended prose.
128
+ - Schemas outside the ten domains need fine-tuning. The `ros` schema
129
+ (floating-point fields) is the weakest and benefits most from more data.
130
+ - The action benchmark is synthetic, drawn from the training distribution
131
+ family with a disjoint evaluation seed (999).
132
+
133
+ ## Citation
134
+
135
+ ```bibtex
136
+ @misc{samg2026,
137
+ title = {SAM-G: A 30M-Parameter Dual-Mode Language Model for Offline Structured Action Generation},
138
+ author = {AMEFORGE Lab},
139
+ year = {2026}
140
+ }
141
+ ```