Instructions to use QuantFactory/NuExtract-1.5-tiny-GGUF with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- llama-cpp-python
How to use QuantFactory/NuExtract-1.5-tiny-GGUF with llama-cpp-python:
# !pip install llama-cpp-python from llama_cpp import Llama llm = Llama.from_pretrained( repo_id="QuantFactory/NuExtract-1.5-tiny-GGUF", filename="NuExtract-1.5-tiny.Q2_K.gguf", )
llm.create_chat_completion( messages = [ { "role": "user", "content": "What is the capital of France?" } ] ) - Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- llama.cpp
How to use QuantFactory/NuExtract-1.5-tiny-GGUF with llama.cpp:
Install from brew
brew install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf QuantFactory/NuExtract-1.5-tiny-GGUF:Q4_K_M # Run inference directly in the terminal: llama-cli -hf QuantFactory/NuExtract-1.5-tiny-GGUF:Q4_K_M
Install from WinGet (Windows)
winget install llama.cpp # Start a local OpenAI-compatible server with a web UI: llama-server -hf QuantFactory/NuExtract-1.5-tiny-GGUF:Q4_K_M # Run inference directly in the terminal: llama-cli -hf QuantFactory/NuExtract-1.5-tiny-GGUF:Q4_K_M
Use pre-built binary
# Download pre-built binary from: # https://github.com/ggerganov/llama.cpp/releases # Start a local OpenAI-compatible server with a web UI: ./llama-server -hf QuantFactory/NuExtract-1.5-tiny-GGUF:Q4_K_M # Run inference directly in the terminal: ./llama-cli -hf QuantFactory/NuExtract-1.5-tiny-GGUF:Q4_K_M
Build from source code
git clone https://github.com/ggerganov/llama.cpp.git cd llama.cpp cmake -B build cmake --build build -j --target llama-server llama-cli # Start a local OpenAI-compatible server with a web UI: ./build/bin/llama-server -hf QuantFactory/NuExtract-1.5-tiny-GGUF:Q4_K_M # Run inference directly in the terminal: ./build/bin/llama-cli -hf QuantFactory/NuExtract-1.5-tiny-GGUF:Q4_K_M
Use Docker
docker model run hf.co/QuantFactory/NuExtract-1.5-tiny-GGUF:Q4_K_M
- LM Studio
- Jan
- vLLM
How to use QuantFactory/NuExtract-1.5-tiny-GGUF with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "QuantFactory/NuExtract-1.5-tiny-GGUF" # Call the server using curl (OpenAI-compatible API): curl -X POST "http://localhost:8000/v1/chat/completions" \ -H "Content-Type: application/json" \ --data '{ "model": "QuantFactory/NuExtract-1.5-tiny-GGUF", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/QuantFactory/NuExtract-1.5-tiny-GGUF:Q4_K_M
- Ollama
How to use QuantFactory/NuExtract-1.5-tiny-GGUF with Ollama:
ollama run hf.co/QuantFactory/NuExtract-1.5-tiny-GGUF:Q4_K_M
- Unsloth Studio
How to use QuantFactory/NuExtract-1.5-tiny-GGUF with Unsloth Studio:
Install Unsloth Studio (macOS, Linux, WSL)
curl -fsSL https://unsloth.ai/install.sh | sh # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for QuantFactory/NuExtract-1.5-tiny-GGUF to start chatting
Install Unsloth Studio (Windows)
irm https://unsloth.ai/install.ps1 | iex # Run unsloth studio unsloth studio -H 0.0.0.0 -p 8888 # Then open http://localhost:8888 in your browser # Search for QuantFactory/NuExtract-1.5-tiny-GGUF to start chatting
Using HuggingFace Spaces for Unsloth
# No setup required # Open https://huggingface.co/spaces/unsloth/studio in your browser # Search for QuantFactory/NuExtract-1.5-tiny-GGUF to start chatting
- Pi
How to use QuantFactory/NuExtract-1.5-tiny-GGUF with Pi:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama-server -hf QuantFactory/NuExtract-1.5-tiny-GGUF:Q4_K_M
Configure the model in Pi
# Install Pi: npm install -g @mariozechner/pi-coding-agent # Add to ~/.pi/agent/models.json: { "providers": { "llama-cpp": { "baseUrl": "http://localhost:8080/v1", "api": "openai-completions", "apiKey": "none", "models": [ { "id": "QuantFactory/NuExtract-1.5-tiny-GGUF:Q4_K_M" } ] } } }Run Pi
# Start Pi in your project directory: pi
- Hermes Agent new
How to use QuantFactory/NuExtract-1.5-tiny-GGUF with Hermes Agent:
Start the llama.cpp server
# Install llama.cpp: brew install llama.cpp # Start a local OpenAI-compatible server: llama-server -hf QuantFactory/NuExtract-1.5-tiny-GGUF:Q4_K_M
Configure Hermes
# Install Hermes: curl -fsSL https://hermes-agent.nousresearch.com/install.sh | bash hermes setup # Point Hermes at the local server: hermes config set model.provider custom hermes config set model.base_url http://127.0.0.1:8080/v1 hermes config set model.default QuantFactory/NuExtract-1.5-tiny-GGUF:Q4_K_M
Run Hermes
hermes
- Docker Model Runner
How to use QuantFactory/NuExtract-1.5-tiny-GGUF with Docker Model Runner:
docker model run hf.co/QuantFactory/NuExtract-1.5-tiny-GGUF:Q4_K_M
- Lemonade
How to use QuantFactory/NuExtract-1.5-tiny-GGUF with Lemonade:
Pull the model
# Download Lemonade from https://lemonade-server.ai/ lemonade pull QuantFactory/NuExtract-1.5-tiny-GGUF:Q4_K_M
Run and chat with the model
lemonade run user.NuExtract-1.5-tiny-GGUF-Q4_K_M
List all available models
lemonade list
Improve language tag
Browse filesHi! As the model is multilingual, this is a PR to add other languages than English to the language tag to improve the referencing. Note that 29 languages are announced in the README, but only 13 are explicitly listed. I was therefore only able to add these 13 languages.
|
@@ -1,180 +1,189 @@
|
|
| 1 |
-
|
| 2 |
-
|
| 3 |
-
|
| 4 |
-
|
| 5 |
-
|
| 6 |
-
-
|
| 7 |
-
|
| 8 |
-
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
-
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
|
| 19 |
-
|
| 20 |
-
|
| 21 |
-
|
| 22 |
-
|
| 23 |
-
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
| 28 |
-
|
| 29 |
-
|
| 30 |
-
|
| 31 |
-
|
| 32 |
-
|
| 33 |
-
|
| 34 |
-
|
| 35 |
-
|
| 36 |
-
|
| 37 |
-
|
| 38 |
-
|
| 39 |
-
|
| 40 |
-
|
| 41 |
-
|
| 42 |
-
|
| 43 |
-
|
| 44 |
-
|
| 45 |
-
|
| 46 |
-
|
| 47 |
-
|
| 48 |
-
|
| 49 |
-
|
| 50 |
-
|
| 51 |
-
|
| 52 |
-
|
| 53 |
-
|
| 54 |
-
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
|
| 61 |
-
|
| 62 |
-
|
| 63 |
-
|
| 64 |
-
|
| 65 |
-
|
| 66 |
-
|
| 67 |
-
|
| 68 |
-
|
| 69 |
-
|
| 70 |
-
|
| 71 |
-
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
-
|
| 78 |
-
|
| 79 |
-
|
| 80 |
-
|
| 81 |
-
|
| 82 |
-
|
| 83 |
-
|
| 84 |
-
|
| 85 |
-
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
|
| 89 |
-
|
| 90 |
-
|
| 91 |
-
|
| 92 |
-
|
| 93 |
-
|
| 94 |
-
|
| 95 |
-
|
| 96 |
-
|
| 97 |
-
|
| 98 |
-
|
| 99 |
-
|
| 100 |
-
|
| 101 |
-
|
| 102 |
-
|
| 103 |
-
|
| 104 |
-
|
| 105 |
-
|
| 106 |
-
|
| 107 |
-
|
| 108 |
-
|
| 109 |
-
|
| 110 |
-
|
| 111 |
-
|
| 112 |
-
|
| 113 |
-
|
| 114 |
-
|
| 115 |
-
|
| 116 |
-
|
| 117 |
-
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
| 121 |
-
|
| 122 |
-
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
| 127 |
-
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
return
|
| 131 |
-
|
| 132 |
-
def
|
| 133 |
-
|
| 134 |
-
|
| 135 |
-
|
| 136 |
-
|
| 137 |
-
|
| 138 |
-
|
| 139 |
-
|
| 140 |
-
|
| 141 |
-
|
| 142 |
-
|
| 143 |
-
|
| 144 |
-
|
| 145 |
-
|
| 146 |
-
|
| 147 |
-
|
| 148 |
-
|
| 149 |
-
|
| 150 |
-
|
| 151 |
-
|
| 152 |
-
|
| 153 |
-
|
| 154 |
-
|
| 155 |
-
|
| 156 |
-
|
| 157 |
-
|
| 158 |
-
|
| 159 |
-
|
| 160 |
-
|
| 161 |
-
|
| 162 |
-
|
| 163 |
-
|
| 164 |
-
|
| 165 |
-
|
| 166 |
-
|
| 167 |
-
|
| 168 |
-
|
| 169 |
-
|
| 170 |
-
|
| 171 |
-
|
| 172 |
-
|
| 173 |
-
|
| 174 |
-
|
| 175 |
-
|
| 176 |
-
|
| 177 |
-
|
| 178 |
-
|
| 179 |
-
|
| 180 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: mit
|
| 3 |
+
language:
|
| 4 |
+
- zho
|
| 5 |
+
- eng
|
| 6 |
+
- fra
|
| 7 |
+
- spa
|
| 8 |
+
- por
|
| 9 |
+
- deu
|
| 10 |
+
- ita
|
| 11 |
+
- rus
|
| 12 |
+
- jpn
|
| 13 |
+
- kor
|
| 14 |
+
- vie
|
| 15 |
+
- tha
|
| 16 |
+
- ara
|
| 17 |
+
tags:
|
| 18 |
+
- nlp
|
| 19 |
+
base_model: Qwen/Qwen2.5-0.5B
|
| 20 |
+
pipeline_tag: text-generation
|
| 21 |
+
---
|
| 22 |
+
|
| 23 |
+
[](https://hf.co/QuantFactory)
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
# QuantFactory/NuExtract-1.5-tiny-GGUF
|
| 27 |
+
This is quantized version of [numind/NuExtract-1.5-tiny](https://huggingface.co/numind/NuExtract-1.5-tiny) created using llama.cpp
|
| 28 |
+
|
| 29 |
+
# Original Model Card
|
| 30 |
+
|
| 31 |
+
|
| 32 |
+
# NuExtract-tiny-v1.5 by NuMind 🔥
|
| 33 |
+
|
| 34 |
+
NuExtract-tiny-v1.5 is a fine-tuning of [Qwen/Qwen2.5-0.5B](https://huggingface.co/Qwen/Qwen2.5-0.5B), trained on a private high-quality dataset for structured information extraction. It supports long documents and several languages (English, French, Spanish, German, Portuguese, and Italian).
|
| 35 |
+
To use the model, provide an input text and a JSON template describing the information you need to extract.
|
| 36 |
+
|
| 37 |
+
Note: This model is trained to prioritize pure extraction, so in most cases all text generated by the model is present as is in the original text.
|
| 38 |
+
|
| 39 |
+
We also provide a 3.8B version which is based on Phi-3.5-mini-instruct: [NuExtract-v1.5](https://huggingface.co/numind/NuExtract-v1.5)
|
| 40 |
+
|
| 41 |
+
Check out the [blog post](https://numind.ai/blog/nuextract-1-5---multilingual-infinite-context-still-small-and-better-than-gpt-4o).
|
| 42 |
+
|
| 43 |
+
Try the 3.8B model here: [Playground](https://huggingface.co/spaces/numind/NuExtract-v1.5)
|
| 44 |
+
|
| 45 |
+
## Benchmark
|
| 46 |
+
|
| 47 |
+
Zero-shot performance (English):
|
| 48 |
+
|
| 49 |
+
<p align="left">
|
| 50 |
+
<img src="english_bench.png" style="width: 600; height: auto;">
|
| 51 |
+
</p>
|
| 52 |
+
|
| 53 |
+
Few-shot fine-tuning:
|
| 54 |
+
|
| 55 |
+
<p align="left">
|
| 56 |
+
<img src="fewshot_bench.png" style="width: 750; height: auto;">
|
| 57 |
+
</p>
|
| 58 |
+
|
| 59 |
+
|
| 60 |
+
## Usage
|
| 61 |
+
|
| 62 |
+
To use the model:
|
| 63 |
+
|
| 64 |
+
```python
|
| 65 |
+
import json
|
| 66 |
+
import torch
|
| 67 |
+
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 68 |
+
|
| 69 |
+
def predict_NuExtract(model, tokenizer, texts, template, batch_size=1, max_length=10_000, max_new_tokens=4_000):
|
| 70 |
+
template = json.dumps(json.loads(template), indent=4)
|
| 71 |
+
prompts = [f"""<|input|>\n### Template:\n{template}\n### Text:\n{text}\n\n<|output|>""" for text in texts]
|
| 72 |
+
|
| 73 |
+
outputs = []
|
| 74 |
+
with torch.no_grad():
|
| 75 |
+
for i in range(0, len(prompts), batch_size):
|
| 76 |
+
batch_prompts = prompts[i:i+batch_size]
|
| 77 |
+
batch_encodings = tokenizer(batch_prompts, return_tensors="pt", truncation=True, padding=True, max_length=max_length).to(model.device)
|
| 78 |
+
|
| 79 |
+
pred_ids = model.generate(**batch_encodings, max_new_tokens=max_new_tokens)
|
| 80 |
+
outputs += tokenizer.batch_decode(pred_ids, skip_special_tokens=True)
|
| 81 |
+
|
| 82 |
+
return [output.split("<|output|>")[1] for output in outputs]
|
| 83 |
+
|
| 84 |
+
model_name = "numind/NuExtract-tiny-v1.5"
|
| 85 |
+
device = "cuda"
|
| 86 |
+
model = AutoModelForCausalLM.from_pretrained(model_name, torch_dtype=torch.bfloat16, trust_remote_code=True).to(device).eval()
|
| 87 |
+
tokenizer = AutoTokenizer.from_pretrained(model_name, trust_remote_code=True)
|
| 88 |
+
|
| 89 |
+
text = """We introduce Mistral 7B, a 7–billion-parameter language model engineered for
|
| 90 |
+
superior performance and efficiency. Mistral 7B outperforms the best open 13B
|
| 91 |
+
model (Llama 2) across all evaluated benchmarks, and the best released 34B
|
| 92 |
+
model (Llama 1) in reasoning, mathematics, and code generation. Our model
|
| 93 |
+
leverages grouped-query attention (GQA) for faster inference, coupled with sliding
|
| 94 |
+
window attention (SWA) to effectively handle sequences of arbitrary length with a
|
| 95 |
+
reduced inference cost. We also provide a model fine-tuned to follow instructions,
|
| 96 |
+
Mistral 7B – Instruct, that surpasses Llama 2 13B – chat model both on human and
|
| 97 |
+
automated benchmarks. Our models are released under the Apache 2.0 license.
|
| 98 |
+
Code: <https://github.com/mistralai/mistral-src>
|
| 99 |
+
Webpage: <https://mistral.ai/news/announcing-mistral-7b/>"""
|
| 100 |
+
|
| 101 |
+
template = """{
|
| 102 |
+
"Model": {
|
| 103 |
+
"Name": "",
|
| 104 |
+
"Number of parameters": "",
|
| 105 |
+
"Number of max token": "",
|
| 106 |
+
"Architecture": []
|
| 107 |
+
},
|
| 108 |
+
"Usage": {
|
| 109 |
+
"Use case": [],
|
| 110 |
+
"Licence": ""
|
| 111 |
+
}
|
| 112 |
+
}"""
|
| 113 |
+
|
| 114 |
+
prediction = predict_NuExtract(model, tokenizer, [text], template)[0]
|
| 115 |
+
print(prediction)
|
| 116 |
+
|
| 117 |
+
```
|
| 118 |
+
|
| 119 |
+
Sliding window prompting:
|
| 120 |
+
|
| 121 |
+
```python
|
| 122 |
+
import json
|
| 123 |
+
|
| 124 |
+
MAX_INPUT_SIZE = 20_000
|
| 125 |
+
MAX_NEW_TOKENS = 6000
|
| 126 |
+
|
| 127 |
+
def clean_json_text(text):
|
| 128 |
+
text = text.strip()
|
| 129 |
+
text = text.replace("\#", "#").replace("\&", "&")
|
| 130 |
+
return text
|
| 131 |
+
|
| 132 |
+
def predict_chunk(text, template, current, model, tokenizer):
|
| 133 |
+
current = clean_json_text(current)
|
| 134 |
+
|
| 135 |
+
input_llm = f"<|input|>\n### Template:\n{template}\n### Current:\n{current}\n### Text:\n{text}\n\n<|output|>" + "{"
|
| 136 |
+
input_ids = tokenizer(input_llm, return_tensors="pt", truncation=True, max_length=MAX_INPUT_SIZE).to("cuda")
|
| 137 |
+
output = tokenizer.decode(model.generate(**input_ids, max_new_tokens=MAX_NEW_TOKENS)[0], skip_special_tokens=True)
|
| 138 |
+
|
| 139 |
+
return clean_json_text(output.split("<|output|>")[1])
|
| 140 |
+
|
| 141 |
+
def split_document(document, window_size, overlap):
|
| 142 |
+
tokens = tokenizer.tokenize(document)
|
| 143 |
+
print(f"\tLength of document: {len(tokens)} tokens")
|
| 144 |
+
|
| 145 |
+
chunks = []
|
| 146 |
+
if len(tokens) > window_size:
|
| 147 |
+
for i in range(0, len(tokens), window_size-overlap):
|
| 148 |
+
print(f"\t{i} to {i + len(tokens[i:i + window_size])}")
|
| 149 |
+
chunk = tokenizer.convert_tokens_to_string(tokens[i:i + window_size])
|
| 150 |
+
chunks.append(chunk)
|
| 151 |
+
|
| 152 |
+
if i + len(tokens[i:i + window_size]) >= len(tokens):
|
| 153 |
+
break
|
| 154 |
+
else:
|
| 155 |
+
chunks.append(document)
|
| 156 |
+
print(f"\tSplit into {len(chunks)} chunks")
|
| 157 |
+
|
| 158 |
+
return chunks
|
| 159 |
+
|
| 160 |
+
def handle_broken_output(pred, prev):
|
| 161 |
+
try:
|
| 162 |
+
if all([(v in ["", []]) for v in json.loads(pred).values()]):
|
| 163 |
+
# if empty json, return previous
|
| 164 |
+
pred = prev
|
| 165 |
+
except:
|
| 166 |
+
# if broken json, return previous
|
| 167 |
+
pred = prev
|
| 168 |
+
|
| 169 |
+
return pred
|
| 170 |
+
|
| 171 |
+
def sliding_window_prediction(text, template, model, tokenizer, window_size=4000, overlap=128):
|
| 172 |
+
# split text into chunks of n tokens
|
| 173 |
+
tokens = tokenizer.tokenize(text)
|
| 174 |
+
chunks = split_document(text, window_size, overlap)
|
| 175 |
+
|
| 176 |
+
# iterate over text chunks
|
| 177 |
+
prev = template
|
| 178 |
+
for i, chunk in enumerate(chunks):
|
| 179 |
+
print(f"Processing chunk {i}...")
|
| 180 |
+
pred = predict_chunk(chunk, template, prev, model, tokenizer)
|
| 181 |
+
|
| 182 |
+
# handle broken output
|
| 183 |
+
pred = handle_broken_output(pred, prev)
|
| 184 |
+
|
| 185 |
+
# iterate
|
| 186 |
+
prev = pred
|
| 187 |
+
|
| 188 |
+
return pred
|
| 189 |
+
```
|