nimendraai commited on
Commit
a3ccfec
·
verified ·
1 Parent(s): 96da09b

Add README

Browse files
Files changed (1) hide show
  1. README.md +10 -114
README.md CHANGED
@@ -3,122 +3,18 @@ tags:
3
  - gguf
4
  - llama.cpp
5
  - unsloth
6
- - smollm2
7
- - json-extraction
8
- - data-extraction
9
- language:
10
- - en
11
- license: apache-2.0
12
- base_model: HuggingFaceTB/SmolLM2-360M
13
- ---
14
-
15
- # 🎓 SmolLM2-360M-Assignment-Metadata-Extractor (GGUF)
16
-
17
- 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.
18
-
19
- 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`.
20
-
21
- ## 📌 Model Capabilities
22
-
23
- 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:
24
- - **Noise Filtering:** Completely ignoring conversational filler, apologies, word counts, formatting artifacts, and academic instructions.
25
- - **Handling Chaos:** Robust against typos (e.g., "Stuednt No"), varied capitalization, and unpredictable line breaks.
26
- - **Strict JSON Output:** Trained to output ONLY a valid JSON object with zero conversational preamble (no "Here is the JSON...").
27
-
28
- ### Expected Output Schema
29
- The model will exclusively output data in the following JSON structure:
30
- ```json
31
- {
32
- "student_number": "...",
33
- "student_name": "...",
34
- "assignment_number": "..."
35
- }
36
- ````
37
-
38
- -----
39
-
40
- ## 🚀 Deployment & Usage
41
-
42
- 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.
43
-
44
- ### Method 1: Using Ollama (Recommended for standard usage)
45
-
46
- Create a `Modelfile` with the following configuration to enforce the correct prompt template and prevent creativity:
47
-
48
- ```text
49
- FROM hf.co/nimendraai/SmolLM2-360M-Assignment-Metadata-Extractor:Q4_K_M
50
-
51
- TEMPLATE """### Instruction:
52
- Extract student info as JSON from the following text.
53
-
54
- ### Input:
55
- {{ .Prompt }}
56
-
57
- ### Response:
58
- """
59
 
60
- SYSTEM """
61
- You are a precise student assignment data extractor.
62
- Output ONLY a valid JSON object. No explanation. No extra text. No markdown.
63
- Always output exactly: {"student_number":"...","student_name":"...","assignment_number":"..."}
64
- """
65
-
66
- PARAMETER temperature 0
67
- PARAMETER stop "}"
68
- ```
69
-
70
- **Build and Run:**
71
-
72
- ```bash
73
- ollama create json-extractor -f Modelfile
74
- ollama run json-extractor "Course: CS101 \n Stuednt No=20210088 \n Full Nme: Nimal Silva \n HW No.-03 \n Please grade fairly!"
75
- ```
76
-
77
- ### Method 2: Python using Outlines (For bulletproof JSON validation)
78
-
79
- For production environments where `json.JSONDecodeError` is entirely unacceptable, use this model with `outlines` and `llama-cpp-python` to structurally constrain the output tokens.
80
-
81
- ```python
82
- import outlines
83
- from pydantic import BaseModel
84
-
85
- class StudentExtraction(BaseModel):
86
- student_number: str
87
- student_name: str
88
- assignment_number: str
89
-
90
- # Load the GGUF model
91
- model = outlines.models.llamacpp(
92
- "hf.co/nimendraai/SmolLM2-360M-Assignment-Metadata-Extractor:Q4_K_M",
93
- device="cpu" # or "cuda"
94
- )
95
-
96
- # Constrain the generator to the Pydantic schema
97
- generator = outlines.generate.json(model, StudentExtraction)
98
-
99
- # Format the prompt exactly as trained
100
- prompt = (
101
- "### Instruction:\nExtract student info as JSON from the following text.\n\n"
102
- "### Input:\nStu. ID: 20210088 | Full Name: Nimal Silva | HW-3\n\n"
103
- "### Response:\n"
104
- )
105
-
106
- result = generator(prompt)
107
- print(result.model_dump_json())
108
- ```
109
-
110
- -----
111
-
112
- ## 🧠 Training Details
113
 
114
- - **Base Model:** `HuggingFaceTB/SmolLM2-360M`
115
- - **Dataset:** 1,250 highly varied synthetic examples containing realistic human errors, markdown noise, and distractor text.
116
- - **Epochs:** 5 (Optimized to achieve a loss \< \~0.40 to prevent hallucinations).
117
- - **Framework:** Trained efficiently using LoRA (Low-Rank Adaptation) via Unsloth.
118
- - **Quantization:** Exported to `Q4_K_M` GGUF format to reduce memory footprint to \~270MB.
119
 
120
- ---
121
 
122
- This was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth)
 
 
123
 
124
- [<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)
 
 
 
 
3
  - gguf
4
  - llama.cpp
5
  - unsloth
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
 
7
+ ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
8
 
9
+ # SmolLM2-360M-Assignment-Metadata-Extractor : GGUF
 
 
 
 
10
 
11
+ This model was finetuned and converted to GGUF format using [Unsloth](https://github.com/unslothai/unsloth).
12
 
13
+ **Example usage**:
14
+ - For text only LLMs: `llama-cli -hf nimendraai/SmolLM2-360M-Assignment-Metadata-Extractor --jinja`
15
+ - For multimodal models: `llama-mtmd-cli -hf nimendraai/SmolLM2-360M-Assignment-Metadata-Extractor --jinja`
16
 
17
+ ## Available Model files:
18
+ - `SmolLM2-360M.Q4_K_M.gguf`
19
+ This was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth)
20
+ [<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)