Instructions to use tarif2108/gemma-3-270m-json-extractor with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use tarif2108/gemma-3-270m-json-extractor with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="tarif2108/gemma-3-270m-json-extractor") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("tarif2108/gemma-3-270m-json-extractor") model = AutoModelForCausalLM.from_pretrained("tarif2108/gemma-3-270m-json-extractor", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.apply_chat_template( messages, add_generation_prompt=True, tokenize=True, return_dict=True, return_tensors="pt", ).to(model.device) outputs = model.generate(**inputs, max_new_tokens=40) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use tarif2108/gemma-3-270m-json-extractor with llama.cpp:
Install (macOS, Linux)
curl -LsSf https://llama.app/install.sh | sh # Start a local OpenAI-compatible server with a web UI: llama serve -hf tarif2108/gemma-3-270m-json-extractor:F16 # Run inference directly in the terminal: llama cli -hf tarif2108/gemma-3-270m-json-extractor:F16
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama serve -hf tarif2108/gemma-3-270m-json-extractor:F16 # Run inference directly in the terminal: llama cli -hf tarif2108/gemma-3-270m-json-extractor:F16
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf tarif2108/gemma-3-270m-json-extractor:F16 # Run inference directly in the terminal: ./llama-cli -hf tarif2108/gemma-3-270m-json-extractor:F16
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf tarif2108/gemma-3-270m-json-extractor:F16 # Run inference directly in the terminal: ./build/bin/llama-cli -hf tarif2108/gemma-3-270m-json-extractor:F16
Use Docker
docker model run hf.co/tarif2108/gemma-3-270m-json-extractor:F16
- LM Studio
- Jan
- vLLM
How to use tarif2108/gemma-3-270m-json-extractor with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "tarif2108/gemma-3-270m-json-extractor" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tarif2108/gemma-3-270m-json-extractor", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/tarif2108/gemma-3-270m-json-extractor:F16
- SGLang
How to use tarif2108/gemma-3-270m-json-extractor with SGLang:
Install from pip and serve model
# Install SGLang from pip: pip install sglang # Start the SGLang server: python3 -m sglang.launch_server \ --model-path "tarif2108/gemma-3-270m-json-extractor" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tarif2108/gemma-3-270m-json-extractor", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker images
docker run --gpus all \ --shm-size 32g \ -p 30000:30000 \ -v ~/.cache/huggingface:/root/.cache/huggingface \ --env "HF_TOKEN=<secret>" \ --ipc=host \ lmsysorg/sglang:latest \ python3 -m sglang.launch_server \ --model-path "tarif2108/gemma-3-270m-json-extractor" \ --host 0.0.0.0 \ --port 30000 # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:30000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "tarif2108/gemma-3-270m-json-extractor", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Ollama
How to use tarif2108/gemma-3-270m-json-extractor with Ollama:
ollama run hf.co/tarif2108/gemma-3-270m-json-extractor:F16
- Unsloth Studio
How to use tarif2108/gemma-3-270m-json-extractor 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 tarif2108/gemma-3-270m-json-extractor 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 tarif2108/gemma-3-270m-json-extractor to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for tarif2108/gemma-3-270m-json-extractor to start chatting
- Atomic Chat new
- Docker Model Runner
How to use tarif2108/gemma-3-270m-json-extractor with Docker Model Runner:
docker model run hf.co/tarif2108/gemma-3-270m-json-extractor:F16
- Lemonade
How to use tarif2108/gemma-3-270m-json-extractor with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull tarif2108/gemma-3-270m-json-extractor:F16
Run and chat with the model
lemonade run user.gemma-3-270m-json-extractor-F16
List all available models
lemonade list
🚀 Gemma 3 270M — Structured JSON & Function Calling Extractor
gemma-3-270m-json-extractor is a fine-tuned version of google/gemma-3-270m-it optimized for strict, raw JSON output and structured function-calling extraction without conversational filler.
Despite its tiny footprint (270 million parameters), this fine-tuned model delivers a 6x reduction in latency and a **4x increase in valid JSON formatting accuracy** compared to the base model.
📊 Key Benchmark & Evaluation Results
Evaluated on a held-out test split of 100 complex structured JSON extraction prompts:
| Metric | Base gemma-3-270m-it |
Fine-Tuned (gemma-3-270m-json-extractor) |
Improvement |
|---|---|---|---|
| JSON Validity Rate | 23.0% | 90.0% | +291% |
| Exact Schema Match | 0.0% | 21.0% | +21.0% |
| Key Coverage Rate | 0.0% | 59.0% | +59.0% |
| ROUGE-L Score | 26.58 | 67.79 | +155% |
| Avg Inference Latency | 11.54s | 1.92s | 6x Faster |
Key takeaway: The base model frequently rambled with conversational preamble ("Sure, here is your JSON..."), leading to long generation times and broken JSON syntax. The fine-tuned model immediately triggers JSON generation and cleanly emits the
<eos>token upon completion.
💻 How to Use
Basic Inference with Transformers
import torch
from transformers import AutoModelForCausalLM, AutoTokenizer
model_id = "tarif2108/gemma-3-270m-json-extractor"
tokenizer = AutoTokenizer.from_pretrained(model_id)
model = AutoModelForCausalLM.from_pretrained(
model_id,
torch_dtype=torch.bfloat16,
device_map="auto"
)
system_prompt = "You are a JSON generator. Reply ONLY with a single valid JSON object and nothing else."
user_prompt = "Extract user info into JSON with keys: name, age, city. Input: 'Hi, I'm Ada Lovelace, 28 years old, living in London.'"
messages = [
{"role": "system", "content": system_prompt},
{"role": "user", "content": user_prompt}
]
prompt = tokenizer.apply_chat_template(messages, tokenize=False, add_generation_prompt=True)
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
outputs = model.generate(
**inputs,
max_new_tokens=256,
do_sample=False,
pad_token_id=tokenizer.pad_token_id,
eos_token_id=tokenizer.eos_token_id
)
response = tokenizer.decode(outputs[0][inputs["input_ids"].shape[1]:], skip_special_tokens=True)
print(response)
# Expected Output: {"name":"Ada Lovelace","age":28,"city":"London"}
🛡️ Guaranteeing 100% Valid JSON (Constrained Decoding) While this fine-tuned model achieves 90% valid JSON natively, you can achieve 100% guaranteed schema enforcement during inference by combining this model with lm-format-enforcer:
pip install lm-formatenforcer pydantic
from pydantic import BaseModel
from lmformatenforcer import JsonSchemaParser
from lmformatenforcer.integrations.transformers import build_transformers_prefix_allowed_tokens_fn
class UserSchema(BaseModel):
name: str
age: int
city: str
parser = JsonSchemaParser(UserSchema.model_json_schema())
prefix_fn = build_transformers_prefix_allowed_tokens_fn(tokenizer, parser)
# Pass prefix_allowed_tokens_fn to model.generate
outputs = model.generate(
**inputs,
max_new_tokens=256,
prefix_allowed_tokens_fn=prefix_fn
)
⚙️ Training Details
- Base Model:
google/gemma-3-270m-it - Dataset:
NousResearch/hermes-function-calling-v1(~11,500 clean JSON rows across all subsets) - Fine-Tuning Technique: QLoRA (4-bit NF4 quantization)
- LoRA Target Modules:
q_proj,k_proj,v_proj,o_proj,gate_proj,up_proj,down_proj - LoRA Parameters: r=16, alpha=32, dropout=0.05
- Hardware: NVIDIA RTX 3050 (4GB VRAM)
- Optimizer:
paged_adamw_8bit - Precision:
bfloat16compute - Sequence Length: 512
- Downloads last month
- 23