modern gliner bi base v1.0

knowledgator

Introduction

GLiNER is a Named Entity Recognition (NER) model designed to identify any entity type using bidirectional transformer encoders. It serves as an efficient alternative to traditional NER models and large language models, offering flexibility without the resource constraints of larger models.

Architecture

The model employs a bi-encoder architecture, featuring a textual encoder based on ModernBERT-base and an entity label encoder using the BGE-small-en sentence transformer. Key advantages include the ability to recognize unlimited entity types, faster inference with preprocessed entity embeddings, and improved generalization to unseen entities. However, the architecture may struggle with disambiguating semantically similar entities due to limited inter-label interactions.

Training

GLiNER has been benchmarked across various datasets, showing competitive performance with an average score of 47.9%. It demonstrates enhanced efficiency compared to DeBERTa-based models, supporting context lengths up to 8,192 tokens.

Guide: Running Locally

  1. Install Required Packages

    • Update and install the gliner package:
      pip install gliner -U
      
    • Install the latest version of transformers:
      pip install git+https://github.com/huggingface/transformers.git
      
  2. Set Up the Model

    • Import GLiNER and load the pre-trained model:
      from gliner import GLiNER
      model = GLiNER.from_pretrained("knowledgator/modern-gliner-bi-base-v1.0")
      
    • Predict entities by providing text and labels:
      text = "Your text here"
      labels = ["entity labels"]
      entities = model.predict_entities(text, labels, threshold=0.3)
      
  3. Optimize Performance

    • Install flash-attn and triton for flash attention:
      pip install flash-attn triton
      
    • Enable flash attention and set maximum sequence length:
      model = GLiNER.from_pretrained("knowledgator/modern-gliner-bi-base-v1.0", _attn_implementation='flash_attention_2', max_len=2048).to('cuda:0')
      
  4. Suggested Cloud GPUs

    • Use cloud services like AWS, GCP, or Azure for GPU resources to enhance model performance during large-scale inference or training tasks.

License

GLiNER is released under the Apache-2.0 license, allowing for wide use and distribution under specified terms.

More Related APIs in Token Classification