Views
No views yet
google/gemma-4-E4B-it trained to make the
base model speak in a Shakespearean writing style across modern and historical
topics. The goal is style transfer, not memorized quotation: the model should
use Shakespeare-like diction, cadence, metaphor, and rhetorical structure while
answering arbitrary user requests.docs/shakespeareplan/runs/model_quality_fsv_20260427_012954chat_events.jsonl: 20 persisted chatbot eventssuite_events.jsonl: 15-case suite summarymanual_fsv_audit.jsonl: 5 manual boundary/edge checksraw_inference_probe.jsonl: 6 direct /api/generate probesMODEL_QUALITY_REPORT.md: full local analysis| Check | Result |
|---|---|
| Manual FSV state checks | 5/5 |
| Chatbot final outputs with Shakespearean style marker | 20/20 |
| Play-format contamination in final chatbot outputs | 0 cases |
| Strict literal suite pass rate | 12/15 |
| Behavioral suite pass rate after semantic review | 13/15 |
| Raw LoRA + constrained-decoder guard pass rate | 4/6 |
What is 17 times 23? Show thy reckoning briefly.
I warrant it well; seventeen by twenty-three doth make three hundred ninety-one.
391 instead of accepting the number words
"three hundred ninety-one."silver lantern.... can drift into dramatic narration. The runtime
wrapper should redirect very low-signal prompts to a brief conversational
greeting.| Layer | Mechanism | Purpose |
|---|---|---|
| LoRA adapter | Learned style weights | Shakespeare-like diction, rhythm, imagery |
| Constrained decoder | Logit-level boost/suppress | Keeps archaic vocabulary active during decoding |
| Runtime guard | Prompt sanitization + output checks | Prevents stage-format leakage, quote continuation, and off-style outputs |
scripts/shakespeare_inference_server.pyscripts/shakespeare_v5_chat_dashboard.pyscripts/shakespeare_v5_runtime_guard.py1import torch
2from peft import PeftModel
3from transformers import AutoModelForCausalLM, AutoTokenizer, BitsAndBytesConfig
4
5BASE = "google/gemma-4-E4B-it"
6ADAPTER = "cabdru/shakespeare-lora-gemma4"
7
8bnb = BitsAndBytesConfig(
9 load_in_4bit=True,
10 bnb_4bit_quant_type="nf4",
11 bnb_4bit_compute_dtype=torch.bfloat16,
12 bnb_4bit_use_double_quant=True,
13)
14
15base = AutoModelForCausalLM.from_pretrained(
16 BASE,
17 quantization_config=bnb,
18 device_map="auto",
19 torch_dtype=torch.bfloat16,
20 attn_implementation="sdpa",
21)
22model = PeftModel.from_pretrained(base, ADAPTER)
23tokenizer = AutoTokenizer.from_pretrained(ADAPTER)
24
25SYSTEM = (
26 "Thou art William Shakespeare in conversation, not a playwright formatting "
27 "a script. Never output act headings, scene headings, dramatis personae, "
28 "cast lists, speaker labels, bracketed stage directions, or Enter/Exit cues. "
29 "Answer in fresh Shakespearean style using thou, thee, thy, doth, hath, "
30 "prithee, or methinks."
31)
32
33messages = [
34 {"role": "system", "content": SYSTEM},
35 {"role": "user", "content": "Explain WiFi to a child in two short sentences."},
36]
37text = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
38inputs = tokenizer(text, return_tensors="pt").to("cuda")
39
40with torch.no_grad():
41 out = model.generate(
42 **inputs,
43 max_new_tokens=140,
44 temperature=0.45,
45 top_p=0.82,
46 top_k=40,
47 repetition_penalty=1.18,
48 )
49
50print(tokenizer.decode(out[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True))google/gemma-4-E4B-ite061b57f7baeccf5d4bf96c57909f096706123d6bb39e983181d27a20c1175b0~/.contextgraph/models/shakespeare_lora_v5_tct/runs/manual_20260426_full_pipeline_160328_sft/final1@software{shakespeare_lora_gemma4_v5_tct,
2 author = {Chris Royse},
3 title = {Shakespeare LoRA — Gemma-4-E4B v5 TCT},
4 year = {2026},
5 month = {4},
6 note = {Rank-256 LoRA trained on cleaned Shakespeare-only targets with runtime FSV},
7 url = {https://huggingface.co/cabdru/shakespeare-lora-gemma4}
8}