20 Downloads Updated 1 month ago
ollama run gaurav-aiml/edulora
Updated 1 month ago
1 month ago
e19708c011b5 · 1.2GB
Fine Tuining is an end-to-end educational fine-tuning project built around Qwen/Qwen3-0.6B. It is designed to turn educational PDF material into a locally runnable AI study assistant. The pipeline accepts PDFs containing content from areas such as philosophy, mathematics, computer science, and physics, extracts the text, cleans and normalizes it, converts it into supervised chat-style examples, tokenizes those examples with the Qwen3 chat template, fine-tunes the base model using PEFT/LoRA on CPU, merges the adapter with the base model, and prepares the result for deployment through Ollama.
The goal of this project is not to build a replacement for a teacher, textbook, or verified academic source. Instead, it is a practical demonstration of how a very small language model can be specialized for educational explanation tasks on modest hardware. Qwen3-0.6B is lightweight, fast, and easy to run locally, which makes it useful for experimentation, offline study support, and understanding the full lifecycle of a fine-tuned model: data extraction, dataset construction, tokenization, training, evaluation, merging, conversion, and local deployment.
A key clarification for this project is the model identity. This project uses Qwen/Qwen3-0.6B. The earlier label qwen3.5:0.8b was inaccurate. The trained checkpoint is Qwen3-0.6B, not Qwen3.5-0.8B. This distinction matters for reproducibility, evaluation, and anyone comparing the model against other checkpoints.
At a high level, the project performs the following work:
The project is deliberately transparent. Every major stage produces an artifact that can be inspected, rebuilt, or replaced. The PDFs are treated as source inputs, while the raw, cleaned, processed, tokenized, adapter, merged, and GGUF outputs are generated artifacts. Most of these generated files are excluded from Git because they can be rebuilt from the original PDFs, though rebuilding may take time, disk space, or network access.
The data pipeline has four preparation stages followed by CPU fine-tuning.
PDF extraction
PDFs placed in the input directory are read and converted into page-level JSON. This preserves the connection between extracted text and its source page, which is useful for metadata and later review.
Text cleaning
The extracted JSON is normalized. Paragraphs are cleaned and standardized so that the later dataset stage receives more consistent text.
Training dataset creation
Cleaned page text is split into paragraphs. Very short paragraphs are skipped, and the remaining text is converted into JSONL chat examples. Each example contains a user message and an assistant message.
Tokenization
The configured model tokenizer is applied to the chat examples. The Qwen3 chat template is used, and each example is truncated to a short maximum sequence length. The tokenized dataset is cached so training can consume it efficiently.
Fine-tuning
The base model is loaded and trained with a PEFT LoRA adapter. The adapter is saved, then merged with the base model to produce a complete Hugging Face model directory.
Evaluation
The merged model can be scored on held-out JSONL examples. The evaluator reports likelihood-based metrics and exact-match generation metrics, and it saves predictions for qualitative review.
Deployment preparation
The merged model can be converted to GGUF format and imported into Ollama. The included Modelfile is intended to point at the converted GGUF model.
Each generated training record follows a chat-style structure with a user message, an assistant message, and metadata. The user message asks the model to explain a piece of educational content clearly. The assistant target is the same paragraph that was used to build the example.
This means the training objective is primarily a basic reconstruction task. The model learns to reproduce or restate educational paragraphs in a helpful explanatory format. This is useful for teaching tone, formatting, and paragraph-level explanation behavior, but it does not create independent question-answer pairs, and it does not verify factual accuracy.
For a stronger educational assistant, the dataset would need to be redesigned. Instead of copying paragraphs, a better dataset might include:
Because the current dataset is paragraph-based, users should review the generated examples before training if they want a different learning objective.
Training is intentionally configured for CPU-only use. This makes the project accessible on machines without a dedicated GPU, but it also means training is slow and sensitive to available memory.
The training configuration uses:
This setup reduces memory pressure, but it does not eliminate the risk of an operating-system out-of-memory kill. If the training process is terminated with Killed, it is usually because the system ran out of memory. On memory-constrained machines, increasing sequence length or batch size is not recommended.
Evaluation must use examples that were not included in the model’s training data. The current project does not automatically create a held-out split, so a separate evaluation file is needed. That file should use the same message format as the training data and should end with a reference assistant answer.
The evaluator can report:
Exact match is a strict copying metric. It is not a measure of semantic equivalence, and it should not be treated as a complete measure of educational quality. Perplexity should also be interpreted carefully because this project’s training objective is paragraph reconstruction rather than open-ended question answering.
A useful comparison is to evaluate both the fine-tuned model and the original base checkpoint on the same held-out file. This helps show whether fine-tuning improved the desired behavior or simply changed the model’s output style.
Successful training and preparation can produce:
The LoRA adapter alone is not a complete model. It must be merged with the base model before conversion and deployment. The merged model is the correct source for GGUF conversion.
Generated model files, tokenized datasets, and intermediate outputs are generally excluded from Git. The original PDFs are source inputs and should not be treated as disposable build output. If generated artifacts are deleted, they can usually be rebuilt, but rebuilding may require significant time, memory, disk space, or network access.
Deployment is intended to happen through Ollama. Ollama imports GGUF models, and the included Modelfile is designed to point at the converted GGUF file. The model can then be run locally and, if desired, published under an Ollama account so other users can pull it.
On Windows, importing a Safetensors directory directly into Ollama may fail because Ollama can report that the MLX runtime is unavailable. In that case, the correct approach is to convert the merged Hugging Face model to GGUF first and point the Modelfile at the resulting .gguf file. Ollama imports GGUF as provided, so the conversion step is important for Windows compatibility.
Ollama’s local API is available while its service is running, which allows the model to be used by local applications in addition to the command-line interface.
This project is intended for:
It is not intended for:
Because Qwen3-0.6B is very small, it has limited reasoning capacity and may hallucinate. Fine-tuning on educational paragraphs can improve style and formatting, but it does not guarantee factual accuracy. For stronger results, the model should be combined with retrieval-augmented generation, calculators, Python execution, or other external tools.