Downloads · 30 days
18
20% of all-time downloads
makiisthebes/gemma-3-270M-Instruct-FoodExtract
gemma-3-270M-Instruct-FoodExtract is a text generation model from makiisthebes. Use it when you need the model to write or continue text. It is set up for transformers. The card lists the license as gemma.
A small, task-specific language model fine-tuned to extract food and drink items from arbitrary text (such as image captions) and return them in a compact TOON structured format.
Downloads · 30 days
18
20% of all-time downloads
All-time downloads
91
Public
Parameters
268M
1.1 GB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors536 MB · 94%
From the Hugging Face model README
A small, task-specific language model fine-tuned to extract food and drink items from arbitrary text (such as image captions) and return them in a compact TOON structured format.
This model is a Supervised Fine-Tuned (SFT) version of google/gemma-3-270m-it,
trained to perform a single, narrow task: given a piece of free-form text,
classify whether it mentions food/drink and, if so, extract the specific items
as structured data. The motivation was to produce a cheap, locally-runnable
model that can filter or label large volumes of image captions without paying
for a frontier API or sending data off-device.
google/gemma-3-270m-itThe model takes a free-form English sentence and returns a TOON-encoded object describing whether the text mentions food or drink, and what specifically is mentioned. Typical inputs are image captions or short descriptive snippets, e.g.:
"For breakfast I had eggs, bacon and toast and a glass of orange juice."
Suitable as a lightweight filter or labeller in a larger pipeline — for example, filtering a large dataset of image captions down to only those that reference food, before passing the filtered set to a more expensive downstream system (e.g. a recommendation engine or food-tracking app).
mrdbourke/FoodExtract-1k, ~1,420
rows) skews toward Western foods and image-caption-style phrasing. The
model will likely under-perform on cuisines, dishes, or phrasings that are
underrepresented in that distribution.gpt-oss-120b, so
any systematic errors in the teacher labels will be inherited by this model.Validate outputs with a parser before downstream use, and treat the model as a filter/heuristic rather than a source of truth for nutritional or allergen information.
from transformers import AutoTokenizer, AutoModelForCausalLM, pipeline
MODEL = "makiisthebes/gemma-3-270M-Instruct-FoodExtract" # replace with the published repo
tokenizer = AutoTokenizer.from_pretrained(MODEL)
model = AutoModelForCausalLM.from_pretrained(
MODEL,
dtype="auto",
device_map="auto",
attn_implementation="sdpa",
)
pipe = pipeline("text-generation", model=model, tokenizer=tokenizer)
messages = [{
"role": "user",
"content": "a photo of a person's lunch with a tuna, cheese and capers melt sandwich",
}]
prompt = tokenizer.apply_chat_template(
messages, tokenize=False, add_generation_prompt=True
)
output = pipe(prompt, max_new_tokens=256)
print(output[0]["generated_text"])
A Gradio demo is also provided in the training notebook for interactive use.
mrdbourke/FoodExtract-1ksequence field (input text) and a
gpt-oss-120b-label / gpt-oss-120b-label-condensed field (structured
food/drink annotations produced by gpt-oss-120b)train_test_split calls with shuffle=False to preserve orderEach sample is converted into a chat-style conversation:
{
"messages": [
{"role": "user", "content": sample["sequence"]},
{"role": "assistant", "content": sample["gpt-oss-120b-label-condensed"]},
]
}
The tokenizer's built-in Gemma chat template (<start_of_turn>user … <end_of_turn> <start_of_turn>model …) is then applied during training so that the model
learns to produce the structured response after the model turn marker.
Targets use TOON instead of raw JSON. TOON encodes the same structure with substantially fewer tokens, which both reduces training cost and shortens generation at inference time.
Configured via trl.SFTConfig and trained with trl.SFTTrainer:
| Parameter | Value |
|---|---|
| Base model | google/gemma-3-270m-it |
| Epochs | 3 |
| Per-device train batch size | 16 |
| Per-device eval batch size | 16 |
| Learning rate | 5e-5 |
| LR scheduler | constant |
| Optimizer | adamw_torch_fused |
| Max sequence length | 512 |
| Packing | False |
| Gradient checkpointing | True |
| Save / eval strategy | per epoch |
| Attention implementation | sdpa |
| Logging | trackio |
dtype="auto" (bf16 on
supported hardware) via AutoModelForCausalLM.from_pretrained(...).The held-out 10% test split of mrdbourke/FoodExtract-1k, which was not seen
during training or hyperparameter selection.
Evaluated qualitatively across:
Currently human review of generated outputs against the ground-truth
labels, comparing the fine-tuned model side-by-side with the base
gemma-3-270m-it. An LLM-as-judge approach is planned as a follow-up.
Qualitatively, the fine-tuned model:
For its size (~270M parameters), the model produces consistent, parseable structured output for food/drink extraction, which the base instruction model does not do reliably without heavier prompting.
Carbon emissions can be estimated using the Machine Learning Impact calculator presented in Lacoste et al. (2019).
Decoder-only transformer (Gemma 3, 270M parameters), trained with a causal language modelling objective on chat-formatted (user → assistant) examples where the assistant turn contains the TOON-encoded food/drink extraction.
Nvidia DGX Spark x 1
transformerstrl (SFTTrainer, SFTConfig)datasetstorch (CUDA)trackio for run loggingtoon-format for compact structured outputsgradio for the interactive demoBase model:
@misc{gemma3_2025,
title = {Gemma 3},
author = {Google},
year = {2025},
url = {https://huggingface.co/google/gemma-3-270m-it}
}
Built as a learning exercise following Daniel Bourke's two-part fine-tuning tutorial, with adaptations including the use of TOON instead of JSON for structured outputs.
Michael Peres