Update README.md
Browse files
README.md
CHANGED
|
@@ -1,22 +1,125 @@
|
|
| 1 |
---
|
| 2 |
-
base_model: unsloth/
|
| 3 |
-
|
| 4 |
-
- text-generation-inference
|
| 5 |
-
- transformers
|
| 6 |
-
- unsloth
|
| 7 |
-
- qwen2
|
| 8 |
-
- trl
|
| 9 |
license: apache-2.0
|
| 10 |
language:
|
| 11 |
-
- en
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
---
|
| 13 |
|
| 14 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 15 |
|
| 16 |
-
-
|
| 17 |
-
-
|
| 18 |
-
-
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
|
| 22 |
-
|
|
|
|
| 1 |
---
|
| 2 |
+
base_model: unsloth/Qwen2.5-1.5B-Instruct
|
| 3 |
+
library_name: peft
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 4 |
license: apache-2.0
|
| 5 |
language:
|
| 6 |
+
- en
|
| 7 |
+
tags:
|
| 8 |
+
- unsloth
|
| 9 |
+
- lora
|
| 10 |
+
- json
|
| 11 |
+
- extraction
|
| 12 |
+
- structured-output
|
| 13 |
+
- qwen2.5
|
| 14 |
+
pipeline_tag: text-generation
|
| 15 |
---
|
| 16 |
|
| 17 |
+
# json-extract
|
| 18 |
+
|
| 19 |
+
A fine-tuned **Qwen2.5-1.5B-Instruct** model with LoRA adapters for extracting structured JSON from natural language text.
|
| 20 |
+
|
| 21 |
+
## What it does
|
| 22 |
+
|
| 23 |
+
Give it any unstructured text and a target JSON schema — it returns clean, structured JSON output.
|
| 24 |
+
|
| 25 |
+
**Input:**
|
| 26 |
+
```
|
| 27 |
+
Paid 500 to Ravi for lunch on Jan 5
|
| 28 |
+
```
|
| 29 |
+
|
| 30 |
+
**Output:**
|
| 31 |
+
```json
|
| 32 |
+
{
|
| 33 |
+
"amount": 500,
|
| 34 |
+
"person": "Ravi",
|
| 35 |
+
"date": "2025-01-05",
|
| 36 |
+
"note": "lunch"
|
| 37 |
+
}
|
| 38 |
+
```
|
| 39 |
+
|
| 40 |
+
## How to use
|
| 41 |
+
|
| 42 |
+
### With Unsloth (recommended)
|
| 43 |
+
|
| 44 |
+
```python
|
| 45 |
+
from unsloth import FastLanguageModel
|
| 46 |
+
import json
|
| 47 |
+
|
| 48 |
+
model, tokenizer = FastLanguageModel.from_pretrained(
|
| 49 |
+
"suneeldk/json-extract",
|
| 50 |
+
load_in_4bit=True,
|
| 51 |
+
)
|
| 52 |
+
FastLanguageModel.for_inference(model)
|
| 53 |
+
|
| 54 |
+
def extract(text, schema):
|
| 55 |
+
prompt = f"### Input: {text}\n### Schema: {json.dumps(schema)}\n### Output:"
|
| 56 |
+
inputs = tokenizer(prompt, return_tensors="pt").to("cuda")
|
| 57 |
+
outputs = model.generate(
|
| 58 |
+
**inputs,
|
| 59 |
+
max_new_tokens=512,
|
| 60 |
+
temperature=0.1,
|
| 61 |
+
do_sample=True,
|
| 62 |
+
pad_token_id=tokenizer.eos_token_id,
|
| 63 |
+
use_cache=False,
|
| 64 |
+
)
|
| 65 |
+
result = tokenizer.decode(outputs[0], skip_special_tokens=True)
|
| 66 |
+
output_part = result.split("### Output:")[-1].strip()
|
| 67 |
+
return json.loads(output_part)
|
| 68 |
+
|
| 69 |
+
schema = {
|
| 70 |
+
"amount": "number",
|
| 71 |
+
"person": "string|null",
|
| 72 |
+
"date": "ISO date|null",
|
| 73 |
+
"note": "string|null"
|
| 74 |
+
}
|
| 75 |
+
|
| 76 |
+
result = extract("Paid 500 to Ravi for lunch on Jan 5", schema)
|
| 77 |
+
print(json.dumps(result, indent=2))
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
### With Transformers + PEFT
|
| 81 |
+
|
| 82 |
+
```python
|
| 83 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 84 |
+
from peft import PeftModel
|
| 85 |
+
|
| 86 |
+
base_model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-1.5B-Instruct")
|
| 87 |
+
model = PeftModel.from_pretrained(base_model, "YOUR_USERNAME/json-extract")
|
| 88 |
+
tokenizer = AutoTokenizer.from_pretrained("YOUR_USERNAME/json-extract")
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
+
## Training details
|
| 92 |
+
|
| 93 |
+
| Parameter | Value |
|
| 94 |
+
|---|---|
|
| 95 |
+
| Base model | Qwen2.5-1.5B-Instruct |
|
| 96 |
+
| Method | LoRA (r=16, alpha=16) |
|
| 97 |
+
| Target modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj |
|
| 98 |
+
| Epochs | 3 |
|
| 99 |
+
| Learning rate | 2e-4 |
|
| 100 |
+
| Batch size | 4 (x4 gradient accumulation) |
|
| 101 |
+
| Scheduler | Cosine |
|
| 102 |
+
| Optimizer | AdamW 8-bit |
|
| 103 |
+
| Precision | 4-bit quantized (QLoRA) |
|
| 104 |
+
| Max sequence length | 2048 |
|
| 105 |
+
|
| 106 |
+
## Prompt format
|
| 107 |
+
|
| 108 |
+
```
|
| 109 |
+
### Input: <your text here>
|
| 110 |
+
### Schema: <json schema>
|
| 111 |
+
### Output:
|
| 112 |
+
```
|
| 113 |
+
|
| 114 |
+
The model will generate a JSON object matching the provided schema.
|
| 115 |
+
|
| 116 |
+
## Limitations
|
| 117 |
|
| 118 |
+
- Optimized for short-to-medium length text inputs
|
| 119 |
+
- Works best with schemas similar to the training data
|
| 120 |
+
- May not handle highly nested or complex JSON structures
|
| 121 |
+
- English language only
|
| 122 |
|
| 123 |
+
## License
|
| 124 |
|
| 125 |
+
Apache 2.0
|