Instructions to use numind/NuExtract-tiny with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use numind/NuExtract-tiny with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-generation", model="numind/NuExtract-tiny") messages = [ {"role": "user", "content": "Who are you?"}, ] pipe(messages)# pip install -U transformers accelerate # Load model directly from transformers import AutoTokenizer, AutoModelForCausalLM tokenizer = AutoTokenizer.from_pretrained("numind/NuExtract-tiny") model = AutoModelForCausalLM.from_pretrained("numind/NuExtract-tiny", device_map="auto") messages = [ {"role": "user", "content": "Who are you?"}, ] inputs = tokenizer.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=256) print(tokenizer.decode(outputs[0][inputs["input_ids"].shape[-1]:])) - Inference
- Notebooks
- Google Colab
- Kaggle
- Local Apps Settings
- vLLM
How to use numind/NuExtract-tiny with vLLM:
Install from pip and serve model
# Install vLLM from pip: pip install vllm # Start the vLLM server: vllm serve "numind/NuExtract-tiny" # 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-tiny", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'Use Docker
docker model run hf.co/numind/NuExtract-tiny
- SGLang
How to use numind/NuExtract-tiny 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-tiny" \ --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-tiny", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }'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-tiny" \ --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-tiny", "messages": [ { "role": "user", "content": "What is the capital of France?" } ] }' - Docker Model Runner
How to use numind/NuExtract-tiny with Docker Model Runner:
docker model run hf.co/numind/NuExtract-tiny
Update README.md
Browse files
README.md
CHANGED
|
@@ -5,9 +5,11 @@ language:
|
|
| 5 |
---
|
| 6 |
# Structure Extraction Model by NuMind 🔥
|
| 7 |
|
| 8 |
-
NuExtract_tiny is a
|
| 9 |
|
| 10 |
-
Note: This model
|
|
|
|
|
|
|
| 11 |
|
| 12 |
We also provide a base (3.8B) and large(7B) version of this model: [NuExtract](https://huggingface.co/numind/NuExtract) and [NuExtract-large](https://huggingface.co/numind/NuExtract-large)
|
| 13 |
|
|
@@ -26,7 +28,7 @@ import json
|
|
| 26 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 27 |
|
| 28 |
|
| 29 |
-
def predict_NuExtract(model,tokenizer,text, schema,
|
| 30 |
schema = json.dumps(json.loads(schema), indent=4)
|
| 31 |
input_llm = "<|input|>\n### Template:\n" + schema + "\n"
|
| 32 |
for i in example:
|
|
@@ -34,7 +36,7 @@ def predict_NuExtract(model,tokenizer,text, schema,example = ["","",""]):
|
|
| 34 |
input_llm += "### Example:\n"+ json.dumps(json.loads(i), indent=4)+"\n"
|
| 35 |
|
| 36 |
input_llm += "### Text:\n"+text +"\n<|output|>\n"
|
| 37 |
-
input_ids = tokenizer(input_llm, return_tensors="pt",
|
| 38 |
|
| 39 |
output = tokenizer.decode(model.generate(**input_ids)[0], skip_special_tokens=True)
|
| 40 |
return output.split("<|output|>")[1].split("<|end-output|>")[0]
|
|
@@ -72,7 +74,7 @@ schema = """{
|
|
| 72 |
}
|
| 73 |
}"""
|
| 74 |
|
| 75 |
-
prediction = predict_NuExtract(model,tokenizer,text, schema,
|
| 76 |
print(prediction)
|
| 77 |
|
| 78 |
```
|
|
|
|
| 5 |
---
|
| 6 |
# Structure Extraction Model by NuMind 🔥
|
| 7 |
|
| 8 |
+
NuExtract_tiny is a version of [Qwen1.5-0.5](https://huggingface.co/Qwen/Qwen1.5-0.5B), fine-tuned on a private high-quality synthetic dataset for information extraction. To use the model, provide an input text (less than 2000 tokens) and a JSON template describing the information you need to extract.
|
| 9 |
|
| 10 |
+
Note: This model is purely extractive, so all text output by the model is present as is in the original text. You can also provide an example of output formatting to help the model understand your task more precisely.
|
| 11 |
+
|
| 12 |
+
Note: While this model provides good 0 shot performance, it is intendeed to be fine-tune on a specific task (>=30 examples).
|
| 13 |
|
| 14 |
We also provide a base (3.8B) and large(7B) version of this model: [NuExtract](https://huggingface.co/numind/NuExtract) and [NuExtract-large](https://huggingface.co/numind/NuExtract-large)
|
| 15 |
|
|
|
|
| 28 |
from transformers import AutoModelForCausalLM, AutoTokenizer
|
| 29 |
|
| 30 |
|
| 31 |
+
def predict_NuExtract(model, tokenizer, text, schema, example=["","",""]):
|
| 32 |
schema = json.dumps(json.loads(schema), indent=4)
|
| 33 |
input_llm = "<|input|>\n### Template:\n" + schema + "\n"
|
| 34 |
for i in example:
|
|
|
|
| 36 |
input_llm += "### Example:\n"+ json.dumps(json.loads(i), indent=4)+"\n"
|
| 37 |
|
| 38 |
input_llm += "### Text:\n"+text +"\n<|output|>\n"
|
| 39 |
+
input_ids = tokenizer(input_llm, return_tensors="pt", truncation=True, max_length=4000).to("cuda")
|
| 40 |
|
| 41 |
output = tokenizer.decode(model.generate(**input_ids)[0], skip_special_tokens=True)
|
| 42 |
return output.split("<|output|>")[1].split("<|end-output|>")[0]
|
|
|
|
| 74 |
}
|
| 75 |
}"""
|
| 76 |
|
| 77 |
+
prediction = predict_NuExtract(model, tokenizer, text, schema, example=["","",""])
|
| 78 |
print(prediction)
|
| 79 |
|
| 80 |
```
|