Skip to main content

GLiNER2 information extraction on Apple Silicon via MLX

Project description

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

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_mlx-0.1.1.tar.gz (105.0 kB view details)

Uploaded Source

Built Distribution

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

gliner2_mlx-0.1.1-py3-none-any.whl (25.1 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for gliner2_mlx-0.1.1.tar.gz
Algorithm Hash digest
SHA256 d397a5270ca54da1f0f72e40b9c1fd33b96c2fb1273f72725b0a40ff4a2715dc
MD5 054760352e2482c465d6f6fa56b1667b
BLAKE2b-256 bc87520bbfabbf493e51954361b49ce36648f21103a9fc13ab38c8dc13ea73d2

See more details on using hashes here.

Provenance

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

Publisher: publish.yml on Andrew-Chen-Wang/gliner2-mlx

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_mlx-0.1.1-py3-none-any.whl.

File metadata

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

File hashes

Hashes for gliner2_mlx-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 b2b687ffba6adcb1c974f4271b73b5a3dc6d110fb0425b742e64c0f9f6a96779
MD5 786ce2e0603778a7fe3b5c53dbcd2b95
BLAKE2b-256 b279d2235b0bbed313cea804c8799ad970f73e8cd8d848755dfdb84486427228

See more details on using hashes here.

Provenance

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

Publisher: publish.yml on Andrew-Chen-Wang/gliner2-mlx

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