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("lmoe/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("lmoe/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(
    "lmoe/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(
    "lmoe/gliner2-large-v1-onnx",
    precision="fp16"
)

Models

Pre-exported ONNX models:

Model HuggingFace
gliner2-large-v1 lmoe/gliner2-large-v1-onnx
gliner2-multi-v1 lmoe/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.0.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.0-py3-none-any.whl (10.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: gliner2_onnx-0.1.0.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.0.tar.gz
Algorithm Hash digest
SHA256 280c71b57c914cca2414fa374eb978dce44a3c626dbd401d15baab59f1a38a00
MD5 9cf3f3d2dd7d7d850dda36143cbedce0
BLAKE2b-256 b1c06d1aff850a264b038d3fe1a024a0b34db7c5852b9e76659918cb64cbc1dd

See more details on using hashes here.

Provenance

The following attestation bundles were made for gliner2_onnx-0.1.0.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.0-py3-none-any.whl.

File metadata

  • Download URL: gliner2_onnx-0.1.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ce058e9f9dfdc45bd3b236fc272c6d4325cd833d4e4062bd43e407dcf51c00e8
MD5 783698906cb0e16a69b024c569cea032
BLAKE2b-256 f32c67a051bc6de3d9f02ea43406f42563e751435fe8478e1a9621de5047b61d

See more details on using hashes here.

Provenance

The following attestation bundles were made for gliner2_onnx-0.1.0-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