File size: 10,166 Bytes
6533537
ad0ead8
 
6533537
ad0ead8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1b0377a
ad0ead8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0763735
6533537
 
ad0ead8
6533537
ad0ead8
 
 
 
6533537
ad0ead8
 
 
 
 
6533537
ad0ead8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
f1cd762
6533537
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
---
license: mit
base_model: numind/NuExtract-tiny-v1.5
tags:
  - nlp
  - json
  - information-extraction
  - resume-parsing
  - structured-extraction
  - qwen2
  - unsloth
  - lora
  - gguf
  - ollama
  - langchain
language:
  - en
pipeline_tag: text-generation
library_name: transformers
---

# NuExtract-tiny-Resume-Data-Extractor

A fine-tuned version of [numind/NuExtract-tiny-v1.5](https://huggingface.co/numind/NuExtract-tiny-v1.5)
(Qwen2.5-0.5B backbone) specialised for **resume / CV structured extraction**.

Given raw resume text in any format, the model returns a clean JSON object with name,
contact details, skills, work experience, education, and other details β€” ready to plug
into a hiring pipeline, ATS, or LangChain workflow.

![Gemini_Generated_Image_t8vmzet8vmzet8vm.png](https://cdn-uploads.huggingface.co/production/uploads/69e38d3a85cbb38401962a34/CSpI68gEFsI_-ENhHQi6z.jpeg)

## Model Details

| Property | Value |
|---|---|
| Base model | `numind/NuExtract-tiny-v1.5` |
| Backbone | Qwen2.5-0.5B |
| Total parameters | 511,388,160 |
| Trainable (LoRA) | 17,596,416 (3.44%) |
| LoRA rank / alpha | r=32 / alpha=64 |
| Quantisation | Q4_K_M GGUF (Ollama-ready) |
| Vocabulary size | 151,665 (unchanged from base) |
| License | MIT |

---

## Training

| Property | Value |
|---|---|
| Method | QLoRA via Unsloth |
| Dataset | 3,000 synthetic resumes (generated) |
| Train / eval split | 95% / 5% (2,850 / 150) |
| Packed sequences | 1,125 |
| Epochs | 4 |
| Total steps | 284 |
| Batch size | 16 (2 per device Γ— 8 grad accum) |
| Learning rate | 2e-4 (cosine schedule, 14 warmup steps) |
| Hardware | 1Γ— NVIDIA Tesla T4 (Google Colab) |
| Training time | ~24 minutes |

### Loss Curve

| Step | Epoch | Train Loss | Val Loss |
|---|---|---|---|
| 100 | 1.0 | 0.2355 | 0.2354 |
| 200 | 2.8 | 0.2298 | 0.2313 |
| 284 | 4.0 | 0.2276 | 0.2296 |

Near-zero train/val gap throughout β€” no overfitting observed.
Best checkpoint (step 284, val loss 0.2296) loaded automatically.

---

## Output Schema

```json
{
  "name":         "string or null",
  "email":        "string or null",
  "phone":        "string or null",
  "website":      "string or null",
  "skills":       ["string"],
  "experience":   [{"title": "string", "company": "string", "duration": "string"}],
  "education":    [{"degree": "string", "institution": "string", "year": "string"}],
  "other_details": ["string"]
}
```

- Missing scalar fields β†’ `null`
- Missing list fields β†’ `[]`
- `skills` contains technical skills only β€” soft skills excluded
- `other_details` captures certifications, languages, awards, publications

---

## Inference Speed (Ollama, Tesla T4)

| Metric | Value |
|---|---|
| Prompt eval | 161 tokens in ~28ms |
| Generation | 154 tokens in ~2,986ms |
| Total (typical resume) | ~7.5 seconds |
| Throughput | ~52 tokens/sec |

---

## Usage

### Ollama (recommended)

**Step 1 β€” Create Modelfile:**

```dockerfile
FROM hf.co/nimendraai/NuExtract-tiny-Resume-Data-Extractor:Q4_K_M

PARAMETER temperature 0
PARAMETER top_k 10
PARAMETER top_p 0.9
PARAMETER repeat_penalty 1.1
PARAMETER seed 42
PARAMETER num_ctx 2048
PARAMETER num_predict 600
PARAMETER stop "<|end-output|>"
PARAMETER stop "<|endoftext|>"

TEMPLATE """<|input|>
### Template:
{
    "name": "",
    "email": "",
    "phone": "",
    "website": "",
    "skills": [""],
    "experience": [{"title": "", "company": "", "duration": ""}],
    "education": [{"degree": "", "institution": "", "year": ""}],
    "other_details": [""]
}
### Text:
{{ .Prompt }}

<|output|>
"""

LICENSE """Apache License, Version 2.0 - http://www.apache.org/licenses/LICENSE-2.0"""
```

**Step 2 β€” Create model:**

```bash
ollama create agenthire-extractor -f Modelfile
```

**Step 3 β€” Query:**

```bash
curl http://localhost:11434/api/generate \
  -X POST \
  -H "Content-Type: application/json" \
  -d '{
    "model": "agenthire-extractor",
    "format": "json",
    "stream": false,
    "prompt": "<resume text here>"
  }'
```

> Always apply brace-counting extraction on the response value β€” see Python helper below.

---

### Python (transformers)

```python
import json
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer

model_name = "nimendraai/NuExtract-tiny-Resume-Data-Extractor"
model = AutoModelForCausalLM.from_pretrained(
    model_name, torch_dtype=torch.bfloat16, trust_remote_code=True
).eval().cuda()
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)

TEMPLATE = json.dumps({
    "name": "", "email": "", "phone": "", "website": "",
    "skills": [""],
    "experience": [{"title": "", "company": "", "duration": ""}],
    "education":  [{"degree": "", "institution": "", "year": ""}],
    "other_details": [""],
}, indent=4)

def extract_first_json(text):
    depth, start = 0, None
    for i, ch in enumerate(text):
        if ch == "{":
            if start is None: start = i
            depth += 1
        elif ch == "}":
            depth -= 1
            if depth == 0 and start is not None:
                return text[start:i+1]
    return text

def extract(resume_text: str) -> dict:
    prompt = (
        "<|input|>\n"
        f"### Template:\n{TEMPLATE}\n"
        f"### Text:\n{resume_text}\n\n"
        "<|output|>"
    )
    inputs = tokenizer(
        prompt, return_tensors="pt", truncation=True, max_length=2048
    ).to(model.device)
    with torch.no_grad():
        out = model.generate(
            **inputs, max_new_tokens=512, do_sample=False
        )
    decoded = tokenizer.decode(out[0], skip_special_tokens=True)
    raw = decoded.split("<|output|>")[-1].strip()
    return json.loads(extract_first_json(raw))
```

---

### LangChain

```python
from langchain_ollama import OllamaLLM
from pydantic import BaseModel, Field
from typing import Optional
import json

class Experience(BaseModel):
    title: str = Field(default="")
    company: str = Field(default="")
    duration: str = Field(default="")

class Education(BaseModel):
    degree: str = Field(default="")
    institution: str = Field(default="")
    year: str = Field(default="")

class ResumeExtraction(BaseModel):
    name: Optional[str] = None
    email: Optional[str] = None
    phone: Optional[str] = None
    website: Optional[str] = None
    skills: list[str] = Field(default_factory=list)
    experience: list[Experience] = Field(default_factory=list)
    education: list[Education] = Field(default_factory=list)
    other_details: list[str] = Field(default_factory=list)

def extract_first_json(text):
    depth, start = 0, None
    for i, ch in enumerate(text):
        if ch == "{":
            if start is None: start = i
            depth += 1
        elif ch == "}":
            depth -= 1
            if depth == 0 and start is not None:
                return text[start:i+1]
    return text

llm = OllamaLLM(model="agenthire-extractor", format="json", temperature=0)

def extract_resume(text: str) -> ResumeExtraction:
    raw = llm.invoke(text)
    return ResumeExtraction(**json.loads(extract_first_json(raw)))

# Batch processing
resumes = [resume_1, resume_2, resume_3]
results = [
    ResumeExtraction(**json.loads(extract_first_json(r)))
    for r in llm.batch(resumes)
]

# Pipeline with scoring
from langchain_core.prompts import PromptTemplate
from langchain_ollama import OllamaLLM as ScoreLLM

scoring_prompt = PromptTemplate.from_template(
    "Job: {job_description}\n\nCandidate: {candidate}\n\n"
    "Score 1-10 and explain."
)
scorer = ScoreLLM(model="llama3", temperature=0.3)

def process_application(resume_text, job_description):
    candidate = extract_resume(resume_text).model_dump()
    evaluation = (scoring_prompt | scorer).invoke({
        "job_description": job_description,
        "candidate": json.dumps(candidate, indent=2),
    })
    return {"candidate": candidate, "evaluation": evaluation}
```

---

## Important Notes

**Always use brace-counting extraction** on raw model output before `json.loads()`.
The model occasionally appends a small amount of text after the closing `}`. Parsing
the raw string directly will raise `JSONDecodeError: Extra data`.

```python
def extract_first_json(text):
    depth, start = 0, None
    for i, ch in enumerate(text):
        if ch == "{":
            if start is None: start = i
            depth += 1
        elif ch == "}":
            depth -= 1
            if depth == 0 and start is not None:
                return text[start:i+1]
    return text

result = json.loads(extract_first_json(raw_output))
```

**Do not call the raw HuggingFace model directly via Ollama** (`hf.co/nimendraai/...`)
without a Modelfile. The NuExtract `<|input|> / ### Template: / ### Text:` prompt
format must be applied β€” the Modelfile `TEMPLATE` block handles this automatically.

**Skill capitalisation** is normalised via `.title()` during training, so `FastAPI`
may appear as `Fastapi` in output. Apply a canonical map in post-processing if needed.

---

## Limitations

- Trained on **synthetic** English resumes β€” real-world resumes with unusual layouts
  may produce lower accuracy. Fine-tuning on 30+ real examples will improve results.
- Skills are extracted with light normalisation β€” canonical casing (FastAPI vs Fastapi)
  requires a post-processing map.
- Phone numbers are extracted as-is without E.164 normalisation.
- Best suited for English resumes. Some multilingual capability exists from the
  Qwen2.5 backbone but was not tested.

---

## Citation

If you use this model, please also cite the original NuExtract work:

```bibtex
@misc{nuextract2024,
  author = {NuMind},
  title  = {NuExtract: A Foundation Model for Structured Extraction},
  year   = {2024},
  url    = {https://numind.ai/blog/nuextract-a-foundation-model-for-structured-extraction}
}
```

---

## License

MIT β€” same as the base model [`numind/NuExtract-tiny-v1.5`](https://huggingface.co/numind/NuExtract-1.5-tiny).

---
This was trained 2x faster with [Unsloth](https://github.com/unslothai/unsloth)
[<img src="https://raw.githubusercontent.com/unslothai/unsloth/main/images/unsloth%20made%20with%20love.png" width="200"/>](https://github.com/unslothai/unsloth)