Text Generation
PEFT
Safetensors
English
unsloth
lora
json
extraction
structured-output
qwen2.5
conversational
Instructions to use suneeldk/json-extract with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- PEFT
How to use suneeldk/json-extract with PEFT:
from peft import PeftModel from transformers import AutoModelForCausalLM base_model = AutoModelForCausalLM.from_pretrained("unsloth/qwen2.5-1.5b-instruct-unsloth-bnb-4bit") model = PeftModel.from_pretrained(base_model, "suneeldk/json-extract") - Notebooks
- Google Colab
- Kaggle
- Local Apps
- Unsloth Studio
How to use suneeldk/json-extract with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for suneeldk/json-extract to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for suneeldk/json-extract to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for suneeldk/json-extract to start chatting
Load model with FastModel
pip install unsloth from unsloth import FastModel model, tokenizer = FastModel.from_pretrained( model_name="suneeldk/json-extract", max_seq_length=2048, )
| base_model: unsloth/Qwen2.5-1.5B-Instruct | |
| library_name: peft | |
| license: apache-2.0 | |
| language: | |
| - en | |
| tags: | |
| - unsloth | |
| - lora | |
| - json | |
| - extraction | |
| - structured-output | |
| - qwen2.5 | |
| pipeline_tag: text-generation | |
| # json-extract | |
| A fine-tuned **Qwen2.5-1.5B-Instruct** model with LoRA adapters for extracting structured JSON from natural language text. | |
| ## What it does | |
| Give it any unstructured text and a target JSON schema — it returns clean, structured JSON output. | |
| **Input:** | |
| ``` | |
| Paid 500 to Ravi for lunch on Jan 5 | |
| ``` | |
| **Output:** | |
| ```json | |
| { | |
| "amount": 500, | |
| "person": "Ravi", | |
| "date": "2025-01-05", | |
| "note": "lunch" | |
| } | |
| ``` | |
| ## How to use | |
| ### With Unsloth (recommended) | |
| ```python | |
| from unsloth import FastLanguageModel | |
| import json | |
| model, tokenizer = FastLanguageModel.from_pretrained( | |
| "suneeldk/json-extract", | |
| load_in_4bit=True, | |
| ) | |
| FastLanguageModel.for_inference(model) | |
| def extract(text, schema): | |
| prompt = f"### Input: {text}\n### Schema: {json.dumps(schema)}\n### Output:" | |
| inputs = tokenizer(prompt, return_tensors="pt").to("cuda") | |
| outputs = model.generate( | |
| **inputs, | |
| max_new_tokens=512, | |
| temperature=0.1, | |
| do_sample=True, | |
| pad_token_id=tokenizer.eos_token_id, | |
| use_cache=False, | |
| ) | |
| result = tokenizer.decode(outputs[0], skip_special_tokens=True) | |
| output_part = result.split("### Output:")[-1].strip() | |
| return json.loads(output_part) | |
| schema = { | |
| "amount": "number", | |
| "person": "string|null", | |
| "date": "ISO date|null", | |
| "note": "string|null" | |
| } | |
| result = extract("Paid 500 to Ravi for lunch on Jan 5", schema) | |
| print(json.dumps(result, indent=2)) | |
| ``` | |
| ### With Transformers + PEFT | |
| ```python | |
| from transformers import AutoModelForCausalLM, AutoTokenizer | |
| from peft import PeftModel | |
| base_model = AutoModelForCausalLM.from_pretrained("Qwen/Qwen2.5-1.5B-Instruct") | |
| model = PeftModel.from_pretrained(base_model, "YOUR_USERNAME/json-extract") | |
| tokenizer = AutoTokenizer.from_pretrained("YOUR_USERNAME/json-extract") | |
| ``` | |
| ## Training details | |
| | Parameter | Value | | |
| |---|---| | |
| | Base model | Qwen2.5-1.5B-Instruct | | |
| | Method | LoRA (r=16, alpha=16) | | |
| | Target modules | q_proj, k_proj, v_proj, o_proj, gate_proj, up_proj, down_proj | | |
| | Epochs | 3 | | |
| | Learning rate | 2e-4 | | |
| | Batch size | 4 (x4 gradient accumulation) | | |
| | Scheduler | Cosine | | |
| | Optimizer | AdamW 8-bit | | |
| | Precision | 4-bit quantized (QLoRA) | | |
| | Max sequence length | 2048 | | |
| ## Prompt format | |
| ``` | |
| ### Input: <your text here> | |
| ### Schema: <json schema> | |
| ### Output: | |
| ``` | |
| The model will generate a JSON object matching the provided schema. | |
| ## Limitations | |
| - Optimized for short-to-medium length text inputs | |
| - Works best with schemas similar to the training data | |
| - May not handle highly nested or complex JSON structures | |
| - English language only | |
| ## License | |
| Apache 2.0 |