2 Getting started with fine-tuning: A few examples
After introducing the value of specialization, the chapter moves quickly from theory to practice by showing how a general model falls short on a concrete finance task: credit risk assessment. It demonstrates that while broad models can calculate ratios and produce reasonable explanations, they often miss organization-specific thresholds, required formatting, and compliance-ready decision logic. This makes them useful as a baseline, but not dependable enough for real underwriting workflows that demand consistency, transparency, and institutional alignment.
The core of the chapter is the end-to-end fine-tuning workflow, starting with dataset design and then moving through efficient model adaptation. The dataset must be structured so that inputs are consistent and outputs are explainable, pairing applicant profiles or financial documents with labeled decisions or summaries. To make training practical, the chapter uses parameter-efficient methods such as LoRA, along with tools like Unsloth and TRL’s trainer, to adapt an open-source model without retraining every weight. The examples emphasize formatting prompts carefully, selecting an appropriate foundation model, and using efficient training settings that fit on limited hardware.
The chapter also broadens fine-tuning into a reusable mental model: choose a strong base model, prepare high-quality data, train carefully, and evaluate rigorously, looping back when results reveal gaps. It stresses that specialization is iterative rather than linear, and that data quality, label consistency, and domain fit matter as much as the training code. Beyond the first example, it shows how modular adapters can be swapped across tasks and how fine-tuned models can be deployed locally for privacy and control, reinforcing the idea that fine-tuning turns a general language model into a practical, domain-specific decision or summarization system.
A screenshot from Hugging Face (https://huggingface.co/datasets/bongpheng/credit_risk_ds_100k)
LoRA adapter swapping for different domains or use cases. A single frozen foundation model serves as the shared backbone for multiple lightweight domain adapters. Each adapter adds a small set of trainable weights alongside the frozen layers — less than 0.1% of the base model's parameters — and can be swapped in or out without modifying the underlying model.
The fine-tuning process mental model. After the evaluation we can come back to any of the previous steps depending on the results. The evaluation sometimes can be conducted directly in production after the deployment, measuring the quality on real use case with real users.
Summary
- Generic models fail at precision-demanding business tasks not from lack of capability but from lack of institutional alignment. They can’t apply organization-specific risk thresholds, follow internal compliance requirements, or generate outputs in the structured formats that operational systems require. This makes them unsuitable for production financial workflows without specialization.
- Dataset quality determines specialization success. Fine-tuning requires structured inputs (consistent numerical and categorical data) paired with explainable outputs (transparent reasoning trails showing intermediate calculations and decision logic). This dual requirement ensures models don’t just pattern-match but internalize the analytical processes that domain experts follow.
- Modern fine-tuning uses parameter-efficient techniques such as LoRA (Low-Rank Adaptation). These techniques train small, specialized adapter modules while keeping the base model weights frozen. This modular approach lets you maintain a single foundation model with swappable adapters for different domains, dramatically reducing storage costs and enabling rapid experimentation.
- The systematic four-step fine-tuning process forms a practical mental model: (1) select foundation models with domain exposure to reduce the teaching effort, (2) prepare datasets through iterative cleaning and labeling cycles, (3) execute training with efficient techniques, and (4) evaluate rigorously against predefined quality thresholds; steps 2 and 4 form a natural feedback loop that most successful projects cycle through multiple times.
- Foundation model selection requires evaluating both task performance (can it do the type of work?) and domain knowledge (does it understand the subject matter?). Models pretrained on domain-relevant corpora (like BioGPT for medical texts) require significantly less fine-tuning data and compute to achieve expert-level performance than generic models that must learn specialized knowledge from scratch.
- Professional dataset creation combines synthetic generation with human verification: existing models generate initial labels at scale, then domain experts verify accuracy, refine phrasing, and eliminate hallucinations. This hybrid approach achieves both the volume needed for effective training and the reliability required for high-stakes applications.
FAQ
What is the main goal of fine-tuning in this chapter?
The main goal is to turn a general-purpose LLM into a specialized system that follows domain-specific rules, produces the required output format, and delivers consistent, auditable decisions for tasks like credit risk assessment or financial summarization.
Why is credit risk assessment a good example of fine-tuning?
It is a high-stakes task where generic models may give reasonable advice, but not the precise, organization-specific, compliance-ready assessments needed in production. Fine-tuning helps the model learn thresholds, reasoning patterns, and decision logic used by the institution.
What problems do generic models have when assessing credit risk?
They can produce inconsistent risk classifications, offer generic recommendations instead of actionable decisions, and fail to align with institutional terminology, thresholds, and workflows.
What should a fine-tuning dataset contain for credit risk assessment?
The dataset should contain structured inputs such as income, debt obligations, credit score, and late payments, along with explainable outputs that include both the risk label and a reasoning trail showing how the decision was made.
Why is explainability important in supervised fine-tuning for finance?
Because financial decisions must be defensible to auditors, regulators, internal stakeholders, and sometimes borrowers. Training on both the answer and the reasoning helps the model produce transparent, traceable outputs.
What is LoRA and why is it used in fine-tuning?
LoRA, or Low-Rank Adaptation, is a parameter-efficient fine-tuning method that trains small adapter modules instead of updating all model weights. It reduces memory and compute requirements while still allowing the model to learn domain-specific behavior.
Why are 4-bit quantization and memory-efficient optimizers useful?
They make fine-tuning feasible on limited hardware by reducing GPU memory usage. Quantization compresses model weights, and optimizers like adamw_8bit reduce training memory overhead.
What is the purpose of the chat prompt template and EOS token?
The chat prompt template gives every example a consistent instruction-input-response structure, and the EOS token tells the model where each training example ends. Together they help the model learn clean boundaries and avoid ambiguous or incomplete patterns.
What are the four steps of the fine-tuning process described in the chapter?
The four steps are: select a foundation model, prepare the dataset, execute training, and evaluate and validate quality. The process is iterative, so evaluation may lead back to dataset refinement.
Why does the chapter emphasize adapter swapping and local inference?
Adapter swapping lets one frozen base model support multiple specialized behaviors without retraining the whole model. Local inference tools like Ollama and LM Studio keep data private, reduce latency, and allow offline use of fine-tuned models.
Building Specialized AI Systems ebook for free