{ "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": [ "" ] }, "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": [ "" ] }, "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": [ "" ] }, "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 }