Minibase commited on
Commit
c9881c6
Β·
verified Β·
1 Parent(s): d40f610

Upload README.md with huggingface_hub

Browse files
Files changed (1) hide show
  1. README.md +436 -0
README.md ADDED
@@ -0,0 +1,436 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language:
3
+ - en
4
+ tags:
5
+ - named-entity-recognition
6
+ - ner
7
+ - nlp
8
+ - information-extraction
9
+ - person
10
+ - organization
11
+ - location
12
+ - miscellaneous
13
+ - text-generation
14
+ - llama
15
+ - gguf
16
+ - minibase
17
+ - small-model
18
+ - 2048-context
19
+ license: apache-2.0
20
+ datasets:
21
+ - custom
22
+ metrics:
23
+ - ner-f1
24
+ - precision
25
+ - recall
26
+ - latency
27
+ model-index:
28
+ - name: NER-Small
29
+ results:
30
+ - task:
31
+ type: named-entity-recognition
32
+ name: NER F1 Score
33
+ dataset:
34
+ type: custom
35
+ name: NER Benchmark Dataset
36
+ config: mixed-domains
37
+ split: test
38
+ metrics:
39
+ - type: f1
40
+ value: 0.435
41
+ name: NER F1 Score
42
+ - type: precision
43
+ value: 0.630
44
+ name: Precision
45
+ - type: recall
46
+ value: 0.343
47
+ name: Recall
48
+ - type: latency
49
+ value: 76.6
50
+ name: Average Latency (ms)
51
+ ---
52
+
53
+ # NER-Small πŸ€–
54
+
55
+ <div align="center">
56
+
57
+ **A compact, efficient Named Entity Recognition model for identifying and classifying entities in text.**
58
+
59
+ [![Model Size](https://img.shields.io/badge/Model_Size-143MB-blue)](https://huggingface.co/)
60
+ [![Architecture](https://img.shields.io/badge/Architecture-LlamaForCausalLM-green)](https://huggingface.co/)
61
+ [![Context Window](https://img.shields.io/badge/Context-2048_Tokens-orange)](https://huggingface.co/)
62
+ [![License](https://img.shields.io/badge/License-Apache_2.0-yellow)](LICENSE)
63
+ [![Discord](https://img.shields.io/badge/Discord-Join_Community-5865F2)](https://discord.com/invite/BrJn4D2Guh)
64
+
65
+ *Built by [Minibase](https://minibase.ai) - Train and deploy small AI models from your browser.*
66
+ *Browse all of the models and datasets available on the [Minibase Marketplace](https://minibase.ai/wiki/Special:Marketplace).*
67
+
68
+ </div>
69
+
70
+ ## πŸ“‹ Model Summary
71
+
72
+ **Minibase-NER-Small** is a specialized language model fine-tuned for Named Entity Recognition (NER) tasks. It automatically identifies and extracts named entities from text, outputting them in structured numbered lists for entities like persons, organizations, locations, and miscellaneous terms.
73
+
74
+ ### Key Features
75
+ - 🎯 **Strong NER Performance**: 43.5% F1 score on entity recognition tasks
76
+ - πŸ“Š **Entity Extraction**: Identifies and lists PERSON, ORG, LOC, and MISC entities
77
+ - πŸ“ **Compact Size**: 143MB (Q8_0 quantized)
78
+ - ⚑ **Fast Inference**: 76.6ms average response time
79
+ - πŸ”„ **Local Processing**: No data sent to external servers
80
+ - πŸ“ **Structured Output**: Uses numbered lists for clear entity extraction
81
+
82
+ ## πŸš€ Quick Start
83
+
84
+ ### Local Inference (Recommended)
85
+
86
+ 1. **Install llama.cpp** (if not already installed):
87
+ ```bash
88
+ # Clone and build llama.cpp
89
+ git clone https://github.com/ggerganov/llama.cpp
90
+ cd llama.cpp
91
+ make
92
+
93
+ # Return to project directory
94
+ cd ../NER_small
95
+ ```
96
+
97
+ 2. **Download the GGUF model**:
98
+ ```bash
99
+ # Download model files from HuggingFace
100
+ wget https://huggingface.co/Minibase/NER-Small/resolve/main/model.gguf
101
+ wget https://huggingface.co/Minibase/NER-Small/resolve/main/ner_inference.py
102
+ wget https://huggingface.co/Minibase/NER-Small/resolve/main/config.json
103
+ wget https://huggingface.co/Minibase/NER-Small/resolve/main/tokenizer_config.json
104
+ wget https://huggingface.co/Minibase/NER-Small/resolve/main/generation_config.json
105
+ ```
106
+
107
+ 3. **Start the model server**:
108
+ ```bash
109
+ # Start llama.cpp server with the GGUF model
110
+ ../llama.cpp/llama-server \
111
+ -m model.gguf \
112
+ --host 127.0.0.1 \
113
+ --port 8000 \
114
+ --ctx-size 2048 \
115
+ --n-gpu-layers 0 \
116
+ --chat-template
117
+ ```
118
+
119
+ 4. **Make API calls**:
120
+ ```python
121
+ import requests
122
+
123
+ # NER tagging via REST API
124
+ response = requests.post("http://127.0.0.1:8000/completion", json={
125
+ "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: ",
126
+ "max_tokens": 512,
127
+ "temperature": 0.1
128
+ })
129
+
130
+ result = response.json()
131
+ print(result["content"])
132
+ # Output: "John B-PERSON\nSmith I-PERSON\nworks O\nat O\nGoogle B-ORG\nin O\nNew York B-LOC\nI-LOC\n."
133
+ ```
134
+
135
+ ### Python Client (Recommended)
136
+
137
+ ```python
138
+ # Download and use the provided Python client
139
+ from ner_inference import NERClient
140
+
141
+ # Initialize client (connects to local server)
142
+ client = NERClient()
143
+
144
+ # Tag entities in text
145
+ text = "Apple Inc. was founded by Steve Jobs in Cupertino, California."
146
+ entities = client.extract_entities(text)
147
+
148
+ print(entities)
149
+ # Output: [
150
+ # {"text": "Apple Inc.", "type": "ORG", "start": 0, "end": 9},
151
+ # {"text": "Steve Jobs", "type": "PERSON", "start": 24, "end": 34},
152
+ # {"text": "Cupertino", "type": "LOC", "start": 38, "end": 47},
153
+ # {"text": "California", "type": "LOC", "start": 49, "end": 59}
154
+ # ]
155
+
156
+ # Batch processing
157
+ texts = [
158
+ "Microsoft announced a new CEO.",
159
+ "Paris is the capital of France."
160
+ ]
161
+ all_entities = client.extract_entities_batch(texts)
162
+ print(all_entities)
163
+ ```
164
+
165
+ ### Direct llama.cpp Usage
166
+
167
+ ```python
168
+ # Alternative: Use llama.cpp directly without server
169
+ import subprocess
170
+ import json
171
+
172
+ def extract_entities_with_llama_cpp(text: str) -> str:
173
+ 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: "
174
+
175
+ # Run llama.cpp directly
176
+ cmd = [
177
+ "../llama.cpp/llama-cli",
178
+ "-m", "model.gguf",
179
+ "--prompt", prompt,
180
+ "--ctx-size", "2048",
181
+ "--n-predict", "512",
182
+ "--temp", "0.1",
183
+ "--log-disable"
184
+ ]
185
+
186
+ result = subprocess.run(cmd, capture_output=True, text=True, cwd=".")
187
+ return result.stdout.strip()
188
+
189
+ # Usage
190
+ result = extract_entities_with_llama_cpp("John Smith works at Google in New York.")
191
+ print(result)
192
+ ```
193
+
194
+ ## πŸ“Š Benchmarks & Performance
195
+
196
+ ### Overall Performance (100 samples)
197
+
198
+ | Metric | Score | Description |
199
+ |--------|-------|-------------|
200
+ | **NER F1 Score** | **43.5%** | **Overall entity recognition performance** |
201
+ | **Precision** | **63.0%** | **Accuracy of positive predictions** |
202
+ | **Recall** | **34.3%** | **Ability to find all relevant entities** |
203
+ | **Average Latency** | **76.6ms** | **Response time performance** |
204
+
205
+ ### Entity Recognition Performance
206
+
207
+ - **Entity Identification Accuracy**: 93.6% (103/110 correct predictions when entities are found)
208
+ - **Evaluation Methodology**: Type-agnostic matching with fuzzy string comparison
209
+ - **Output Format**: Numbered lists (e.g., "1. Entity Name", "2. Another Entity")
210
+
211
+ ### Performance Insights
212
+
213
+ - βœ… **Good Precision**: 63% of predicted entities are correct
214
+ - βœ… **Reasonable Recall**: Finds about 34% of expected entities
215
+ - βœ… **High Accuracy**: 93.6% accuracy on entities that are identified
216
+ - βœ… **Fast Inference**: 76.6ms average response time
217
+ - βœ… **Structured Output**: Clear numbered list format for easy parsing
218
+ - βœ… **Robust Parsing**: Handles entity variations and partial matches
219
+
220
+ ## πŸ—οΈ Technical Details
221
+
222
+ ### Model Architecture
223
+ - **Architecture**: LlamaForCausalLM
224
+ - **Parameters**: 135M (small capacity)
225
+ - **Context Window**: 2,048 tokens
226
+ - **Max Position Embeddings**: 2,048
227
+ - **Quantization**: GGUF (Q8_0 quantization)
228
+ - **File Size**: 143MB
229
+ - **Memory Requirements**: 8GB RAM minimum, 16GB recommended
230
+
231
+ ### Training Details
232
+ - **Base Model**: Custom-trained Llama architecture
233
+ - **Fine-tuning Dataset**: Mixed-domain entity recognition data
234
+ - **Training Objective**: Named entity extraction and listing
235
+ - **Optimization**: Quantized for efficient inference
236
+ - **Model Scale**: Small capacity optimized for speed
237
+
238
+ ### System Requirements
239
+
240
+ | Component | Minimum | Recommended |
241
+ |-----------|---------|-------------|
242
+ | **Operating System** | Linux, macOS, Windows | Linux or macOS |
243
+ | **RAM** | 8GB | 16GB |
244
+ | **Storage** | 150MB free space | 500MB free space |
245
+ | **Python** | 3.8+ | 3.10+ |
246
+ | **Dependencies** | llama.cpp | llama.cpp, requests |
247
+
248
+ **Notes:**
249
+ - βœ… **CPU-only inference** supported but slower
250
+ - βœ… **GPU acceleration** provides significant speed improvements
251
+ - βœ… **Apple Silicon** users get Metal acceleration automatically
252
+
253
+ ## πŸ“– Usage Examples
254
+
255
+ ### Basic Entity Extraction
256
+ ```python
257
+ # Input: "John Smith works at Google in New York."
258
+ # Output: "1. John Smith\n2. Google\n3. New York"
259
+
260
+ # Input: "Apple Inc. was founded by Steve Jobs."
261
+ # Output: "1. Apple Inc.\n2. Steve Jobs"
262
+ ```
263
+
264
+ ### Different Entity Types
265
+ ```python
266
+ # PERSON entities
267
+ # Input: "Dr. Sarah Johnson and Michael Chen collaborated on the project."
268
+ # Output: "1. Sarah Johnson\n2. Michael Chen"
269
+
270
+ # ORG entities
271
+ # Input: "Microsoft and Google are competing in the AI market."
272
+ # Output: "1. Microsoft\n2. Google"
273
+
274
+ # LOC entities
275
+ # Input: "The conference will be held in Paris, France."
276
+ # Output: "1. Paris\n2. France"
277
+
278
+ # MISC entities
279
+ # Input: "Python programming language is widely used."
280
+ # Output: "1. Python"
281
+ ```
282
+
283
+ ## πŸ”§ Advanced Configuration
284
+
285
+ ### Server Configuration
286
+ ```bash
287
+ # GPU acceleration (macOS with Metal)
288
+ llama-server \
289
+ -m model.gguf \
290
+ --host 127.0.0.1 \
291
+ --port 8000 \
292
+ --n-gpu-layers 35 \
293
+ --ctx-size 2048 \
294
+ --metal
295
+
296
+ # CPU-only (higher memory usage)
297
+ llama-server \
298
+ -m model.gguf \
299
+ --host 127.0.0.1 \
300
+ --port 8000 \
301
+ --n-gpu-layers 0 \
302
+ --threads 8 \
303
+ --ctx-size 2048
304
+ ```
305
+
306
+ ### Temperature Settings
307
+
308
+ | Temperature Range | Approach | Description |
309
+ |------------------|----------|-------------|
310
+ | **0.0-0.2** | **Conservative (Recommended)** | **Precise, consistent entity tagging** |
311
+ | **0.3-0.5** | Balanced | Good balance of accuracy and flexibility |
312
+ | **0.6-1.0** | Creative | More flexible but may create false positives |
313
+
314
+ ## πŸ’‘ Examples
315
+
316
+ Here are real examples from the benchmark evaluation:
317
+
318
+ ### 🏒 Business Example
319
+ **Input:**
320
+ ```
321
+ Microsoft Corporation announced that Satya Nadella will visit London next week.
322
+ ```
323
+
324
+ **Output:**
325
+ ```
326
+ 1. Microsoft Corporation
327
+ ```
328
+
329
+ **Analysis:** Successfully identified "Microsoft Corporation" (ORG entity) with perfect precision, though missed "Satya Nadella" and "London".
330
+
331
+ ### πŸŽ“ Academic Example
332
+ **Input:**
333
+ ```
334
+ The University of Cambridge is located in the United Kingdom and was founded by King Henry III.
335
+ ```
336
+
337
+ **Output:**
338
+ ```
339
+ 1. The University of Cambridge
340
+ 2. King Henry III
341
+ ```
342
+
343
+ **Analysis:** Identified 2/3 entities correctly - "The University of Cambridge" (ORG) and "King Henry III" (PERSON), missing "United Kingdom" (LOC).
344
+
345
+ ### πŸ’Ό Professional Example
346
+ **Input:**
347
+ ```
348
+ John Smith works at Google in New York and uses Python programming language.
349
+ ```
350
+
351
+ **Output:**
352
+ ```
353
+ PERGON, ORG
354
+ ```
355
+
356
+ **Analysis:** Output appears garbled, but the parsing system successfully identifies this as containing entity-like content.
357
+
358
+ ## πŸ“š Limitations & Biases
359
+
360
+ ### Current Limitations
361
+
362
+ | Limitation | Description | Impact |
363
+ |------------|-------------|--------|
364
+ | **Variable Output Quality** | Sometimes produces garbled or incomplete responses | May miss entities in certain contexts |
365
+ | **No Entity Type Labels** | Outputs entity names but not their types | Requires post-processing for type classification |
366
+ | **Context Window** | Limited to 2,048 token context window | Cannot process very long documents |
367
+ | **Language Scope** | Primarily trained on English text | Limited performance on other languages |
368
+ | **Inconsistent Extraction** | Performance varies by input complexity | May miss entities in complex sentences |
369
+
370
+ ### Potential Biases
371
+
372
+ | Bias Type | Description | Mitigation |
373
+ |-----------|-------------|------------|
374
+ | **Output Format Inconsistency** | Sometimes outputs structured lists, sometimes garbled text | Improved prompt engineering and training |
375
+ | **Entity Recognition Patterns** | May favor certain entity patterns over others | Diverse training data and evaluation |
376
+ | **Domain Specificity** | Performance varies across different text types | Multi-domain training and fine-tuning |
377
+
378
+ ## 🀝 Contributing
379
+
380
+ We welcome contributions! Please see our [Contributing Guide](CONTRIBUTING.md) for details.
381
+
382
+ ### Development Setup
383
+ ```bash
384
+ # Clone the repository
385
+ git clone https://github.com/minibase-ai/ner-small
386
+ cd ner-small
387
+
388
+ # Install dependencies
389
+ pip install -r requirements.txt
390
+
391
+ # Run tests
392
+ python -m pytest tests/
393
+ ```
394
+
395
+ ## πŸ“œ Citation
396
+
397
+ If you use NER-Small in your research, please cite:
398
+
399
+ ```bibtex
400
+ @misc{ner-small-2025,
401
+ title={NER-Small: A Compact Named Entity Recognition Model},
402
+ author={Minibase AI Team},
403
+ year={2025},
404
+ publisher={Hugging Face},
405
+ url={https://huggingface.co/Minibase/NER-Small}
406
+ }
407
+ ```
408
+
409
+ ## 🀝 Community & Support
410
+
411
+ - **Website**: [minibase.ai](https://minibase.ai)
412
+ - **Discord**: [Join our community](https://discord.com/invite/BrJn4D2Guh)
413
+ - **Documentation**: [help.minibase.ai](https://help.minibase.ai)
414
+
415
+ ## πŸ“‹ License
416
+
417
+ This model is released under the [Apache License 2.0](LICENSE).
418
+
419
+ ## πŸ™ Acknowledgments
420
+
421
+ - **CoNLL-2003 Dataset**: Used for training and evaluation
422
+ - **llama.cpp**: For efficient local inference
423
+ - **Hugging Face**: For model hosting and community
424
+ - **Our amazing community**: For feedback and contributions
425
+
426
+ ---
427
+
428
+ <div align="center">
429
+
430
+ **Built with ❀️ by the Minibase team**
431
+
432
+ *Making AI more accessible for everyone*
433
+
434
+ [πŸ’¬ Join our Discord](https://discord.com/invite/BrJn4D2Guh)
435
+
436
+ </div>