Instructions to use ldalbe/calorie-lfm2.5-350m-onnx with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers.js
How to use ldalbe/calorie-lfm2.5-350m-onnx with Transformers.js:
// npm i @huggingface/transformers import { pipeline } from '@huggingface/transformers'; // Allocate pipeline const pipe = await pipeline('text-generation', 'ldalbe/calorie-lfm2.5-350m-onnx');
Calorie LFM2.5 350M ONNX
This is a Q4F16 ONNX export of an LFM2.5-350M model fine-tuned to turn a natural-language food or meal description into a strict JSON ingredient and calorie estimate. It is packaged for client-side inference with Transformers.js and WebGPU.
The model produces an ingredient array. Applications should calculate the
total calories by summing caloriesPerMeasurement * amount.
Usage
import { pipeline } from "@huggingface/transformers";
const systemPrompt = await fetch(
"https://huggingface.co/ldalbe/calorie-lfm2.5-350m-onnx/resolve/main/system_prompt.txt",
).then((response) => response.text());
const generate = await pipeline(
"text-generation",
"ldalbe/calorie-lfm2.5-350m-onnx",
{ device: "webgpu", dtype: "q4f16" },
);
const output = await generate(
[
{ role: "system", content: systemPrompt.trimEnd() },
{ role: "user", content: "a fried egg on toast with 2 bacon rashers" },
],
{ max_new_tokens: 400, do_sample: false },
);
const response = output[0].generated_text.at(-1).content;
const ingredients = JSON.parse(response);
const totalCalories = ingredients.reduce(
(total, item) => total + item.caloriesPerMeasurement * item.amount,
0,
);
The initial browser download is approximately 243 MB. Load the pipeline once, reuse it between requests, and run generation in a Web Worker in production.
Output schema
[
{
"ingredient": "egg",
"caloriesPerMeasurement": 72,
"measurementType": "whole",
"amount": 1
}
]
Each element has exactly four fields. caloriesPerMeasurement is kcal per
whole unit when measurementType is whole, and kcal per gram when it is
grams.
Training and evaluation
The model was LoRA fine-tuned for approximately one epoch on 21,250 synthetic training examples, then fused and converted to ONNX. On a deterministic 100-example held-out evaluation, it produced parseable JSON and the required schema for all 100 examples, with 90% exact target match.
These figures measure performance against the synthetic held-out labels, not real-world nutritional accuracy.
Limitations
Outputs are approximate estimates, not medical, regulatory, or restaurant nutrition data. Recipes, portions, and preparation methods vary. Unspecified portion sizes are subjective, and unusual foods or phrasing may be handled incorrectly. Users should verify estimates when accuracy matters.
Base model and license
This model is derived from LiquidAI/LFM2.5-350M
and is distributed under the LFM Open License v1.0 included in LICENSE.
- Downloads last month
- 181