--- tags: - gguf - llama.cpp - unsloth - smollm2 - json-extraction - data-extraction language: - en license: apache-2.0 base_model: HuggingFaceTB/SmolLM2-360M --- # 🎓 SmolLM2-360M-Assignment-Metadata-Extractor (GGUF) This is a highly specialized, lightweight (360M parameter) model fine-tuned specifically to extract student metadata from chaotic, noisy assignment text and output it as strictly formatted JSON. It was finetuned and converted to 4-bit GGUF format using [Unsloth](https://github.com/unslothai/unsloth) for maximum CPU/GPU efficiency and rapid deployment via Ollama or `llama.cpp`. **Github Repo**: *https://github.com/nmdra/Assignment-Metadata-Extractor* ## 📌 Model Capabilities Unlike generic LLMs, this model has been purposefully overfit on a highly mutated dataset to act as a **Zero-Shot Data Extractor**. It excels at: - **Noise Filtering:** Completely ignoring conversational filler, apologies, word counts, formatting artifacts, and academic instructions. - **Handling Chaos:** Robust against typos (e.g., "Stuednt No"), varied capitalization, and unpredictable line breaks. - **Strict JSON Output:** Trained to output ONLY a valid JSON object with zero conversational preamble (no "Here is the JSON..."). ### Expected Output Schema The model will exclusively output data in the following JSON structure: ```json { "student_number": "...", "student_name": "...", "assignment_number": "..." } ```` ----- ## 🚀 Deployment & Usage Because this model was trained with a specific instruction template, it performs best when wrapped in an environment that enforces **Temperature 0** and matches the training prompt. ### Method 1: Using Ollama (Recommended for standard usage) Create a `Modelfile` with the following configuration to enforce the correct prompt template and prevent creativity: ```text FROM hf.co/nimendraai/SmolLM2-360M-Assignment-Metadata-Extractor:Q4_K_M TEMPLATE """### Instruction: Extract student info as JSON from the following text. ### Input: {{ .Prompt }} ### Response: """ SYSTEM """ You are a precise student assignment data extractor. Output ONLY a valid JSON object. No explanation. No extra text. No markdown. Always output exactly: {"student_number":"...","student_name":"...","assignment_number":"..."} """ PARAMETER temperature 0 PARAMETER stop "}" ``` **Build and Run:** ```bash ollama create json-extractor -f Modelfile ollama run json-extractor "Course: CS101 \n Stuednt No=20210088 \n Full Nme: Nimal Silva \n HW No.-03 \n Please grade fairly!" ``` ### Method 2: Python using Outlines (For bulletproof JSON validation) For production environments where `json.JSONDecodeError` is entirely unacceptable, use this model with `outlines` and `llama-cpp-python` to structurally constrain the output tokens. ```python import outlines from pydantic import BaseModel class StudentExtraction(BaseModel): student_number: str student_name: str assignment_number: str # Load the GGUF model model = outlines.models.llamacpp( "hf.co/nimendraai/SmolLM2-360M-Assignment-Metadata-Extractor:Q4_K_M", device="cpu" # or "cuda" ) # Constrain the generator to the Pydantic schema generator = outlines.generate.json(model, StudentExtraction) # Format the prompt exactly as trained prompt = ( "### Instruction:\nExtract student info as JSON from the following text.\n\n" "### Input:\nStu. ID: 20210088 | Full Name: Nimal Silva | HW-3\n\n" "### Response:\n" ) result = generator(prompt) print(result.model_dump_json()) ``` ----- ## 🧠 Training Details - **Base Model:** `HuggingFaceTB/SmolLM2-360M` - **Dataset:** 1,250 highly varied synthetic examples containing realistic human errors, markdown noise, and distractor text. - **Epochs:** 5 (Optimized to achieve a loss \< \~0.40 to prevent hallucinations). - **Framework:** Trained efficiently using LoRA (Low-Rank Adaptation) via Unsloth. - **Quantization:** Exported to `Q4_K_M` GGUF format to reduce memory footprint to \~270MB. --- This was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth) [](https://github.com/unslothai/unsloth)