YAML Metadata Warning: empty or missing yaml metadata in repo card (https://huggingface.co/docs/hub/model-cards#model-card-metadata)

NER Customer Support Model

This project builds and utilizes a Named Entity Recognition (NER) model tailored for customer support interactions. The model uses BERT and focuses on identifying customer-specific entities such as complaints, product names, and appointment information.

Introduction

The goal of this NER model is to improve customer support interactions by recognizing specific entities from customer queries. This enables automated systems to efficiently interpret and route customer queries based on recognized entities.

Requirements

This project requires Python 3.7.4 and specific libraries listed in the requirements.txt file. Notable dependencies include:

  • BERT (using the Transformers library)
  • PyTorch for model training and inference
  • seqeval for NER evaluation
  • pandas and numpy for data handling

Setup

  1. Clone the repository and install dependencies:

    pip install -r requirements.txt
    
  2. Download Pre-trained BERT model: Ensure you have a trained BERT model for token classification saved with configuration and weights. The model components should be available as separate files, such as config.json, pytorch_model.bin, and vocab.txt.

Usage

  1. Load the Model and Tokenizer:

    Specify the paths to the configuration, model weights, and tokenizer files:

    from transformers import BertForTokenClassification, BertConfig, BertTokenizer
    import torch
    
    # Specify paths
    config_path = "path/to/config.json"
    model_weights_path = "path/to/pytorch_model.bin"
    vocab_path = "path/to/vocab.txt"
    
    # Load config and model
    config = BertConfig.from_json_file(config_path)
    model = BertForTokenClassification(config)
    model.load_state_dict(torch.load(model_weights_path, map_location=torch.device('cpu')))
    
    # Load tokenizer
    tokenizer = BertTokenizer.from_pretrained(vocab_path)
    
    # Set device
    device = torch.device('cpu')
    model.to(device)
    
  2. Tag a Sentence:

    After loading the model, pass a sentence to be tagged for entities:

    sentence = "Your sample customer query here."
    
    # Tokenize and prepare inputs
    inputs = tokenizer(sentence, return_tensors="pt", truncation=True, padding=True)
    inputs = {key: val.to(device) for key, val in inputs.items()}
    
    # Predict tags
    with torch.no_grad():
        outputs = model(**inputs)
    logits = outputs.logits
    
    # Convert predictions to tags
    predictions = torch.argmax(logits, dim=-1).cpu().numpy()
    tags = [config.id2label[label] for label in predictions[0]]
    
    print("Tokens:", tokenizer.tokenize(sentence))
    print("Tags:", tags)
    

Results

The model will output tokens and their corresponding tags for the provided sentence, allowing you to see which entities were recognized.

File Structure

  • NER_Customer_final.ipynb: The main notebook containing data preprocessing, model training, and evaluation.
  • requirements.txt: Lists required libraries.
  • README.md: This file.

Additional Notes

Ensure that GPU support is enabled if available to speed up processing. The code is set to use CPU by default:

device = torch.device('cpu')
model.to(device)
Downloads last month
4
Inference Providers NEW
This model isn't deployed by any Inference Provider. ๐Ÿ™‹ Ask for provider support