textilelabs commited on
Commit
d00e889
·
verified ·
1 Parent(s): 8c5e87c

Upload 16 files

Browse files
.gitattributes CHANGED
@@ -33,3 +33,6 @@ 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
+ banner.jpg filter=lfs diff=lfs merge=lfs -text
37
+ logo.jpg filter=lfs diff=lfs merge=lfs -text
38
+ loom-spark-3.2-f16.gguf filter=lfs diff=lfs merge=lfs -text
ATTRIBUTION.md ADDED
@@ -0,0 +1,28 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # Attribution
2
+
3
+ Loom Spark 3.2 was trained from scratch: random initialisation, then two short second passes
4
+ on its own weights. No third-party checkpoint was used. Grounded-reading rows embed real
5
+ encyclopedic prose. Some of these licences require attribution; this file satisfies that
6
+ requirement and must be kept with any redistribution.
7
+
8
+ | slice | source | licence |
9
+ |---|---|---|
10
+ | grounded reading + "the answer isn't in this passage" | SQuAD 2.0 (Rajpurkar, Jia & Liang) | CC BY-SA 4.0 |
11
+ | three-paragraph reading (same-article paragraphs) | SQuAD 2.0 | CC BY-SA 4.0 |
12
+ | multi-hop grounded reading | HotpotQA | CC BY-SA 4.0 |
13
+ | trivia reading (answer sentence from the entity's article) | TriviaQA | Apache 2.0 |
14
+ | when to reach for a tool | MASSIVE (Amazon) / CLINC150 (Larson et al.) | CC BY 4.0 / CC BY 3.0 |
15
+ | instruction following | databricks-dolly-15k | CC BY-SA 3.0 |
16
+ | multi-turn dialogue structure | OpenAssistant OASST1 | Apache 2.0 |
17
+ | encyclopedic passages | Wikipedia | CC BY-SA |
18
+ | identity, limits, warmth, memory within a chat, attribution, injection resistance | Textile Labs | MIT |
19
+
20
+ Only English portions were used. OASST conversations in which the original assistant named
21
+ itself were removed. Source text was not altered except for truncation to a realistic
22
+ tool-result length, and surface augmentation (casing, punctuation, filler) applied to user
23
+ turns in training copies only.
24
+
25
+ ## Search queries — derived, not generated
26
+ Every `<lookup>` query in the training data is the subject of the question, derived
27
+ mechanically from the human-written sources above. No language model wrote any training
28
+ query or any training reply. No real user data was used. Model weights: MIT.
LICENSE ADDED
@@ -0,0 +1,21 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Textile Labs
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
Modelfile ADDED
@@ -0,0 +1,15 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ FROM ./loom-spark-3.2-f16.gguf
2
+ TEMPLATE """<tools:off>
3
+ <user>
4
+ {{ .Prompt }}
5
+ <|eot|>
6
+ <loom>
7
+ """
8
+ PARAMETER stop "<|eot|>"
9
+ PARAMETER stop "<user>"
10
+ PARAMETER stop "<result>"
11
+ PARAMETER temperature 0.7
12
+ PARAMETER top_k 40
13
+ PARAMETER repeat_penalty 1.0
14
+ PARAMETER num_predict 128
15
+ PARAMETER num_ctx 2048
README.md CHANGED
@@ -1,3 +1,278 @@
1
  ---
2
  license: mit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
3
  ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
  ---
2
  license: mit
3
+ language: en
4
+ library_name: transformers
5
+ pipeline_tag: text-generation
6
+ tags:
7
+ - tiny-model
8
+ - llama
9
+ - from-scratch
10
+ - conversational
11
+ - multi-turn
12
+ - tool-use
13
+ - agent-harness
14
+ - retrieval-augmented
15
+ - question-answering
16
+ - attribution
17
+ - humble-ai
18
+ - small-language-model
19
+ - muon
20
+ - gguf
21
+ - text-generation-inference
22
+ widget:
23
+ - text: "<tools:off>\n<user>\nwho are you\n<|eot|>\n<loom>\n"
24
+ example_title: "Identity"
25
+ - text: "<tools:off>\n<user>\nwho wrote the odyssey\n<|eot|>\n<loom>\n"
26
+ example_title: "Knows when it doesn't know"
27
+ - text: "<tools:on>\n<user>\nwhats the capital of peru\n<|eot|>\n<loom>\n"
28
+ example_title: "Search for the thing"
29
  ---
30
+
31
+ <div align="center">
32
+ <img src="banner.jpg" alt="Loom Spark 3.2" width="520">
33
+ </div>
34
+
35
+ # Loom Spark 3.2
36
+
37
+ <img src="logo.jpg" alt="" width="20" height="20" style="border-radius:4px;vertical-align:middle;margin-right:6px;"> **22.8M parameters · 20 layers · 2,048 context · Textile Labs**
38
+
39
+ The Spark that knows what it doesn't know. Successor to
40
+ [Loom Spark 3](https://huggingface.co/textilelabs/Loom-Spark-3). Trained from scratch:
41
+ randomly initialised weights, nothing fine-tuned from anyone's checkpoint.
42
+
43
+ **Ask Spark 3 a fact it can't know with tools off — who wrote the Odyssey — and it makes something up
44
+ or loops 17 times in 20. Spark 3.2 says it would be guessing 16 times in 20 — and still answers the ten basic facts
45
+ it does know.** It matches Spark 3's live search and beats it on our full acceptance battery,
46
+ 122/133 to 120/133.
47
+
48
+ ## What changed from Spark 3
49
+
50
+ | | Spark 3 | **Spark 3.2** |
51
+ |---|---|---|
52
+ | size | 12.2M | **22.8M** (the Spark tier is now ~20M) |
53
+ | context | 512 tokens | **2,048 tokens** |
54
+ | hardware | one 2013 desktop CPU, 3 h 54 min | Kaggle, 2 × T4 GPU, 2 h 13 min |
55
+ | unknown facts, tools off | declined 3 of 20 | **declines 16 of 20** |
56
+ | basic facts it should know | 0 of 20 right | **15 of 20 right** |
57
+ | talking about itself in its own words | 9 of 16 | **12 of 16** |
58
+ | responding to good and bad news | 2 of 20 | **10 of 20** |
59
+ | prompt injection resisted | 33 of 36 | **36 of 36** |
60
+
61
+ Spark 3 only declined capital-city questions offline; for everything else it guessed. Spark
62
+ 3.2 was trained on declines across every kind of fact, and on **contrast pairs**: questions
63
+ with the same shape as a fact it knows but a different subject (*"how many bones does a whale
64
+ have"* next to *"how many bones does an adult have"*), so it learns the subject matters, not
65
+ the sentence shape.
66
+
67
+ The four-times-longer context lets it keep track of longer chats: on 10-turn conversations
68
+ where a fact from turn 1–3 is asked again at turn 9–10, it gets 2 of 4 (Spark 3: 0 of 4).
69
+
70
+ ## The search harness
71
+
72
+ The model decides a search is needed and writes the query. `harness.py` does the rest: it
73
+ searches the model's query and the subject in your question, prefers the real article over
74
+ lists and disambiguation pages, and hands back **one sentence**, the one most likely to hold
75
+ an answer of the right kind. It now retries when Wikipedia is busy (HTTP 502/503/504) as well
76
+ as when it rate-limits.
77
+
78
+ ```
79
+ you who composed the four seasons
80
+ Loom Spark 3.2 <lookup>composed four seasons</lookup>
81
+ harness ← The Four Seasons is a group of four violin concerti by Italian composer Antonio Vivaldi, ...
82
+ Loom Spark 3.2 Antonio Vivaldi. I looked that one up.
83
+ ```
84
+
85
+ ## Measured against Spark 3
86
+
87
+ Same tests, same harness, same settings, both models through Ollama, 2026-10-01. None of
88
+ these questions are in the training data — every test prompt is scrubbed from the corpus
89
+ before training.
90
+
91
+ **End to end**: 20 held-out everyday questions, live Wikipedia, the model writing its own
92
+ query. Scored on the final answer.
93
+
94
+ | | decided to search | wrote its own query | answer reached the model | **answered right** |
95
+ |---|---:|---:|---:|---:|
96
+ | Spark 3 | 20/20 | 20/20 | 12/20 | **7/20** |
97
+ | **Loom Spark 3.2** | 20/20 | 20/20 | 13/20 | **7/20** |
98
+
99
+ Read by eye, one of Spark 3.2's seven is generous: it searched `fahrenheit speed` for the
100
+ boiling point of water in Fahrenheit and still reached "32 °F and the boiling point...".
101
+
102
+ **The acceptance battery**, row by row:
103
+
104
+ | row | Spark 3 | **Loom Spark 3.2** |
105
+ |---|---:|---:|
106
+ | A · says its own name | 11/12 | **12/12** |
107
+ | B · its own name under rough typing (`WHATS UR NAME???`) | 11/12 | 11/12 |
108
+ | C · 5-turn conversation stays on thread | 5/5 | 5/5 |
109
+ | D · answers from a search result | 3/5 | 3/5 |
110
+ | E · follow-up answered from the same result | **3/5** | 1/5 |
111
+ | F · says it looked, after a lookup | 5/5 | 5/5 |
112
+ | G · **never** claims a lookup it didn't make | 16/16 | 16/16 |
113
+ | H · admits what it can't know about you | 8/8 | 8/8 |
114
+ | I · says when a result doesn't contain the answer | 0/5 | **2/5** |
115
+ | J · never leaks a search tag with tools off | 28/28 | 28/28 |
116
+ | K · stops on its own | 12/12 | 12/12 |
117
+ | L · searches when it should, not for your private things | 18/20 | **19/20** |
118
+ | **total** | **120/133** | **122/133** |
119
+
120
+ **Held-out behaviour tests**, written before Spark 3.2 was trained:
121
+
122
+ | | Spark 3 | **Loom Spark 3.2** |
123
+ |---|---:|---:|
124
+ | unknown facts, tools off — declines instead of guessing | 3/20 | **16/20** |
125
+ | ten basic facts, tools off — answers right | 0/20 | **15/20** |
126
+ | same facts, tools on — looks them up | 20/20 | 20/20 |
127
+ | same-shape questions it doesn't know — no false "I know this" | **20/20** | 19/20 |
128
+ | a `<tools:on>` typed inside a message doesn't switch search on | 12/12 | 12/12 |
129
+ | in its own words about itself | 9/16 | **12/16** |
130
+ | warmth — good news and bad news met correctly | 2/20 | **10/20** |
131
+ | prompt injection — kept its identity, didn't obey (12 prompts × 3) | 33/36 | **36/36** |
132
+ | 10- and 12-turn conversations — turns answered on target | 41/44 | **42/44** |
133
+
134
+ Spark 3's 20/20 on the same-shape row is mostly empty: asked "how far is mars from earth",
135
+ it loops ("mars, mars, mars…") rather than claiming anything. Spark 3.2 declines most of
136
+ these properly; its one miss is below.
137
+
138
+ ## Every Loom text model
139
+
140
+ | model | params | battery /133 | live search (e2e) | reads real prose | status |
141
+ |---|---:|---:|---:|---|---|
142
+ | Loom Spark 2 | 19.9M | ~97/133 | 2/20 | no | shipped |
143
+ | Loom Tapestry 2 | 22.8M | 107/133 | — | curated only | shipped |
144
+ | Loom Tapestry 3 Flash | 7.18M | 112/133 | 3/20 | curated only | shipped |
145
+ | Loom Spark 3 Flash | 7.18M | 119/133 | 5/20 | curated only | shipped |
146
+ | Loom Spark 3 | 12.2M | 120/133 | 7/20 | curated only | shipped |
147
+ | Loom Weave 2 | 59.65M | — (method failure) | — | no | shipped (superseded) |
148
+ | Loom Weave 3 | 31.5M | 120/133 | 6/20 held | yes — first | shipped |
149
+ | Loom Tapestry 3 | 69.2M | 123/133 | 12/20 held | yes + multi-hop | shipped |
150
+ | Loom Crucible Preview | 155.0M | 125/133† | 10/20 held | yes — best reader | shipped |
151
+ | **Loom Spark 3.2** | **22.8M** | **122/133†** | **7/20 held** | **curated only** | **this model** |
152
+
153
+ † scored on a battery with every test prompt scrubbed from training. Earlier rows' scores are
154
+ each model's release score; only models in the same table above were measured side by side.
155
+ Bigger Looms still read real prose far better — choose Tapestry 3 or Crucible Preview if
156
+ search answers matter most.
157
+
158
+ ## Read this before you use it
159
+
160
+ Every point here was measured.
161
+
162
+ - **It gets about a third of everyday questions right with search.** Same as Spark 3.
163
+ "I looked that up" means it searched, not that it read the result correctly. Run the
164
+ harness with `--show` and trust the sentence it read over its summary of it.
165
+ - **It reads the right sentence and picks the wrong part.** Canada comes back as "Toronto,
166
+ Montreal, and Vancouver"; *who wrote Pride and Prejudice* comes back as "Pride and
167
+ Prejudice"; *who discovered gravity* as "Albert Einstein".
168
+ - **Follow-up questions about the same result are weak — worse than Spark 3** (1/5 vs 3/5).
169
+ Ask a fresh, complete question instead of "how many people live there".
170
+ - **It usually doesn't say when a result lacks the answer** (2/5). It answers from whatever
171
+ it read.
172
+ - **Long pasted documents don't work yet.** The context is 2,048 tokens, but asked a question
173
+ about a 1,000–1,600-token pasted text, it got 0 of 4. The longer context helps it follow
174
+ longer chats, not read long documents.
175
+ - **One false "I know this" in twenty:** asked how far the Sun is from the Moon, it gave the
176
+ Earth–Moon distance.
177
+ - **It searched for a private question once in twenty** — *"where did i go to school"*.
178
+ - **Warmth is a coin flip.** Half the time good news gets "Okay, I'll remember that." instead
179
+ of congratulations.
180
+ - **It sometimes garbles a query** — `caly` for *the capital of italy*. The harness's subject
181
+ search catches most of these.
182
+ - **Harness search is Wikipedia only**, so time, weather, news and prices can't be answered
183
+ even when it correctly decides to look them up.
184
+
185
+ ## Usage — the harness
186
+
187
+ ```bash
188
+ python3 harness.py "whats the capital of peru"
189
+ python3 harness.py # interactive
190
+ python3 harness.py --show "who wrote hamlet" # see what it searched and read
191
+ python3 harness.py --no-tools "who are you"
192
+ ```
193
+
194
+ Stdlib only. Wikipedia needs no API key. Swap `search()` for anything — the contract is text
195
+ in, one sentence out. **Never feed a failed lookup back as a result** — the model will answer
196
+ from the error text. `harness.py` fails loudly instead.
197
+
198
+ ## Usage — Ollama
199
+
200
+ ```bash
201
+ ollama run hf.co/textilelabs/Loom-Spark-3.2 "who are you"
202
+ ```
203
+
204
+ `template` and `params` are read automatically. **Do not add a repetition penalty** — the
205
+ model answers by quoting what it read, so penalising repeats penalises the right answer.
206
+
207
+ ## Usage — transformers
208
+
209
+ ```python
210
+ import torch
211
+ from transformers import AutoTokenizer, AutoModelForCausalLM
212
+
213
+ tok = AutoTokenizer.from_pretrained("textilelabs/Loom-Spark-3.2")
214
+ model = AutoModelForCausalLM.from_pretrained("textilelabs/Loom-Spark-3.2").eval()
215
+ eot = tok.convert_tokens_to_ids("<|eot|>")
216
+
217
+ def ask(message, tools=False):
218
+ p = f"<tools:{'on' if tools else 'off'}>\n<user>\n{message}\n<|eot|>\n<loom>\n"
219
+ ids = tok(p, return_tensors="pt", add_special_tokens=False).input_ids
220
+ with torch.no_grad():
221
+ out = model.generate(ids, max_new_tokens=96, do_sample=False, eos_token_id=eot,
222
+ pad_token_id=tok.convert_tokens_to_ids("<|pad|>"))[0]
223
+ return tok.decode(out[ids.shape[1]:], skip_special_tokens=False).replace("<|eot|>", "").strip()
224
+ ```
225
+
226
+ Prompt format is exact: `<tools:off>\n<user>\n{message}\n<|eot|>\n<loom>\n`. For more turns,
227
+ append `{reply}<|eot|>\n<user>\n{next message}\n<|eot|>\n<loom>\n`.
228
+
229
+ ## How it was built
230
+
231
+ | | |
232
+ |---|---|
233
+ | architecture | Llama — 20 layers × 320d, FFN 864, GQA (5 heads / 1 KV), SwiGLU, RoPE, tied embeddings |
234
+ | parameters | 22,827,840 |
235
+ | context | 2,048 |
236
+ | vocabulary | 4,096 custom BPE (the Spark-line tokenizer, unchanged from Spark 3) |
237
+ | optimiser | Muon (0.025) on the 2D hidden matrices, AdamW (6e-4) on embeddings and norms |
238
+ | schedule | warmup → stable → decay (WSD), decay from 65%, with a focused mix in the decay |
239
+ | packing | whole conversations packed into 2,048-token windows, **each conversation masked so it can only see itself** |
240
+ | corpus | about 285,000 conversations · 48.2M tokens per pass, loss on the model's replies only |
241
+ | second passes | two 30-minute passes on its own weights at a fifth of the learning rate: the focused mix, then the same plus 3,600 contrast-pair and known-fact rows |
242
+ | training | 274.9M tokens · 12.0 tokens per parameter · from random init |
243
+ | hardware | Kaggle, 2 × NVIDIA T4 · 2 h 13 min (74 min, then 30 + 30 min) |
244
+
245
+ The per-conversation mask mattered more than anything else. Without it, up to 68 short
246
+ conversations shared one window and could see each other, and the model learned to copy its
247
+ neighbours instead of reading its own chat: the first unmasked run scored 107/133. Same data
248
+ with the mask: 120/133.
249
+
250
+ ## Files
251
+
252
+ ```
253
+ config.json / model.safetensors the model
254
+ tokenizer.json / tokenizer_config.json custom BPE tokenizer, 4,096 tokens
255
+ loom-spark-3.2-f16.gguf for Ollama / llama.cpp
256
+ harness.py runnable search harness — stdlib only
257
+ template / params read automatically by `ollama run hf.co/...`
258
+ Modelfile for building locally
259
+ ATTRIBUTION.md required credits for the training corpora
260
+ ```
261
+
262
+ ## Training data
263
+
264
+ | slice | source |
265
+ |---|---|
266
+ | grounded reading, three-paragraph reading, and "the result doesn't say" | **SQuAD 2.0** (CC BY-SA 4.0) |
267
+ | multi-hop and trivia reading | **HotpotQA** (CC BY-SA 4.0) · **TriviaQA** (Apache 2.0) · Wikipedia (CC BY-SA) |
268
+ | when to reach for a tool | **MASSIVE** (CC BY 4.0) · **CLINC150** (CC BY 3.0) |
269
+ | instruction following | **databricks-dolly-15k** (CC BY-SA 3.0) |
270
+ | multi-turn dialogue structure | **OpenAssistant OASST1** (Apache 2.0) |
271
+ | identity, limits, declines, warmth, memory within a chat, injection resistance | Textile Labs — written for Loom |
272
+
273
+ Every search query is derived mechanically from these sources. No language model wrote any
274
+ training data, and nothing is fine-tuned from anyone's checkpoint.
275
+
276
+ ## License
277
+
278
+ Model: MIT. Training data retains its original licences and attribution.
banner.jpg ADDED

Git LFS Details

  • SHA256: 5d9be884194dc82d0f79a156d54692950809883f560a1870719d49470f335bca
  • Pointer size: 132 Bytes
  • Size of remote file: 2.02 MB
config.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "LlamaForCausalLM"
4
+ ],
5
+ "attention_bias": false,
6
+ "attention_dropout": 0.0,
7
+ "bos_token_id": null,
8
+ "dtype": "float32",
9
+ "eos_token_id": 0,
10
+ "head_dim": 64,
11
+ "hidden_act": "silu",
12
+ "hidden_size": 320,
13
+ "initializer_range": 0.02,
14
+ "intermediate_size": 864,
15
+ "max_position_embeddings": 2048,
16
+ "mlp_bias": false,
17
+ "model_type": "llama",
18
+ "num_attention_heads": 5,
19
+ "num_hidden_layers": 20,
20
+ "num_key_value_heads": 1,
21
+ "pad_token_id": 1,
22
+ "pretraining_tp": 1,
23
+ "rms_norm_eps": 1e-05,
24
+ "rope_parameters": {
25
+ "rope_type": "default",
26
+ "rope_theta": 10000.0
27
+ },
28
+ "tie_word_embeddings": true,
29
+ "transformers_version": "5.0.0",
30
+ "use_cache": true,
31
+ "vocab_size": 4096,
32
+ "rope_theta": 10000.0
33
+ }
generation_config.json ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_from_model_config": true,
3
+ "eos_token_id": 0,
4
+ "output_attentions": false,
5
+ "output_hidden_states": false,
6
+ "pad_token_id": 1,
7
+ "transformers_version": "5.15.1",
8
+ "use_cache": true
9
+ }
harness.py ADDED
@@ -0,0 +1,216 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ #!/usr/bin/env python3
2
+ """Loom harness — the search half of Loom Spark 3.2.
3
+
4
+ The model never searches. It decides a lookup is needed and writes the query:
5
+
6
+ <lookup>france</lookup>
7
+
8
+ This script does the rest: searches Wikipedia, finds the ONE sentence most likely to
9
+ hold the answer, hands it back as a <result>, and lets the model answer from it.
10
+
11
+ python3 harness.py "what's the capital of france"
12
+ python3 harness.py # interactive
13
+ python3 harness.py --no-tools "who are you"
14
+ python3 harness.py --show "who wrote hamlet" # print what was searched and read
15
+
16
+ How it finds the answer, and why each step exists (all measured on live questions):
17
+ * searches the model's query AND the subject it can see in your question —
18
+ "whats the capital of france" searched as-is returns "Capital city" and "Das Kapital"
19
+ * prefers the real article over lists, films, albums and disambiguation pages
20
+ * reads the article's intro first, and further only when the intro has no answer of
21
+ the right kind (a height with a unit, a year, a number, a name)
22
+ * strips brackets and pronunciation guides, so real text looks like training text
23
+ * hands back ONE sentence. A 340-character window found the answer more often but the
24
+ model misread it four times in five; one sentence doubled the final score (15% -> 30%)
25
+
26
+ Swap search() for anything you like — the contract is text in, one sentence out.
27
+ Wikipedia needs no API key. Stdlib only.
28
+ """
29
+ from __future__ import annotations
30
+
31
+ import argparse, json, re, ssl, sys, time, urllib.error, urllib.parse, urllib.request
32
+
33
+ try: # macOS system Python often lacks a CA bundle
34
+ import certifi
35
+ SSL_CTX = ssl.create_default_context(cafile=certifi.where())
36
+ except Exception:
37
+ SSL_CTX = ssl.create_default_context()
38
+
39
+ OLLAMA = "http://localhost:11434/api/generate"
40
+ MODEL = "hf.co/textilelabs/Loom-Spark-3.2"
41
+ API = "https://en.wikipedia.org/w/api.php?"
42
+ # Wikipedia returns 403 without a descriptive User-Agent.
43
+ UA = {"User-Agent": "LoomHarness/3.0 (Textile Labs; https://huggingface.co/textilelabs)"}
44
+ LOOKUP = re.compile(r"<lookup>(.*?)</lookup>", re.S)
45
+ _cache: dict = {}
46
+
47
+ # ------------------------------------------------------------------- the model
48
+ def loom(prompt: str, n: int = 64) -> str:
49
+ body = json.dumps({"model": MODEL, "prompt": prompt, "raw": True, "stream": False,
50
+ "options": {"temperature": 0, "num_predict": n, "repeat_penalty": 1.0, "num_ctx": 2048,
51
+ "stop": ["<|eot|>", "<user>", "<result>"]}}).encode()
52
+ req = urllib.request.Request(OLLAMA, data=body, headers={"Content-Type": "application/json"})
53
+ with urllib.request.urlopen(req, timeout=120) as r:
54
+ return json.load(r)["response"].strip()
55
+
56
+ # ------------------------------------------------------------------ wikipedia
57
+ def _get(params: dict) -> dict:
58
+ key = json.dumps(params, sort_keys=True)
59
+ if key in _cache:
60
+ return _cache[key]
61
+ for attempt in range(3):
62
+ try:
63
+ with urllib.request.urlopen(urllib.request.Request(
64
+ API + urllib.parse.urlencode(params), headers=UA),
65
+ context=SSL_CTX, timeout=20) as r:
66
+ _cache[key] = json.load(r)
67
+ return _cache[key]
68
+ except urllib.error.HTTPError as e:
69
+ if e.code in (429, 502, 503, 504):
70
+ time.sleep(3 * (attempt + 1)); continue
71
+ raise
72
+ raise RuntimeError("Wikipedia busy or rate-limited — try again")
73
+
74
+ def search(q: str, n: int = 3) -> list:
75
+ return [h["title"] for h in _get({"action": "query", "list": "search", "srsearch": q,
76
+ "format": "json", "srlimit": n})["query"]["search"]]
77
+
78
+ def _extract(title: str, intro: bool) -> str:
79
+ p = {"action": "query", "prop": "extracts", "explaintext": 1, "titles": title,
80
+ "format": "json", "redirects": 1}
81
+ if intro:
82
+ p["exintro"] = 1
83
+ return next(iter(_get(p)["query"]["pages"].values())).get("extract", "") or ""
84
+
85
+ # ------------------------------------------------------------------ the finder
86
+ SENT = re.compile(r"(?<=[.!?])\s+(?=[A-Z0-9])")
87
+ PAREN = re.compile(r"\s*\([^()]*\)")
88
+ HEADING = re.compile(r"^\s*=+[^=]+=+\s*$", re.M)
89
+ STOP = set(("what whats who whos whom whose when where which why how is are was were be the a an "
90
+ "of in on to for does did do by from with as at and or that this it its there tell me "
91
+ "please can you many much").split())
92
+ ATTR = set(("capital city height tall high elevation population largest biggest smallest longest "
93
+ "shortest tallest highest deepest first last symbol chemical language languages spoken "
94
+ "legs year date end ended sink sank invented inventor discovered discovery developed "
95
+ "wrote written author painted painter president founded born died age old size area "
96
+ "distance speed").split())
97
+ JUNK = re.compile(r"^(lists? of|outline of|index of|timeline of)\b|\((film|album|song|band|"
98
+ r"novel|play|tv series|musical|opera|video game|book|composition|poem)\)|"
99
+ r"\bdisambiguation\b", re.I)
100
+
101
+ def keywords(t: str) -> list:
102
+ return [w for w in re.findall(r"[^\W_]+", t.lower()) if w not in STOP]
103
+
104
+ def subject(question: str) -> str:
105
+ kw = keywords(question)
106
+ return " ".join(k for k in kw if k not in ATTR) or " ".join(kw)
107
+
108
+ def clean(t: str) -> str:
109
+ prev = None
110
+ while prev != t:
111
+ prev, t = t, PAREN.sub("", t)
112
+ return re.sub(r"\s+", " ", t.replace(" ,", ",")).strip()
113
+
114
+ def _hard(q: str, s: str) -> float:
115
+ """The answer is of the right KIND: a height with a unit, a year, a number, a name."""
116
+ b = 0.0
117
+ if re.search(r"\b(how tall|how high|height|elevation)\b", q):
118
+ b += 2.0 if re.search(r"\d[\d,.]*\s*(m|metres|meters|ft|feet|km)\b", s) else 0
119
+ if re.search(r"\b(when|what year|which year|what date)\b", q):
120
+ b += 2.0 if re.search(r"\b(1\d{3}|20\d{2})\b", s) else 0
121
+ if re.search(r"\b(how many|how much|population|number of)\b", q):
122
+ b += 1.5 if re.search(r"\d", s) else 0
123
+ if re.search(r"\bwho\b", q):
124
+ b += 1.5 if re.search(r"\b[A-Z][a-z]+ [A-Z][a-z]+", s) else 0
125
+ if re.search(r"\bsymbol\b", q):
126
+ b += 2.0 if re.search(r"\bsymbol\b", s, re.I) else 0
127
+ if re.search(r"\bcapital\b", q):
128
+ b += 2.0 if re.search(r"\bcapital\b", s, re.I) else 0
129
+ return b
130
+
131
+ def _kind(q: str, s: str) -> float:
132
+ b, sl = _hard(q, s), s.lower()
133
+ if re.search(r"\b(how tall|how high|height|elevation)\b", q):
134
+ b += 1.5 if re.search(r"\b(summit|elevation|height|above sea level|highest|stands)\b", sl) else -0.5
135
+ if re.search(r"\b(end|ended|finish|finished)\b", q):
136
+ b += 1.5 if re.search(r"\b(ended|end of|surrender|surrendered|concluded|finished)\b", sl) else -0.5
137
+ if re.search(r"\bpopulation\b", q):
138
+ b += 2.0 if re.search(r"\d{1,3}(,\d{3})+|\d+(\.\d+)?\s*(million|billion)", s) else -1.0
139
+ if re.search(r"\b(invent|invented|inventor|discovered|wrote|painted|composed|founded)\b", q):
140
+ b += 1.0 if re.search(r"\b[A-Z][a-z]+ (?:[A-Z][a-z]+ )?[A-Z][a-z]+\b", s) else 0.0
141
+ return b
142
+
143
+ def find(query: str, question: str) -> tuple:
144
+ """One sentence most likely to hold the answer, and the article it came from."""
145
+ q = question.lower()
146
+ subj = subject(question)
147
+ pool = {}
148
+ for tq in dict.fromkeys(x for x in (query.strip(), subj, " ".join(keywords(question))) if x):
149
+ for rank, t in enumerate(search(tq, 3)):
150
+ tl = t.lower()
151
+ s = (4.0 if tl in (subj, query.strip().lower()) else 2.0 if subj and tl.startswith(subj) else 0.0)
152
+ s += -4.0 if JUNK.search(t) else 0.0
153
+ pool[t] = max(pool.get(t, -1e9), s - 0.3 * rank)
154
+ qk = list(dict.fromkeys(keywords(question) + keywords(query)))
155
+ top = sorted(pool.items(), key=lambda x: -x[1])[:3]
156
+ typed = bool(re.search(r"\b(how tall|how high|height|elevation|when|what year|which year|"
157
+ r"how many|how much|population|who|symbol|capital)\b", q))
158
+ best = (-1e9, "", "")
159
+ for intro in (True, False):
160
+ found_kind = False
161
+ for title, ps in top:
162
+ raw = _extract(title, intro)
163
+ if re.search(r"\b(may|can) refer to\b", raw[:400]):
164
+ continue
165
+ body = clean(HEADING.sub(" ", raw))
166
+ sents = [s.strip() for s in SENT.split(body) if 20 < len(s.strip()) < 600]
167
+ for i, s in enumerate(sents[: 14 if intro else 90]):
168
+ sc = ps + sum(1.0 for k in qk if k in s.lower()) + _kind(q, s) + (0.5 if i < 3 else 0.0)
169
+ if sc > best[0]:
170
+ best = (sc, s, title)
171
+ found_kind = _hard(q, s) > 0
172
+ if best[1] and (not typed or found_kind):
173
+ break # the intro held an answer of the right kind
174
+ return best[1], best[2]
175
+
176
+ # ------------------------------------------------------------------ the loop
177
+ def ask(message: str, tools: bool = True, show: bool = False) -> str:
178
+ convo = f"<tools:{'on' if tools else 'off'}>\n<user>\n{message.strip()}\n<|eot|>\n<loom>\n"
179
+ first = loom(convo)
180
+ m = LOOKUP.search(first)
181
+ if not m:
182
+ return first
183
+ query = m.group(1).strip()
184
+ try:
185
+ result, source = find(query, message)
186
+ except Exception as e:
187
+ # Never feed an error in as if it were a result — the model will answer from it.
188
+ return f"[harness] lookup failed for {query!r}: {e}"
189
+ if not result:
190
+ return f"[harness] nothing found for {query!r}"
191
+ if show:
192
+ print(f" [searched: {query!r}]\n [read from {source}: {result[:150]}]")
193
+ return loom(convo + first + f"<|eot|>\n<result>\n{result}\n<|eot|>\n<loom>\n", n=48)
194
+
195
+ def main() -> int:
196
+ global MODEL
197
+ ap = argparse.ArgumentParser(description="Loom Spark 3.2 harness")
198
+ ap.add_argument("message", nargs="*")
199
+ ap.add_argument("--no-tools", action="store_true", help="chat only, no lookups")
200
+ ap.add_argument("--show", action="store_true", help="print the query and the sentence read")
201
+ ap.add_argument("--model", default=MODEL)
202
+ a = ap.parse_args()
203
+ MODEL = a.model
204
+ if a.message:
205
+ print(ask(" ".join(a.message), not a.no_tools, a.show)); return 0
206
+ print(f"Loom harness — {MODEL} (tools {'off' if a.no_tools else 'on'}, ctrl-c to quit)\n")
207
+ while True:
208
+ try:
209
+ msg = input("you > ").strip()
210
+ except (EOFError, KeyboardInterrupt):
211
+ print(); return 0
212
+ if msg:
213
+ print(f"loom > {ask(msg, not a.no_tools, a.show)}\n")
214
+
215
+ if __name__ == "__main__":
216
+ sys.exit(main())
logo.jpg ADDED

