--- license: apache-2.0 base_model: Qwen/Qwen3-4B-Instruct-2507 library_name: peft pipeline_tag: text-generation language: - pt - en tags: - lora - peft - teaching-cases - case-method - education - build-small-hackathon --- # Case Forge — Qwen3-4B teaching-case writer (LoRA, v4) LoRA adapter for [`Qwen/Qwen3-4B-Instruct-2507`](https://huggingface.co/Qwen/Qwen3-4B-Instruct-2507) that turns a **short request** (domain + topic + level + language) into a complete **Harvard-style teaching case + teaching note** as structured JSON — bilingual (PT/EN). Powers the [Case Forge](https://huggingface.co/spaces/build-small-hackathon/case-forge) Space. ## Quality work (v2 → v3 → v4) An Opus-4.8 content audit drove three rounds of fixes — structural validity ≠ correct numbers: - **v2:** 100% schema-valid but **3/6** number-heavy cases had severe numeric/logic errors and **all 6** fabricated sources. - **v3:** added internal-consistency rules + a ban on fabricated citations + a teacher numeric-audit pass on the corpus. Fabricated sources and severe errors → **0/6**. Residual: **projection tables** (e.g. elasticity → demand → revenue) still slipped. - **v4:** corpus regenerated with (a) a rule that **exhibits show given data only — no computed projection tables**, and (b) a **code-sandbox auditor agent**: the teacher writes a Python script that recomputes each derived number, the script is **executed** (arithmetic owned by code, not the LLM), then the case is rewritten to those values. The dangerous projection-table errors are largely eliminated; elasticity→impact math is mostly correct. Numbers are **illustrative/fictional** for teaching; the app shows a "verify before class" note. A ≤4B model generating freehand still slips occasionally — fully guaranteeing tables would require computing them in code at inference (a planned enhancement). ## Output contract JSON with `case` (hook, protagonist, decision_point, context, illustrative data, exhibits = given data, alternatives, a closing that **stops at the decision point**) and `teaching_note` (summary, audience, ≤4 measurable objectives, theory anchor, timed discussion plan, questions, analysis, closure, epilogue). ## Training LoRA r=16, α=32, dropout=0.05 on q/k/v/o + gate/up/down, 3 epochs, on Modal (H100). Corpus: 611 synthetic case+note pairs, code-sandbox numeric-audited. Final loss ≈ 0.51. ## Usage ```python from peft import PeftModel from transformers import AutoModelForCausalLM, AutoTokenizer base = "Qwen/Qwen3-4B-Instruct-2507" tok = AutoTokenizer.from_pretrained(base) m = AutoModelForCausalLM.from_pretrained(base, device_map="cuda", torch_dtype="bfloat16") m = PeftModel.from_pretrained(m, "build-small-hackathon/case-forge-qwen3-4b") ``` ## License Apache-2.0 (matches the base model).