ner english

flair

Introduction
This document details the English Named Entity Recognition (NER) model from Flair, which is a 4-class NER model implemented using Flair embeddings and LSTM-CRF. The model predicts four entity types: PERSON (PER), LOCATION (LOC), ORGANIZATION (ORG), and MISCELLANEOUS (MISC) with an F1-Score of 93.06 on the corrected CoNLL-03 dataset.

Architecture
The model architecture utilizes Flair embeddings, which are based on contextual string embeddings, and a LSTM-CRF mechanism. This combination allows the model to capture complex patterns in text for accurate entity recognition.

Training
The model was trained using the Flair library with the CoNLL-03 dataset. The training process involves:

  1. Loading the dataset and defining 'ner' as the target tag.
  2. Creating a tag dictionary from the dataset.
  3. Initializing word and contextual embeddings, including GloVe and Flair embeddings.
  4. Stacking these embeddings to create the final embedding layer.
  5. Configuring a SequenceTagger with a hidden size of 256 and the stacked embeddings.
  6. Using a ModelTrainer to train the model for up to 150 epochs.

Guide: Running Locally
To run the model locally:

  1. Install Flair using pip: pip install flair.
  2. Use the following code to load the model and predict NER tags:
    from flair.data import Sentence
    from flair.models import SequenceTagger
    
    tagger = SequenceTagger.load("flair/ner-english")
    sentence = Sentence("George Washington went to Washington")
    tagger.predict(sentence)
    print(sentence)
    for entity in sentence.get_spans('ner'):
        print(entity)
    
  3. For cloud-based execution, consider using cloud GPU services like AWS, Google Cloud, or Azure to speed up processing.

License
The model and its associated code are subject to the licensing terms specified in the original Flair repository. Users should refer to the repository for detailed license information.

More Related APIs in Token Classification