Instructions to use numind/NuExtract-2.0-4B with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use numind/NuExtract-2.0-4B with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("image-text-to-text", model="numind/NuExtract-2.0-4B") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] pipe(text=messages)# Load model directly from transformers import AutoProcessor, AutoModelForMultimodalLM processor = AutoProcessor.from_pretrained("numind/NuExtract-2.0-4B") model = AutoModelForMultimodalLM.from_pretrained("numind/NuExtract-2.0-4B", device_map="auto") messages = [ { "role": "user", "content": [ {"type": "image", "url": "https://huggingface.co/datasets/huggingface/documentation-images/resolve/main/p-blog/candy.JPG"}, {"type": "text", "text": "What animal is on the candy?"} ] }, ] inputs = processor.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(processor.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use numind/NuExtract-2.0-4B with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "numind/NuExtract-2.0-4B" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "numind/NuExtract-2.0-4B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'Use Docker
docker model run hf.co/numind/NuExtract-2.0-4B
- SGLang
How to use numind/NuExtract-2.0-4B 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 "numind/NuExtract-2.0-4B" \ --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": "numind/NuExtract-2.0-4B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }'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 "numind/NuExtract-2.0-4B" \ --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": "numind/NuExtract-2.0-4B", "messages": [ { "role": "user", "content": [ { "type": "text", "text": "Describe this image in one sentence." }, { "type": "image_url", "image_url": { "url": "https://cdn.britannica.com/61/93061-050-99147DCE/Statue-of-Liberty-Island-New-York-Bay.jpg" } } ] } ] }' - Docker Model Runner
How to use numind/NuExtract-2.0-4B with Docker Model Runner:
docker model run hf.co/numind/NuExtract-2.0-4B
2B model outputting math problem solving CoT instead of entities
#2
by xbill - opened
Hello, I am trying out the 2B model on Mac with the following prompt (generated by the tokenizer)
<|im_start|>system
You are NuExtract, an information extraction tool created by NuMind.<|im_end|>
<|im_start|>user
# Template:
{"name": "[string]", "company": "[string]", "amount": "[string]", "date": "[string]"}
# Context:
Hello John, the invoice for $500 from ABC Company is due on Friday.<|im_end|>
<|im_start|>assistant
I am expecting the list of entities as output, but here's what the model generates
[
" John has already paid $200. What is the balance due on the invoice?\nAnswer Choices: (A) 300 (B) 200 (C) 100 (D) 500 (E) 400\n\nTo find the balance due on the invoice, we subtract the amount John has already paid from the total invoice amount. Given that the invoice is for $500 and John has already paid $200, the balance due is:\n\n\\[ \\text{Balance due} = \\text{Invoice amount} - \\text{Payment amount} \\]\n\\[ \\text{Balance due} = 500 - 200 \\]\n\\[ \\text{Balance due} = 300 \\]\n\nTherefore, the correct answer is (A) 300. John is still due $300 on the invoice. However, the question seems to be a mix of a mathematical problem and a word problem, which might not be directly related. If the context is meant to be a mathematical problem, the correct answer is 300. If it's a word problem, the correct answer is not provided in the options. The question might need clarification to match the context accurately."
]
Am I doing something wrong? I have used the code snippets provided in the README. BTW, the AutoModelForVision2Seq class seems to be deprecated in favor of AutoModelForImageTextToText, but I preferred to stick with the old one.
Thanks in advance for your help