modern gliner bi large v1.0

knowledgator

GLiNER Model Documentation

Introduction

GLiNER is a Named Entity Recognition (NER) model designed to identify various entity types using a bidirectional transformer encoder architecture. It offers a scalable alternative to traditional NER models and Large Language Models (LLMs), being both resource-efficient and flexible for recognizing an unlimited number of entity types.

Architecture

The GLiNER model employs a bi-encoder architecture:

  • Textual Encoder: ModernBERT-large
  • Entity Label Encoder: BGE-base-en

This setup allows for:

  • Recognition of unlimited entities simultaneously.
  • Faster inference when entity embeddings are preprocessed.
  • Improved generalization to unseen entities.

The architecture improves efficiency up to fourfold compared to DeBERTa-based models and supports context lengths of up to 8,192 tokens.

Training

The model has been trained on datasets including urchade/pile-mistral-v0.1, numind/NuNER, and knowledgator/GLINER-multi-task-synthetic-data. It demonstrates competitive benchmarking results across various NER datasets.

Guide: Running Locally

  1. Install GLiNER and Transformers Library:

    pip install gliner -U
    pip install git+https://github.com/huggingface/transformers.git
    
  2. Load and Use the Model:

    from gliner import GLiNER
    
    model = GLiNER.from_pretrained("knowledgator/modern-gliner-bi-large-v1.0")
    
    text = "Your input text here"
    labels = ["entity types"]
    entities = model.predict_entities(text, labels, threshold=0.3)
    
    for entity in entities:
        print(entity["text"], "=>", entity["label"])
    
  3. Optional Enhancements:

    • Install flash attention for better performance:

      pip install flash-attn triton
      
    • Pre-embed entities for large datasets:

      entity_embeddings = model.encode_labels(labels, batch_size=8)
      outputs = model.batch_predict_with_embeds(texts, entity_embeddings, labels)
      

Cloud GPUs: Consider using cloud services like AWS EC2, Google Cloud Platform, or Azure for GPU support to handle large-scale inference or training efficiently.

License

GLiNER is released under the Apache-2.0 License, allowing for broad use and modification with proper attribution.

More Related APIs in Token Classification