Upload folder using huggingface_hub
Browse files- .gitattributes +3 -0
- README.md +141 -0
- config.json +4 -0
- gliner2_config.json +35 -0
- onnx/classifier.onnx +3 -0
- onnx/classifier_fp16.onnx +3 -0
- onnx/classifier_int8.onnx +3 -0
- onnx/count_embed.onnx +3 -0
- onnx/count_embed.onnx.data +3 -0
- onnx/count_embed_fp16.onnx +3 -0
- onnx/count_embed_fp16.onnx.data +3 -0
- onnx/count_embed_int8.onnx +3 -0
- onnx/encoder.onnx +3 -0
- onnx/encoder_fp16.onnx +3 -0
- onnx/encoder_int8.onnx +3 -0
- onnx/span_rep.onnx +3 -0
- onnx/span_rep_fp16.onnx +3 -0
- onnx/span_rep_int8.onnx +3 -0
- tokenizer.json +3 -0
- tokenizer_config.json +32 -0
.gitattributes
CHANGED
|
@@ -33,3 +33,6 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
|
|
|
|
|
|
|
|
|
|
|
| 33 |
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
| 36 |
+
onnx/count_embed.onnx.data filter=lfs diff=lfs merge=lfs -text
|
| 37 |
+
onnx/count_embed_fp16.onnx.data filter=lfs diff=lfs merge=lfs -text
|
| 38 |
+
tokenizer.json filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,141 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
library_name: gliner2-onnx
|
| 3 |
+
base_model: hivetrace/gliner-guard-uniencoder
|
| 4 |
+
tags:
|
| 5 |
+
- onnx
|
| 6 |
+
- gliner
|
| 7 |
+
- gliner2
|
| 8 |
+
- ner
|
| 9 |
+
- named-entity-recognition
|
| 10 |
+
- zero-shot
|
| 11 |
+
- classification
|
| 12 |
+
license: mit
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
> **Experimental ONNX build** - Unofficial ONNX export of [hivetrace/gliner-guard-uniencoder](https://huggingface.co/hivetrace/gliner-guard-uniencoder).
|
| 16 |
+
|
| 17 |
+
# gliner2-onnx
|
| 18 |
+
|
| 19 |
+
GLiNER2 ONNX runtime for Python. Runs GLiNER2 models without PyTorch.
|
| 20 |
+
|
| 21 |
+
This library is experimental. The API may change between versions.
|
| 22 |
+
|
| 23 |
+
## Features
|
| 24 |
+
|
| 25 |
+
- Zero-shot NER and text classification
|
| 26 |
+
- Runs with ONNX Runtime (no PyTorch dependency)
|
| 27 |
+
- FP32 and FP16 precision support
|
| 28 |
+
- GPU acceleration via CUDA
|
| 29 |
+
|
| 30 |
+
All other GLiNER2 features such as JSON export are not supported.
|
| 31 |
+
|
| 32 |
+
## Installation
|
| 33 |
+
|
| 34 |
+
```bash
|
| 35 |
+
pip install gliner2-onnx
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
## NER
|
| 39 |
+
|
| 40 |
+
```python
|
| 41 |
+
from gliner2_onnx import GLiNER2ONNXRuntime
|
| 42 |
+
|
| 43 |
+
runtime = GLiNER2ONNXRuntime.from_pretrained("lmo3/gliner2-large-v1-onnx")
|
| 44 |
+
|
| 45 |
+
entities = runtime.extract_entities(
|
| 46 |
+
"John works at Google in Seattle",
|
| 47 |
+
["person", "organization", "location"]
|
| 48 |
+
)
|
| 49 |
+
# [
|
| 50 |
+
# Entity(text='John', label='person', start=0, end=4, score=0.98),
|
| 51 |
+
# Entity(text='Google', label='organization', start=14, end=20, score=0.97),
|
| 52 |
+
# Entity(text='Seattle', label='location', start=24, end=31, score=0.96)
|
| 53 |
+
# ]
|
| 54 |
+
```
|
| 55 |
+
|
| 56 |
+
## Classification
|
| 57 |
+
|
| 58 |
+
```python
|
| 59 |
+
from gliner2_onnx import GLiNER2ONNXRuntime
|
| 60 |
+
|
| 61 |
+
runtime = GLiNER2ONNXRuntime.from_pretrained("lmo3/gliner2-large-v1-onnx")
|
| 62 |
+
|
| 63 |
+
# Single-label classification
|
| 64 |
+
result = runtime.classify(
|
| 65 |
+
"Buy milk from the store",
|
| 66 |
+
["shopping", "work", "entertainment"]
|
| 67 |
+
)
|
| 68 |
+
# {'shopping': 0.95}
|
| 69 |
+
|
| 70 |
+
# Multi-label classification
|
| 71 |
+
result = runtime.classify(
|
| 72 |
+
"Buy milk and finish the report",
|
| 73 |
+
["shopping", "work", "entertainment"],
|
| 74 |
+
threshold=0.3,
|
| 75 |
+
multi_label=True
|
| 76 |
+
)
|
| 77 |
+
# {'shopping': 0.85, 'work': 0.72}
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
## CUDA
|
| 81 |
+
|
| 82 |
+
To use CUDA for GPU acceleration:
|
| 83 |
+
|
| 84 |
+
```python
|
| 85 |
+
runtime = GLiNER2ONNXRuntime.from_pretrained(
|
| 86 |
+
"lmo3/gliner2-large-v1-onnx",
|
| 87 |
+
providers=["CUDAExecutionProvider", "CPUExecutionProvider"]
|
| 88 |
+
)
|
| 89 |
+
```
|
| 90 |
+
|
| 91 |
+
## Precision
|
| 92 |
+
|
| 93 |
+
Both FP32 and FP16 models are supported. Only the requested precision is downloaded.
|
| 94 |
+
|
| 95 |
+
```python
|
| 96 |
+
runtime = GLiNER2ONNXRuntime.from_pretrained(
|
| 97 |
+
"lmo3/gliner2-large-v1-onnx",
|
| 98 |
+
precision="fp16"
|
| 99 |
+
)
|
| 100 |
+
```
|
| 101 |
+
|
| 102 |
+
## Models
|
| 103 |
+
|
| 104 |
+
Pre-exported ONNX models:
|
| 105 |
+
|
| 106 |
+
| Model | HuggingFace |
|
| 107 |
+
|-------|-------------|
|
| 108 |
+
| gliner2-large-v1 | [lmo3/gliner2-large-v1-onnx](https://huggingface.co/lmo3/gliner2-large-v1-onnx) |
|
| 109 |
+
| gliner2-multi-v1 | [lmo3/gliner2-multi-v1-onnx](https://huggingface.co/lmo3/gliner2-multi-v1-onnx) |
|
| 110 |
+
|
| 111 |
+
Note: `gliner2-base-v1` is not supported (uses a different architecture).
|
| 112 |
+
|
| 113 |
+
## Exporting Models
|
| 114 |
+
|
| 115 |
+
To export your own models, clone the repository and use make:
|
| 116 |
+
|
| 117 |
+
```bash
|
| 118 |
+
git clone https://github.com/lmoe/gliner2-onnx
|
| 119 |
+
cd gliner2-onnx
|
| 120 |
+
|
| 121 |
+
# FP32 only
|
| 122 |
+
make onnx-export MODEL=fastino/gliner2-large-v1
|
| 123 |
+
|
| 124 |
+
# FP32 + FP16
|
| 125 |
+
make onnx-export MODEL=fastino/gliner2-large-v1 QUANTIZE=fp16
|
| 126 |
+
```
|
| 127 |
+
|
| 128 |
+
Output is saved to `model_out/<model-name>/`.
|
| 129 |
+
|
| 130 |
+
## JavaScript/TypeScript
|
| 131 |
+
|
| 132 |
+
For Node.js, see [@lmoe/gliner-onnx.js](https://github.com/lmoe/gliner-onnx.js).
|
| 133 |
+
|
| 134 |
+
## Credits
|
| 135 |
+
|
| 136 |
+
- [fastino-ai/GLiNER2](https://github.com/fastino-ai/GLiNER2) - Original GLiNER2 implementation
|
| 137 |
+
- [fastino/gliner2-large-v1](https://huggingface.co/fastino/gliner2-large-v1) - Pre-trained models
|
| 138 |
+
|
| 139 |
+
## License
|
| 140 |
+
|
| 141 |
+
MIT
|
config.json
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"hidden_size": 384,
|
| 3 |
+
"vocab_size": 256000
|
| 4 |
+
}
|
gliner2_config.json
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"max_width": 12,
|
| 3 |
+
"special_tokens": {
|
| 4 |
+
"[SEP_STRUCT]": 256000,
|
| 5 |
+
"[SEP_TEXT]": 256001,
|
| 6 |
+
"[P]": 256002,
|
| 7 |
+
"[C]": 256003,
|
| 8 |
+
"[E]": 256004,
|
| 9 |
+
"[R]": 256005,
|
| 10 |
+
"[L]": 256006,
|
| 11 |
+
"[EXAMPLE]": 256007,
|
| 12 |
+
"[OUTPUT]": 256008,
|
| 13 |
+
"[DESCRIPTION]": 256009
|
| 14 |
+
},
|
| 15 |
+
"onnx_files": {
|
| 16 |
+
"fp32": {
|
| 17 |
+
"encoder": "onnx/encoder.onnx",
|
| 18 |
+
"classifier": "onnx/classifier.onnx",
|
| 19 |
+
"span_rep": "onnx/span_rep.onnx",
|
| 20 |
+
"count_embed": "onnx/count_embed.onnx"
|
| 21 |
+
},
|
| 22 |
+
"fp16": {
|
| 23 |
+
"encoder": "onnx/encoder_fp16.onnx",
|
| 24 |
+
"classifier": "onnx/classifier_fp16.onnx",
|
| 25 |
+
"span_rep": "onnx/span_rep_fp16.onnx",
|
| 26 |
+
"count_embed": "onnx/count_embed_fp16.onnx"
|
| 27 |
+
},
|
| 28 |
+
"int8": {
|
| 29 |
+
"encoder": "onnx/encoder_int8.onnx",
|
| 30 |
+
"classifier": "onnx/classifier_int8.onnx",
|
| 31 |
+
"span_rep": "onnx/span_rep_int8.onnx",
|
| 32 |
+
"count_embed": "onnx/count_embed_int8.onnx"
|
| 33 |
+
}
|
| 34 |
+
}
|
| 35 |
+
}
|
onnx/classifier.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1ed76f308554e94b2bb389d5f186d1ad378018861bee09dd99746f5fd176b081
|
| 3 |
+
size 1186506
|
onnx/classifier_fp16.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2bdabb37377f8dba8570646170e63e1008bb7b2c0360bbd339e4434a8c5f4cee
|
| 3 |
+
size 593983
|
onnx/classifier_int8.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:61133458388b60bf588d158e7296b9363744f507cfefbcf13906ab497a49c1c7
|
| 3 |
+
size 301840
|
onnx/count_embed.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:78e89cfa6ae760074b2ffb125760015faf18e439e2f3268008936444ca695589
|
| 3 |
+
size 258304
|
onnx/count_embed.onnx.data
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:3b4181175c786beb679b49e82d9b33d5330d626815cffc4061a419d0b595079f
|
| 3 |
+
size 6777344
|
onnx/count_embed_fp16.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1713826842118907088757e1bc855c3b8aa1ec5cab8e4fa2d6b7d65398431c6f
|
| 3 |
+
size 271137
|
onnx/count_embed_fp16.onnx.data
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:7bd47a1e6e46cc0fa3895061530e9344cede56c5d22bc39556d121cc5c263a4d
|
| 3 |
+
size 3375104
|
onnx/count_embed_int8.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:064854549090722f40714c4b6f5b57dda3e61047b56244ab95ace95791014fd9
|
| 3 |
+
size 1955108
|
onnx/encoder.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:99b8fc5e95eed3348e87d0a0b7a213c053c1cc730f86fc8f37c9950360bbee1c
|
| 3 |
+
size 562502073
|
onnx/encoder_fp16.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b4f7e40609b46952c71f620d658d033afc57e7541a329c630ef61148086f33c0
|
| 3 |
+
size 281675442
|
onnx/encoder_int8.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1c251526d1fe502b5ce2c3a5be04d9421e1a1c6fee3e21beb9fef7f9da41599e
|
| 3 |
+
size 141369019
|
onnx/span_rep.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:950b357c9fcf9688854024b66cd9de96788ae5a5a94ffa4009b73067bdf09261
|
| 3 |
+
size 16543168
|
onnx/span_rep_fp16.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:aa9671906b5f92cd508e1fd23ebfcaef23e6b30aa212cb29c7677922e92dc360
|
| 3 |
+
size 8276589
|
onnx/span_rep_int8.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2635e77cc3e65b353add9606078c875c498c01269d98fd310a028302e4a6d632
|
| 3 |
+
size 4165286
|
tokenizer.json
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b71cf441ac63c636686a771c74758b9d5d42c1fbea57eecd63bc567774d9ccc9
|
| 3 |
+
size 34365025
|
tokenizer_config.json
ADDED
|
@@ -0,0 +1,32 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"backend": "tokenizers",
|
| 3 |
+
"bos_token": "<bos>",
|
| 4 |
+
"clean_up_tokenization_spaces": false,
|
| 5 |
+
"cls_token": "<bos>",
|
| 6 |
+
"eos_token": "<eos>",
|
| 7 |
+
"extra_special_tokens": [
|
| 8 |
+
"[SEP_STRUCT]",
|
| 9 |
+
"[SEP_TEXT]",
|
| 10 |
+
"[P]",
|
| 11 |
+
"[C]",
|
| 12 |
+
"[E]",
|
| 13 |
+
"[R]",
|
| 14 |
+
"[L]",
|
| 15 |
+
"[EXAMPLE]",
|
| 16 |
+
"[OUTPUT]",
|
| 17 |
+
"[DESCRIPTION]"
|
| 18 |
+
],
|
| 19 |
+
"is_local": false,
|
| 20 |
+
"mask_token": "<mask>",
|
| 21 |
+
"model_input_names": [
|
| 22 |
+
"input_ids",
|
| 23 |
+
"attention_mask"
|
| 24 |
+
],
|
| 25 |
+
"model_max_length": 8192,
|
| 26 |
+
"pad_token": "<pad>",
|
| 27 |
+
"padding_side": "right",
|
| 28 |
+
"sep_token": "<eos>",
|
| 29 |
+
"spaces_between_special_tokens": false,
|
| 30 |
+
"tokenizer_class": "TokenizersBackend",
|
| 31 |
+
"unk_token": "<unk>"
|
| 32 |
+
}
|