File size: 10,163 Bytes
05c768b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "0d698d75",
   "metadata": {},
   "source": [
    "# 0 · What changed when Slayer learned poetry?\n",
    "\n",
    "Start with behavior, then learn how to change it. Regular **Slayer1B-1.09** is a base continuation model; **Slayer1B-Poetry** is a raw-poem CPT LoRA adaptation. This notebook displays all three recorded matched sample pairs without loading weights or renting a GPU.\n",
    "\n",
    "This series uses native Slayer PyTorch code, not Transformers/PEFT wrappers. Next: [CPT](01_cpt.ipynb), [SFT](02_sft.ipynb), [RL](03_rl.ipynb)."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "644f4675",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-18T03:45:49.184826Z",
     "iopub.status.busy": "2026-11-18T03:45:49.184751Z",
     "iopub.status.idle": "2026-11-18T03:45:49.187533Z",
     "shell.execute_reply": "2026-11-18T03:45:49.187150Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Dependencies already installed for validation\n"
     ]
    }
   ],
   "source": [
    "%pip -q install \"torch>=2.4\" \"huggingface_hub>=0.26\" \"tokenizers>=0.20\" \"pydantic>=2\" numpy tqdm\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "9cb422db",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-18T03:45:49.188560Z",
     "iopub.status.busy": "2026-11-18T03:45:49.188492Z",
     "iopub.status.idle": "2026-11-18T03:45:49.774788Z",
     "shell.execute_reply": "2026-11-18T03:45:49.774330Z"
    }
   },
   "outputs": [],
   "source": [
    "from pathlib import Path\n",
    "import sys, json\n",
    "from huggingface_hub import snapshot_download\n",
    "ROOT = Path(snapshot_download(\"SlayerLab/Slayer1B-Poetry\", allow_patterns=[\n",
    "    \"common.py\", \"lora.py\", \"recipe.json\", \"tokenizer.json\",\n",
    "    \"tutorials/slayer_training.py\", \"baseline-samples.json\", \"samples.json\", \"result.json\"\n",
    "]))\n",
    "sys.path.insert(0, str(ROOT))\n",
    "sys.path.insert(0, str(ROOT / \"tutorials\"))\n",
    "from slayer_training import Workshop, Config, form_reward\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "f610a058",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-18T03:45:49.776178Z",
     "iopub.status.busy": "2026-11-18T03:45:49.776056Z",
     "iopub.status.idle": "2026-11-18T03:45:49.780806Z",
     "shell.execute_reply": "2026-11-18T03:45:49.780459Z"
    }
   },
   "outputs": [
    {
     "data": {
      "text/markdown": [
       "### Opening: `The night`"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "REGULAR SLAYER:\n",
      "The night-crawlers of the genus Trapezias are crustaceans that spend almost all of their life lives in burrows that they excavate. At night the crustaceans feed on insects they can hide under objects and in crevices. Most species are nocturnal, but there is also one day-time dwelling species with an unusual behaviour: it does not burrow at all during the daytime, and wakes up in the morning to res\n",
      "\n",
      "POETRY ADAPTER:\n",
      "The night-crowd of the streets\n",
      "Foamed and frothed to and fro;\n",
      "And many a wiry streetman in white was shaded\n",
      "By the flurry: all he felt had been washed with his blood.\n",
      "\n",
      "And lo, the sun had risen; yet still\n",
      "His smile seemed sad, with no change in his eyes for sorrow\n",
      "— Thrust from behind, and backward again,\n",
      "He heard his old\n",
      "\n"
     ]
    },
    {
     "data": {
      "text/markdown": [
       "### Opening: `On the shore`"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "REGULAR SLAYER:\n",
      "On the shore of a lake or in a river, there are numerous plant communities. There could be grasses on the surface or sedges on the bottom. Mosses and the mushrooms that grow from them add colour to the scene and may attract some insects. If you look closely, there usually is some sort of creature beneath the vegetation too; often they can’t see because it is below the water level, but if your eyes are sufficiently sharp, you will spot an occasional\n",
      "\n",
      "POETRY ADAPTER:\n",
      "On the shore of a deep bay.\n",
      "It's a lonely island;--\n",
      "The island is small.\n",
      "\n"
     ]
    },
    {
     "data": {
      "text/markdown": [
       "### Opening: `A small bird`"
      ],
      "text/plain": [
       "<IPython.core.display.Markdown object>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    },
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "REGULAR SLAYER:\n",
      "A small bird with a short tail. The red-winged Blackbird is a popular game bird and is found wherever there are people. Often they will be seen in backyards, fields or woodland edge all over the world, but is equally at home in farmland fields, forest margins and shrubby areas. It has small grey/brown body, yellowish eyes on a green black background, yellow wing patches, and a white patch above its chest and a red\n",
      "\n",
      "POETRY ADAPTER:\n",
      "A small bird that went forth\n",
      "And sang from its nest so long\n",
      "It was not a song of woe,\n",
      "Nor a warlike tirpe’r the same.\n",
      "\n",
      "Shared sampling: {'temperature': 1.0, 'top_k': 50, 'repetition_penalty': 1.1, 'seed': 1234, 'max_new_tokens': 96}\n"
     ]
    }
   ],
   "source": [
    "from IPython.display import display, Markdown\n",
    "base = json.loads((ROOT / \"baseline-samples.json\").read_text())\n",
    "poetry = json.loads((ROOT / \"samples.json\").read_text())\n",
    "for b, p in zip(base, poetry):\n",
    "    assert b[\"opening\"] == p[\"opening\"]\n",
    "    display(Markdown(f\"### Opening: `{b['opening']}`\"))\n",
    "    print(\"REGULAR SLAYER:\\n\" + b[\"text\"])\n",
    "    print(\"\\nPOETRY ADAPTER:\\n\" + p[\"text\"] + \"\\n\")\n",
    "print(\"Shared sampling:\", {k: base[0][k] for k in [\"temperature\", \"top_k\", \"repetition_penalty\", \"seed\", \"max_new_tokens\"]})"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "95d131bb",
   "metadata": {},
   "source": [
    "## Read the samples critically\n",
    "\n",
    "The parent produces descriptive prose for all three openings; the adapter produces lineated verse. Look for imagery, coherence, repetition, natural phrasing and whether the ending resolves. In the bird sample, “tirpe’r” is a clear defect. The shore sample is short and plain. Line breaks show a style shift; they do not prove better literature.\n",
    "\n",
    "These prompts were existing run diagnostics. They are not a blinded preference study. Both sides used temperature 1, top-k 50, repetition penalty 1.1, seed 1234, at most 96 new tokens and a 16-token EOS suppression period. Token caps can cut a sentence short."
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "080bf53d",
   "metadata": {
    "execution": {
     "iopub.execute_input": "2026-11-18T03:45:49.782231Z",
     "iopub.status.busy": "2026-11-18T03:45:49.782149Z",
     "iopub.status.idle": "2026-11-18T03:45:49.784141Z",
     "shell.execute_reply": "2026-11-18T03:45:49.783729Z"
    }
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "{\n",
      "  \"processed_tokens\": 37657600,\n",
      "  \"updates\": 2299,\n",
      "  \"selected_update\": 2299,\n",
      "  \"baseline_validation\": {\n",
      "    \"ce\": 3.4131230413913727,\n",
      "    \"perplexity\": 30.35991161803797,\n",
      "    \"tokens\": 65536\n",
      "  },\n",
      "  \"selected_full_validation\": {\n",
      "    \"ce\": 3.289073363389119,\n",
      "    \"perplexity\": 26.818001596520336,\n",
      "    \"tokens\": 827392\n",
      "  },\n",
      "  \"test\": {\n",
      "    \"ce\": 3.2436408333964164,\n",
      "    \"perplexity\": 25.62685521306139,\n",
      "    \"tokens\": 788480\n",
      "  },\n",
      "  \"elapsed_seconds\": 421.2775601008907,\n",
      "  \"peak_allocated_GiB\": 31.86785888671875\n",
      "}\n"
     ]
    }
   ],
   "source": [
    "print(json.dumps(json.loads((ROOT / \"result.json\").read_text()), indent=2))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "af81ebda",
   "metadata": {},
   "source": [
    "## A quality evaluation you can repeat\n",
    "\n",
    "Before training, freeze a separate list of openings spanning nature, urban scenes, dialogue and emotional tones. Keep training authors/texts out of that list. Generate each model with the same prompt list, sampling settings, length limits and several seeds. Hide model identity and randomize left/right order. Score coherence, imagery, fluency, repetition, form and completeness separately. Record ties and failed samples as well as wins. Check suspicious passages against training data before claiming originality.\n",
    "\n",
    "Keep this held-out evaluation out of checkpoint selection and reward design. Report prompt count, seed count, raw outputs and rater agreement; do not turn three demonstrations into a general win rate. Lower validation perplexity is useful supporting evidence, but not a substitute for reader judgment."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.14.7"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}