Skip to main content

GLiNER2 ONNX runtime for NER and classification without PyTorch

Project description

gliner2-onnx

GLiNER2 ONNX runtime for Python. Runs GLiNER2 models without PyTorch.

This library is experimental. The API may change between versions.

Features

  • Zero-shot NER and text classification
  • Runs with ONNX Runtime (no PyTorch dependency)
  • FP32 and FP16 precision support
  • GPU acceleration via CUDA

All other GLiNER2 features such as JSON export are not supported.

Installation

pip install gliner2-onnx

NER

from gliner2_onnx import GLiNER2ONNXRuntime

runtime = GLiNER2ONNXRuntime.from_pretrained("lmo3/gliner2-large-v1-onnx")

entities = runtime.extract_entities(
    "John works at Google in Seattle",
    ["person", "organization", "location"]
)
# [
#   Entity(text='John', label='person', start=0, end=4, score=0.98),
#   Entity(text='Google', label='organization', start=14, end=20, score=0.97),
#   Entity(text='Seattle', label='location', start=24, end=31, score=0.96)
# ]

Classification

from gliner2_onnx import GLiNER2ONNXRuntime

runtime = GLiNER2ONNXRuntime.from_pretrained("lmo3/gliner2-large-v1-onnx")

# Single-label classification
result = runtime.classify(
    "Buy milk from the store",
    ["shopping", "work", "entertainment"]
)
# {'shopping': 0.95}

# Multi-label classification
result = runtime.classify(
    "Buy milk and finish the report",
    ["shopping", "work", "entertainment"],
    threshold=0.3,
    multi_label=True
)
# {'shopping': 0.85, 'work': 0.72}

CUDA

To use CUDA for GPU acceleration:

runtime = GLiNER2ONNXRuntime.from_pretrained(
    "lmo3/gliner2-large-v1-onnx",
    providers=["CUDAExecutionProvider", "CPUExecutionProvider"]
)

Precision

Both FP32 and FP16 models are supported. Only the requested precision is downloaded.

runtime = GLiNER2ONNXRuntime.from_pretrained(
    "lmo3/gliner2-large-v1-onnx",
    precision="fp16"
)

Models

Pre-exported ONNX models:

Model HuggingFace
gliner2-large-v1 lmo3/gliner2-large-v1-onnx
gliner2-multi-v1 lmo3/gliner2-multi-v1-onnx

Note: gliner2-base-v1 is not supported (uses a different architecture).

Exporting Models

To export your own models, clone the repository and use make:

git clone https://github.com/lmoe/gliner2-onnx
cd gliner2-onnx

# FP32 only
make onnx-export MODEL=fastino/gliner2-large-v1

# FP32 + FP16
make onnx-export MODEL=fastino/gliner2-large-v1 QUANTIZE=fp16

Output is saved to model_out/<model-name>/.

JavaScript/TypeScript

For Node.js, see @lmoe/gliner-onnx.js.

Credits

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

gliner2_onnx-0.1.1.tar.gz (9.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

gliner2_onnx-0.1.1-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

Details for the file gliner2_onnx-0.1.1.tar.gz.

File metadata

  • Download URL: gliner2_onnx-0.1.1.tar.gz
  • Upload date:
  • Size: 9.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gliner2_onnx-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0858337a867e47753046c1041d9c5e2e24a67940a9f566c37f174f861648b63f
MD5 777d628fc5f945ef520a0d2cf030f3ca
BLAKE2b-256 938b594e61d423ec912bc620ca8bd76a6da55c7d3089a9e3c4ee45ea5207fcf4

See more details on using hashes here.

Provenance

The following attestation bundles were made for gliner2_onnx-0.1.1.tar.gz:

Publisher: publish.yml on lmoe/gliner2-onnx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file gliner2_onnx-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: gliner2_onnx-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 10.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for gliner2_onnx-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4f1b8300a880a19c2fec6688b4af51491258f5deefaa84b5a0cebf7c9d5f3044
MD5 2456805575f35f31f640033187ce8beb
BLAKE2b-256 9367ae24b96a31433154eef40d962b90dde1640263aec748ac3040baaf824cc0

See more details on using hashes here.

Provenance

The following attestation bundles were made for gliner2_onnx-0.1.1-py3-none-any.whl:

Publisher: publish.yml on lmoe/gliner2-onnx

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page