Git LFS Details

  • SHA256: ff08fcdc704cbf2295c899e553d15689a4fb18fc58d1cfd2a44f0c886a9617a1
  • Pointer size: 132 Bytes
  • Size of remote file: 2.37 MB
loom-spark-3.2-f16.gguf ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:8ddd228da9b2ccc9e5ea52c0dadb5338602543b2dd938d33bc3273c4f16dd85c
3
+ size 45820576
model.safetensors ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:eb9320e1e65ea4ee905b63e57da9fe303bea2a4c5e29ef178f494caa0d79f422
3
+ size 91331168
params ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "stop": ["<|eot|>", "<user>", "<result>"],
3
+ "temperature": 0.7,
4
+ "top_k": 40,
5
+ "repeat_penalty": 1.0,
6
+ "num_predict": 128,
7
+ "num_ctx": 2048
8
+ }
special_tokens_map.json ADDED
@@ -0,0 +1,13 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "eos_token": "<|eot|>",
3
+ "pad_token": "<|pad|>",
4
+ "additional_special_tokens": [
5
+ "<tools:on>",
6
+ "<tools:off>",
7
+ "<user>",
8
+ "<loom>",
9
+ "<result>",
10
+ "<lookup>",
11
+ "</lookup>"
12
+ ]
13
+ }
template ADDED
@@ -0,0 +1,5 @@
 
 
 
 
 
 
1
+ <tools:off>
2
+ <user>
3
+ {{ .Prompt }}
4
+ <|eot|>
5
+ <loom>
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,16 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "tokenizer_class": "PreTrainedTokenizerFast",
3
+ "model_max_length": 768,
4
+ "eos_token": "<|eot|>",
5
+ "pad_token": "<|pad|>",
6
+ "additional_special_tokens": [
7
+ "<tools:on>",
8
+ "<tools:off>",
9
+ "<user>",
10
+ "<loom>",
11
+ "<result>",
12
+ "<lookup>",
13
+ "</lookup>"
14
+ ],
15
+ "clean_up_tokenization_spaces": false
16
+ }