CoolFace
Modelpublic

leonpham1208/alpha-ner-bi-transformer

sourceHugging Faceupdated 1y agoView on Hugging Face
1likes7downloads
Model Card

Model Details

Model Description

This code demonstrates how to use the GLiNER model for Named Entity Recognition (NER) tasks. The model is loaded from the Hugging Face Hub and fine-tuned to predict entities such as 'product', 'productdetail', 'user', 'level', and 'daterange' from a given query.

Steps:

  1. 1.Load the pre-trained GLiNER model from the Hugging Face Hub.
  2. 2.Define the labels for entity recognition.
  3. 3.Provide a query for which entities need to be extracted.
  4. 4.Use the predict_entities method to extract entities with a specified confidence threshold.
  5. 5.The extracted entities are displayed in the output.

This example is useful for tasks like extracting structured information from unstructured text queries.

This is the model card of a ๐Ÿค— transformers model that has been pushed on the Hub. This model card has been automatically generated.

Uses

<!-- Address questions around how the model is intended to be used, including the foreseeable users of the model and those affected by the model. -->

Installation

bash
!pip install gliner
!pip install accelerate -U

Direct Use

python
from gliner import GLiNER
import torch

device = torch.device('cuda:0') if torch.cuda.is_available() else torch.device('cpu')
model = GLiNER.from_pretrained("leonpham1208/alpha-ner-bi-transformer")
model.to(device)

labels = ["product", "product_detail", "user", "level", "date_range"] 
query = "Get me a Win Loss Detail Report yesterday"

entities = model.predict_entities(query, labels, threshold=0.9)

Test

python
from spacy import displacy

queries = [
    "Get me a Win Loss Detail Report yesterday",
    "Get me a Win Loss Detail Report on day 10",
    "Win Loss Detail Report from 1/1 to 31/1",
    "Get me a Win Loss Detail Report for Direct Member who played Product Detail Sportsbook in Sportsbook Product from 01/02/2024 to 15/02/2024",
    "Give me my Win Loss Detail report  last week",
    "Give me a Win Loss Detail report for Sportsbook from last week.",
    "Give me my Win Loss Detail report  last week",
    "Get me a Win Loss Detail Report of master1",
    "Win/Loss details for Product Sportsbook"
]    


labels = ["product", "product_detail", "user", "level", "date_range"] 

for query in queries:
    
    entities = trained_model.predict_entities(query, labels, threshold=0.9)
    dic_ents = {
        "text": query,
        "ents": entities,
        "title": None
    }
    
    print(f"๐Ÿซ‚ Query: {query}")
    print(f"๐Ÿ˜ Entity: ")
    displacy.render(dic_ents, manual=True, style='ent')
    print("๐Ÿค–==========================================================================================๐Ÿค–")
    print("\n")