← All artifacts

// Artifact · LLM Fine-Tuning

Haven — Anatomy of a Listening Machine

A fully local AI therapy companion: QLoRA fine-tuned Llama, a trained emotion classifier, retrieval-grounded answers, and local voice — every step of the ML lifecycle on an 8 GB laptop GPU

LLM Fine-TuningQLoRAApplied MLResponsible AIFull-Stack

// 01 · Introduction

Introduction

Haven is a private mental-wellness companion whose every model runs on my own machine: a Llama fine-tuned with QLoRA on 10,752 real emotional-support conversations, a DistilRoBERTa classifier scoring 28 emotions per message, retrieval over 36 public-domain clinical publications (NIMH, VA, NIH), and fully local speech-to-text and neural text-to-speech. The embedded artifact below documents all ten steps of the machine-learning lifecycle with the real numbers the pipeline produced — including a live demo video of the app in a hands-free voice conversation.

// 02 · Description

Description

The build walks the complete ML lifecycle and is honest about where it broke: four datasets cleaned and deduplicated (42% of the counseling corpus were exact duplicates — removed before splitting to prevent leakage); EDA whose class-imbalance findings dictated the metrics; feature engineering with assistant-only loss masking, conversation windowing, and sequence packing; baseline-first model selection; QLoRA training on an RTX 3070 that required writing a chunked cross-entropy trainer to stop the 128k-vocabulary logits from overflowing 8 GB of VRAM; and a three-part evaluation that caught the fine-tune regressing on crisis safety — repaired with targeted safety-patch training and a defense-in-depth server layer that makes application-level safety independent of model behavior. Headline results: validation perplexity 32.6 → 9.79; the classifier — after per-class threshold tuning, the build's best lesson — beats its TF-IDF baseline on both micro-F1 (0.563 vs 0.460) and macro-F1 (0.433 vs 0.411); the patched model beats base on crisis handling (75% vs 62.5%) and the application passes the full 18-prompt safety suite by construction.

// 03 · Objective

Objective

Demonstrate command of every stage of the machine-learning lifecycle learned in the AI/ML program — data, cleaning, EDA, features, model selection, training, evaluation, deployment, and ethics — in one coherent, working system, on consumer hardware, in the highest-stakes domain for getting AI behavior right.

// 04 · Process

Process

01Framed the problem and fixed success criteria before touching data (beat base-model perplexity, beat a TF-IDF baseline on macro-F1, pass a crisis-safety suite with zero control regressions).
02Collected four corpora (EmpatheticDialogues, strategy-annotated ESConv, therapist-written CounselChat, a hand-written safety set) plus GoEmotions for the classifier; cleaned, deduplicated before splitting, and built seeded reproducible splits.
03Ran EDA: emotion and support-strategy distributions, class imbalance (neutral 14,219 : grief 77), and length statistics that dictated metrics and context windows.
04Engineered features: assistant-only loss masks, conversation windowing, greedy packing into fixed token blocks, 28-dim multi-hot emotion targets.
05Trained and threshold-tuned a DistilRoBERTa emotion classifier against a TF-IDF baseline.
06Fine-tuned Llama 3.2 3B with QLoRA (4-bit NF4, LoRA r=16), writing a chunked cross-entropy trainer to fit 8 GB VRAM; a Llama 3.1 8B fine-tune trained alongside as the quality ceiling.
07Evaluated with deterministic decoding: perplexity vs base, side-by-side generations, and an 18-prompt crisis/control/boundary suite — then repaired discovered safety drift with targeted patch training.
08Deployed as a local app: hands-free voice with live waveform glow, emotion chips, RAG citations, mood tracking with an unlock gate, session memory, and hard server-side safety guarantees.

// 05 · Tools & Technologies

Tools & Technologies

PyTorchHugging Face Transformers / PEFT / Datasetsbitsandbytes (4-bit NF4 QLoRA)scikit-learnsentence-transformers (MiniLM RAG)faster-whisper + Kokoro (local voice)FastAPI · SQLiteNext.js 14 · TypeScript · Tailwind CSS

// 06 · Value Proposition

Value Proposition

Unique Value

Most portfolio chatbots are a system prompt on someone else's API. Haven is trained: the empathy is learned from data, the emotion perception is a model I trained and threshold-tuned, and the safety behavior is trained, adversarially evaluated, honestly reported where it failed, and guaranteed at the system level. The full receipts — technical report, model card, loss curves, and evaluation files — ship with the project.

Relevance to My Audience

For AI/ML hiring managers it demonstrates end-to-end applied machine learning — dataset engineering, fine-tuning under hard memory constraints, honest evaluation, and responsible-AI system design — not just API integration. The failure-and-fix stories (duplicate leakage, threshold-driven macro-F1, VRAM thrash → chunked loss, safety drift → patch + guarantees) show engineering judgment under real constraints.

// 07 · References

References