Transformers
Safetensors
English
text-generation-inference
gemma4
trl
structured-output
json
function-calling
agentic-ai
Instructions to use agentbyumer/gemma4-e2b-structured-output with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use agentbyumer/gemma4-e2b-structured-output with Transformers:
# pip install -U transformers accelerate # Load model directly from transformers import AutoModel model = AutoModel.from_pretrained("agentbyumer/gemma4-e2b-structured-output", device_map="auto") - Notebooks
- Google Colab
- Kaggle
Update README.md
Browse files
README.md
CHANGED
|
@@ -3,20 +3,104 @@ base_model: unsloth/gemma-4-e2b-it-unsloth-bnb-4bit
|
|
| 3 |
tags:
|
| 4 |
- text-generation-inference
|
| 5 |
- transformers
|
| 6 |
-
- unsloth
|
| 7 |
- gemma4
|
| 8 |
- trl
|
|
|
|
|
|
|
|
|
|
|
|
|
| 9 |
license: apache-2.0
|
| 10 |
language:
|
| 11 |
- en
|
|
|
|
|
|
|
| 12 |
---
|
| 13 |
|
| 14 |
-
#
|
| 15 |
|
| 16 |
-
-
|
| 17 |
-
|
| 18 |
-
|
|
|
|
| 19 |
|
| 20 |
-
|
| 21 |
|
| 22 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
tags:
|
| 4 |
- text-generation-inference
|
| 5 |
- transformers
|
|
|
|
| 6 |
- gemma4
|
| 7 |
- trl
|
| 8 |
+
- structured-output
|
| 9 |
+
- json
|
| 10 |
+
- function-calling
|
| 11 |
+
- agentic-ai
|
| 12 |
license: apache-2.0
|
| 13 |
language:
|
| 14 |
- en
|
| 15 |
+
datasets:
|
| 16 |
+
- interstellarninja/json-mode-agentic
|
| 17 |
---
|
| 18 |
|
| 19 |
+
# Gemma 4 E2B — Structured Output
|
| 20 |
|
| 21 |
+
A QLoRA fine-tune of Google's Gemma 4 E2B, trained to convert natural-language text into
|
| 22 |
+
valid, schema-conforming JSON. Built for use cases where an LLM needs to reliably hand off
|
| 23 |
+
structured data to downstream code — agent tool calls, form extraction, data pipelines,
|
| 24 |
+
and anywhere else "give me clean JSON, not prose" actually matters.
|
| 25 |
|
| 26 |
+
## Why this model exists
|
| 27 |
|
| 28 |
+
Most instruction-tuned models *can* produce JSON when asked, but they tend to wrap it in
|
| 29 |
+
explanation, second-guess the schema, or take an unnecessarily long reasoning path to get
|
| 30 |
+
there. This fine-tune trains that overhead away, so the model goes straight from a schema
|
| 31 |
+
and a block of text to a clean, parseable JSON object.
|
| 32 |
+
|
| 33 |
+
## Training details
|
| 34 |
+
|
| 35 |
+
| | |
|
| 36 |
+
|---|---|
|
| 37 |
+
| Base model | unsloth/gemma-4-e2b-it-unsloth-bnb-4bit |
|
| 38 |
+
| Method | QLoRA |
|
| 39 |
+
| Dataset | [interstellarninja/json-mode-agentic](https://huggingface.co/datasets/interstellarninja/json-mode-agentic) |
|
| 40 |
+
| Task | Schema-guided JSON extraction from natural language |
|
| 41 |
+
| License | apache-2.0 |
|
| 42 |
+
|
| 43 |
+
## Evaluation
|
| 44 |
+
|
| 45 |
+
Tested informally against the base model on a set of hand-written extraction tasks,
|
| 46 |
+
covering simple schemas, nested/typed schemas, and — most importantly — cases where the
|
| 47 |
+
input text is missing information the schema asks for.
|
| 48 |
+
|
| 49 |
+
**Speed.** On every test, the fine-tuned model produced output immediately, with no visible
|
| 50 |
+
reasoning phase. The base model consistently reasoned through a multi-step "analyze, map,
|
| 51 |
+
construct, review" process first, taking 30+ seconds before reaching the same answer.
|
| 52 |
+
|
| 53 |
+
**Accuracy on typed schemas.** On a schema mixing strings, numbers, booleans, and arrays
|
| 54 |
+
(e.g. `price: number`, `in_stock: boolean`, `tags: [string]`), the fine-tuned model matched
|
| 55 |
+
every field type correctly, including nested arrays and decimal numbers. On a separate,
|
| 56 |
+
simpler test, it returned one field (`age`) as a string instead of the integer the schema
|
| 57 |
+
specified — the base model got this particular field right. Across the full test set this
|
| 58 |
+
looked like an isolated slip rather than a systematic pattern, but it's a real, observed
|
| 59 |
+
behavior worth knowing about if your use case depends on strict type fidelity.
|
| 60 |
+
|
| 61 |
+
**Handling missing data.** This was the most important test. When a required field wasn't
|
| 62 |
+
present anywhere in the input text, the fine-tuned model correctly returned `null` for that
|
| 63 |
+
field instead of inventing a plausible-looking value to fill the schema. This matters more
|
| 64 |
+
than it might sound — a structured-output model that fabricates missing fields to "complete"
|
| 65 |
+
a schema is a real liability in any pipeline that trusts its output, and this model didn't
|
| 66 |
+
do that in testing.
|
| 67 |
+
|
| 68 |
+
**Bottom line:** significantly faster and more direct than the base model on structured
|
| 69 |
+
extraction tasks, with strong type accuracy on complex schemas and correct, honest behavior
|
| 70 |
+
on missing data. The one observed weak spot — an occasional type mismatch on simpler
|
| 71 |
+
schemas — is worth validating against your own schema and data before relying on it in
|
| 72 |
+
production.
|
| 73 |
+
|
| 74 |
+
This isn't a formal benchmark result, and it's a small test set. If you run it against
|
| 75 |
+
something more rigorous (JSON-mode-eval, a custom test suite, or your own production data),
|
| 76 |
+
I'd genuinely like to hear how it does — open an issue or start a discussion on this repo.
|
| 77 |
+
|
| 78 |
+
## How to use
|
| 79 |
+
|
| 80 |
+
```python
|
| 81 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 82 |
+
|
| 83 |
+
model = AutoModelForCausalLM.from_pretrained(
|
| 84 |
+
"agentbyumer/gemma4-e2b-structured-output",
|
| 85 |
+
device_map="auto"
|
| 86 |
+
)
|
| 87 |
+
tokenizer = AutoTokenizer.from_pretrained("agentbyumer/gemma4-e2b-structured-output")
|
| 88 |
+
|
| 89 |
+
prompt = """Schema: {"name": "string", "age": "integer", "email": "string"}
|
| 90 |
+
Text: "Hi, I'm Sarah Ahmed, I'm 29 years old, you can reach me at sarah.ahmed@email.com"
|
| 91 |
+
Task: Extract the information into the given JSON schema."""
|
| 92 |
+
|
| 93 |
+
inputs = tokenizer(prompt, return_tensors="pt").to(model.device)
|
| 94 |
+
outputs = model.generate(**inputs, max_new_tokens=200)
|
| 95 |
+
print(tokenizer.decode(outputs[0], skip_special_tokens=True))
|
| 96 |
+
```
|
| 97 |
+
|
| 98 |
+
A GGUF-quantized version for local/CPU inference is planned — check back or watch this repo
|
| 99 |
+
for updates.
|
| 100 |
+
|
| 101 |
+
## Part of an ongoing series
|
| 102 |
+
|
| 103 |
+
This is one of several small, task-focused fine-tunes I'm building and evaluating as part
|
| 104 |
+
of exploring what narrow specialization can (and can't) improve in sub-5B parameter models —
|
| 105 |
+
covering function-calling, math reasoning, code generation, and structured output so far.
|
| 106 |
+
More context on the approach and results across the series.
|