Stop 21 · Build AI Engineer Portfolio ProjectsProjects · 3/8

Fine-Tuned LLM for a Niche Domain

Part of the AI Engineer Roadmap

In short

Prompting gets you far, but some jobs need a model that reliably speaks a domain's language or format. Fine-tuning one and proving it beats the base model is a strong resume signal.

A model fine-tuned (via LoRA/QLoRA) for a specific domain or style — demonstrates you can go beyond prompting when a task genuinely needs it.

The purple blob in a doctor's coat and stethoscope studies a thick medical book beside patient folders.

Think of it like this

From MBBS to specialist

An MBBS doctor already knows the body well. A dermatology specialisation doesn't restart medical school; it adds focused training on skin cases until the doctor spots patterns a GP might miss. Fine-tuning is the same: a general model gets a short, focused course on your domain.

Watch it happen

The build plan

Baseline
Dataset
LoRA train
Compare
Serve

1/5Try the base model with a good prompt first. Score it on 50 held-out examples so you have a number to beat.

The big ideas

What you need to know

Justify why fine-tuning

Fine-tune for style, format or specialised behaviour. For changing facts, RAG is usually the better tool.

Data quality beats quantity

Consistent, correct examples matter more than a huge pile. One bad pattern repeated gets learned too.

LoRA and QLoRA keep it cheap

LoRA trains small add-on matrices. QLoRA also loads the base model in 4-bit so it fits in less memory.

Before and after, in numbers

A table of base vs fine-tuned scores on held-out data is the heart of the project write-up.

See it in code

Walk through the code

python
1from transformers import AutoModelForCausalLM, AutoTokenizer2from peft import LoraConfig, get_peft_model3 4base = "your-small-open-model"   # pick a small open model that fits your GPU5tok = AutoTokenizer.from_pretrained(base)6model = AutoModelForCausalLM.from_pretrained(base)7 8config = LoraConfig(9    r=16, lora_alpha=32, lora_dropout=0.05,10    target_modules=["q_proj", "v_proj"],   # attention layers; names vary by model11    task_type="CAUSAL_LM",12)13model = get_peft_model(model, config)14model.print_trainable_parameters()   # a tiny fraction of the full model

1/3Load a small open model and its tokenizer from the Hugging Face Hub.

Setting up LoRA with Hugging Face PEFT. Train it with the transformers Trainer or TRL's SFTTrainer on your formatted dataset.

Save yourself the pain

Common mistakes

Oops

Fine-tuning first, without measuring how well plain prompting does.

Do this instead

Record a prompted baseline. If fine-tuning can't beat it clearly, say so honestly; that's still a good write-up.

Oops

Testing on examples that were also in the training data.

Do this instead

Split off a held-out set before training and never let it leak in. Otherwise the score means nothing.

Your mission

Milestone one: dataset and baseline

~45 min

Quick check

Your bot must answer from company policies that change every month. What's usually the better first choice?

Go deeper

  1. 1Pick a narrow, well-defined domain where fine-tuning has a clear advantage over prompting.
  2. 2Document your dataset construction process — it's usually the most interesting part to reviewers.
  3. 3Report a clear before/after comparison against the base model.

More projects at this stop

Stuck on this topic? Ask an Insider

Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.

Download
InsideEdge