Skip to main content

Installation

To begin using the GLiNER model, you can install the GLiNER Python library through pip, conda, or directly from the source.

Install via Pip

pip install gliner
ONNX runtime

If you intend to use the GPU-backed ONNX runtime, install GLiNER with the GPU feature. This also installs the onnxruntime-gpu dependency.

pip install gliner[gpu]

Install via Conda

conda install -c conda-forge gliner

Install from Source

To install the GLiNER library from source, follow these steps:

  1. Clone the Repository:

    First, clone the GLiNER repository from GitHub:

    git clone https://github.com/urchade/GLiNER
  2. Navigate to the Project Directory:

    Change to the directory containing the cloned repository:

    cd GLiNER
  3. Install Dependencies:

    tip

    It's a good practice to create and activate a virtual environment before installing dependencies:

    python -m venv venv
    source venv/bin/activate # On Windows use: venv\Scripts\activate

    Install the required dependencies listed in the requirements.txt file:

    pip install -r requirements.txt
  4. Install the GLiNER Package:

    Finally, install the GLiNER package using the setup script:

    pip install .
  5. Verify Installation:

    You can verify the installation by importing the library in a Python script:

    import gliner
    print(gliner.__version__)

Install FlashDeBERTa

Most GLiNER models use the DeBERTa encoder as their backbone. This architecture offers strong token classification performance and typically requires less data to achieve good results. However, a major drawback has been its slower inference speed. We developed FlashDeBERTa to combine the good performance of the model and bring a new level of efficiency.

To use FlashDeBERTa with GLiNER, install it:

pip install flashdeberta -U
tip

Before using FlashDeBERTa, please make sure that you have transformers>=4.47.0.

You need to export the environment variable to enable the usage of FlashDeBERTa: export USE_FLASHDEBERTA=1. And then you can export the GLiNER model, and it will automatically use FlashDeBERTa kernels.

model = GLiNER.from_pretrained("knowledgator/gliner-pii-large-v1.0")

FlashDeBERTa provides up to a 3× speed boost for typical sequence lengths—and even greater improvements for longer sequences. alt text