Vision extraction Nano for structured JSON extraction from images
β Back to Liquid NanosLFM2.5-VL-1.6B-Extract extracts user-defined fields from images and returns structured JSON. It extends the Extract family to vision workflows, using a YAML field list in the system prompt to define exactly what to extract.
Use greedy decoding (temperature=0) for best results. This model is intended for single-image, single-turn extraction.
Describe the fields to extract as a YAML field list in the system prompt, then provide the image as the user message. The model returns a flat JSON object with those fields.
wood_color: The overall coloration of the wood surfacewood_texture: The tactile quality of the wood surfacewood_pattern: The pattern types visible on the wood surface
The model cardβs Transformers example wraps the field list in this system prompt:
Extract the following from the image:{fields_yaml}Respond with only a JSON object. Do not include any text outside the JSON.
Enum fields: list the allowed values in the field description, and the model returns one of them.
wood_color: The overall coloration of the wood surface, such as blue, red, or light tanwood_texture: The tactile quality of the wood surface, select from smooth, rough, or grainywood_pattern: The pattern types visible on the wood surface, e.g., straight, wavy, or curly
from transformers import AutoModelForImageTextToText, AutoProcessorfrom transformers.image_utils import load_imagemodel_id = "LiquidAI/LFM2.5-VL-1.6B-Extract"model = AutoModelForImageTextToText.from_pretrained( model_id, device_map="auto", dtype="bfloat16", trust_remote_code=True,)processor = AutoProcessor.from_pretrained(model_id, trust_remote_code=True)image = load_image("https://huggingface.co/LiquidAI/LFM2.5-VL-1.6B-Extract/resolve/main/sample_image.png")fields_yaml = """wood_color: The overall coloration of the wood surfacewood_texture: The tactile quality of the wood surfacewood_pattern: The pattern types visible on the wood surface"""system_prompt = f"""Extract the following from the image:{fields_yaml}Respond with only a JSON object. Do not include any text outside the JSON."""conversation = [ {"role": "system", "content": system_prompt}, {"role": "user", "content": [{"type": "image", "image": image}]},]inputs = processor.apply_chat_template( conversation, add_generation_prompt=True, return_tensors="pt", return_dict=True, tokenize=True,).to(model.device)outputs = model.generate(**inputs, max_new_tokens=512, do_sample=False)response = processor.batch_decode( outputs[:, inputs["input_ids"].shape[1]:], skip_special_tokens=True,)[0]print(response)
Run with llama-cli (fields go in the prompt, as shown on the GGUF model card):
curl -L -o image.png \ https://huggingface.co/LiquidAI/LFM2.5-VL-1.6B-Extract/resolve/main/sample_image.pngllama-cli -hf LiquidAI/LFM2.5-VL-1.6B-Extract-GGUF:F16 \ -p $'wood_color: The overall coloration of the wood surface\nwood_texture: The tactile quality of the wood surface\nwood_pattern: The pattern types visible on the wood surface' \ --image ./image.png