Skip to main content

gliner2-mlx

PyPI version

An MLX port of GLiNER2 for fast information extraction on Apple Silicon.

GLiNER2 is a multi-task model for named entity recognition, text classification, relation extraction, and structured data extraction. This package runs the compute-heavy transformer encoder on MLX (Apple's GPU framework) while reusing GLiNER2's preprocessing and postprocessing, delivering significant speedups on Mac.

Installation

pip install gliner2-mlx

Or with uv:

uv add gliner2-mlx

Quick Start

from gliner2_mlx import GLiNER2MLX

model = GLiNER2MLX.from_pretrained("fastino/gliner2-base-v1")

# Named entity recognition
result = model.extract_entities(
    "Apple CEO Tim Cook announced the iPhone 15 launch in Cupertino.",
    ["company", "person", "product", "location"],
)
print(result)
# {'entities': {'company': ['Apple'], 'person': ['Tim Cook'], 'product': ['iPhone 15'], 'location': ['Cupertino']}}

Features

The API mirrors GLiNER2 — all extraction methods work the same way:

# Batch entity extraction
results = model.batch_extract_entities(
    ["Apple released iPhone 15.", "Google announced Pixel 8."],
    ["company", "product"],
    batch_size=8,
)

# Text classification
result = model.classify_text(
    "I love this product, it's amazing!",
    {"sentiment": ["positive", "negative", "neutral"]},
)

# Relation extraction
result = model.extract_relations(
    "Elon Musk founded SpaceX in 2002.",
    ["founded_by"],
)

# Structured data extraction
result = model.extract_json(
    "John Smith, aged 35, is a software engineer at Google.",
    {"person": ["name::str", "age::str", "company::str"]},
)

# Schema builder (same as GLiNER2)
from gliner2.inference.engine import Schema

schema = (
    Schema()
    .entities(["company", "person"])
    .relations(["works_for"])
)
result = model.extract("Tim Cook works at Apple.", schema)

Benchmark

Measured on Apple M3 Max, fastino/gliner2-base-v1, 1000 iterations per scenario with 10 warmup iterations. Interleaved execution order to eliminate systematic bias. All results statistically significant (p < 0.001, paired t-test).

Scenario PyTorch CPU MLX GPU Speedup
Single entity extraction 41.79 ms 14.35 ms 2.91x
Batch entity extraction (8 texts) 106.19 ms 35.41 ms 3.00x
Long text entity extraction 68.78 ms 19.55 ms 3.52x
Structure extraction 41.60 ms 14.24 ms 2.92x
Relation extraction 50.43 ms 17.06 ms 2.96x
Overall 61.76 ms 20.12 ms 3.07x

How It Works

gliner2-mlx ports the neural network inference to MLX while keeping GLiNER2 as a dependency for everything else:

  • MLX (GPU): DeBERTaV2 encoder, span representation, classification/count heads
  • GLiNER2 (CPU): Tokenization, schema processing, result formatting, overlap removal

On first use, from_pretrained automatically converts PyTorch weights to MLX format and caches them in ~/.cache/gliner2-mlx/.

Contributing

See CONTRIBUTING.md for development setup, running tests, linting, benchmarking, and publishing instructions.

License

MIT

Metadata

Release files for gliner2-mlx 0.1.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for gliner2-mlx 0.1.2
File Size Uploaded
gliner2_mlx-0.1.2.tar.gz 107.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for gliner2-mlx 0.1.2
File Interpreter ABI Platform
gliner2_mlx-0.1.2-py3-none-any.whl Python 3 none any Details

Total release size: 134.4 kB

Release files / gliner2_mlx-0.1.2.tar.gz

Download URL gliner2_mlx-0.1.2.tar.gz
Size 107.5 kB
Tags Source
SHA-256 checksum
How to use checksums
bcc8739513c9ec3d2f291e7300b4307c836f84abc959ec4d78a1bfeaca15f69a
BLAKE2b-256 checksum
How to use checksums
abc7571ed33d051773ed6392a9babcef869a8b0c083b87c923d76437d633b307
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 22, 2026.

Transparency log

Release files / gliner2_mlx-0.1.2-py3-none-any.whl

Download URL gliner2_mlx-0.1.2-py3-none-any.whl
Size 26.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a4c5dcb2bcba157e08ab8257e795d3fc1872b1ecea888288e5618406bb055bbe
BLAKE2b-256 checksum
How to use checksums
fd71b344e34f48b6ec01128878d7fa0c5ad5951d7a1337903583b9ff7477997b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Jul 22, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.1.2 This release

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page