-
Install llama.cpp (if not already installed):
1# Clone and build llama.cpp
2git clone https://github.com/ggerganov/llama.cpp
3cd llama.cpp
4make
5
6# Return to project directory
7cd ../NER_small
-
Download the GGUF model:
1# Download model files from HuggingFace
2wget https://huggingface.co/Minibase/NER-Small/resolve/main/model.gguf
3wget https://huggingface.co/Minibase/NER-Small/resolve/main/ner_inference.py
4wget https://huggingface.co/Minibase/NER-Small/resolve/main/config.json
5wget https://huggingface.co/Minibase/NER-Small/resolve/main/tokenizer_config.json
6wget https://huggingface.co/Minibase/NER-Small/resolve/main/generation_config.json
-
Start the model server:
1# Start llama.cpp server with the GGUF model
2../llama.cpp/llama-server \
3 -m model.gguf \
4 --host 127.0.0.1 \
5 --port 8000 \
6 --ctx-size 2048 \
7 --n-gpu-layers 0 \
8 --chat-template
-
Make API calls:
1import requests
2
3# NER tagging via REST API
4response = requests.post("http://127.0.0.1:8000/completion", json={
5 "prompt": "Instruction: Identify and tag all named entities in the following text. Use BIO format with entity types: PERSON, ORG, LOC, MISC.\n\nInput: John Smith works at Google in New York.\n\nResponse: ",
6 "max_tokens": 512,
7 "temperature": 0.1
8})
9
10result = response.json()
11print(result["content"])
12# Output: "John B-PERSON\nSmith I-PERSON\nworks O\nat O\nGoogle B-ORG\nin O\nNew York B-LOC\nI-LOC\n."
1# Download and use the provided Python client
2from ner_inference import NERClient
3
4# Initialize client (connects to local server)
5client = NERClient()
6
7# Tag entities in text
8text = "Apple Inc. was founded by Steve Jobs in Cupertino, California."
9entities = client.extract_entities(text)
10
11print(entities)
12# Output: [
13# {"text": "Apple Inc.", "type": "ORG", "start": 0, "end": 9},
14# {"text": "Steve Jobs", "type": "PERSON", "start": 24, "end": 34},
15# {"text": "Cupertino", "type": "LOC", "start": 38, "end": 47},
16# {"text": "California", "type": "LOC", "start": 49, "end": 59}
17# ]
18
19# Batch processing
20texts = [
21 "Microsoft announced a new CEO.",
22 "Paris is the capital of France."
23]
24all_entities = client.extract_entities_batch(texts)
25print(all_entities)
1# Alternative: Use llama.cpp directly without server
2import subprocess
3import json
4
5def extract_entities_with_llama_cpp(text: str) -> str:
6 prompt = f"Instruction: Identify and tag all named entities in the following text. Use BIO format with entity types: PERSON, ORG, LOC, MISC.\n\nInput: {text}\n\nResponse: "
7
8 # Run llama.cpp directly
9 cmd = [
10 "../llama.cpp/llama-cli",
11 "-m", "model.gguf",
12 "--prompt", prompt,
13 "--ctx-size", "2048",
14 "--n-predict", "512",
15 "--temp", "0.1",
16 "--log-disable"
17 ]
18
19 result = subprocess.run(cmd, capture_output=True, text=True, cwd=".")
20 return result.stdout.strip()
21
22# Usage
23result = extract_entities_with_llama_cpp("John Smith works at Google in New York.")
24print(result)
1@misc{ner-small-2025,
2 title={NER-Small: A Compact Named Entity Recognition Model},
3 author={Minibase AI Team},
4 year={2025},
5 publisher={Hugging Face},
6 url={https://huggingface.co/Minibase/NER-Small}
7}
This model is released under the
Apache License 2.0.