Plain-English Overview
A Small Language Model, or SLM, is a smaller AI text model that can run locally or on smaller hardware. Instead of building a model from zero, you start with a pretrained model and teach it your style, task, and examples. In this project, the task is: generate Java DTO classes using Lombok, Jakarta Validation, and Swagger annotations.
How the System Works
The project has two model paths. The first path is an immediate Ollama custom model using a Modelfile. The second path is actual LoRA fine-tuning using Hugging Face Transformers, PyTorch, and PEFT.
Step-by-step Tutorial
Windows Terminal Commands
Use these commands in PowerShell or Windows Terminal.
Dataset Format
The training dataset uses JSONL. JSONL means each line is a separate JSON object. For simple causal language model fine-tuning, one common beginner format is a single `text` field that includes the instruction and the answer.
{"text":"### Instruction:\nCreate a Java DTO named OrderRequest.\n\n### Response:\nimport jakarta.validation.constraints.NotBlank;\n..."}
LoRA Explained Simply
Full fine-tuning updates the whole model. That can be expensive. LoRA adds small trainable layers to parts of the model. You train those smaller layers, called adapters. This is faster and uses less memory.
Full Fine-tuning
Updates most or all model weights. Better control, but expensive.
LoRA Fine-tuning
Trains small adapter weights. Good for local experiments and task specialization.
Ollama Custom Model Explained
Ollama lets you run local models and create custom models with a Modelfile. A Modelfile is like a Dockerfile for a model. It can say which base model to use, what system prompt to apply, and what generation parameters to set.
FROM qwen2.5-coder:0.5b
PARAMETER temperature 0.2
PARAMETER top_p 0.9
PARAMETER num_ctx 8192
SYSTEM """
You are JavaDtoSLM...
"""
Troubleshooting
Reference Docs
Use these references when you want to go deeper.