NCRF++: An Open-source Neural Sequence Labeling Toolkit

Jul 17, 2021 | Data Science

In the world of Natural Language Processing (NLP), sequence labeling models are your best friends for tasks such as Named Entity Recognition (NER), part-of-speech tagging, and word segmentation. Enter NCRF++, a powerful, flexible, and open-source toolkit designed to streamline the development of these models. Buckle up as we take you on a ride through the features, requirements, and usage of NCRF++, ensuring your sprint towards NLP excellence is smooth and efficient!

1. Introduction

NCRF++ leverages state-of-the-art models and architectures involving the Conditional Random Field (CRF) and Long Short-Term Memory (LSTM) or Bidirectional LSTM (BiLSTM) structures. Imagine NCRF++ as a buffet for NLP enthusiasts where you can select from a variety of input features and output structures—all without messing with the code, thanks to its configurable settings!

2. Requirement

  • Python: Version 2 or 3
  • PyTorch: Version 1.0 (You can find a compatible version for PyTorch 0.3 here.)

3. Advantages

  • Fully Configurable: Set all neural model structures using a configuration file.
  • Performance: Achieve state-of-the-art results comparable to existing models.
  • Flexible Features: Design your own features and utilize pretrained embeddings.
  • Speed: Experience fast execution with batched operations.
  • N-best Output: Provides multiple outputs with the associated probabilities.

4. Usage

To harness the power of NCRF++, you will interact mainly through two phases—training and decoding. Start by running the following commands in your terminal:

python main.py --config demo.train.config

For decoding, use:

python main.py --config demo.decode.config

The configuration file manages everything from network structure to hyperparameters—without touching the code! More details are available here.

5. Data Format

NCRF++ accommodates both BIO and BIOES tag schemes. If you’re wondering about the IOB format, it’s not supported as it performs poorly. You can take a peek at the data format in the sample_data folder.

6. Performance

The results produced by NCRF++ on the CONLL 2003 English NER task stand shoulder to shoulder against the best existing models, including:

  • CharLSTM + WordLSTM + CRF: 91.20
  • CharCNN + WordLSTM + CRF: 91.35

These benchmarks prove NCRF++’s capabilities in achieving high accuracy.

7. Add Handcrafted Features

Handcrafted features are vital in sequence labeling tasks. NCRF++ allows you to create your own features through a configuration file, such as Capitalization or POS tags. It’s like customizing your pizza—add your favorite toppings!

8. Speed

Built to be efficient, NCRF++ employs fully batched computation, allowing the LSTM-CRF model to handle 1000 sentences during training and 2000 sentences during decoding. This is akin to a speedy chef in a bustling kitchen, quickly serving up delicious dishes!

9. N-best Decoding

Unlike traditional CRF structures that deliver a single label sequence, NCRF++ offers the tasty treat of n-best decoding. Setting the nbest=10 can yield significantly improved outcomes, providing you with a slice of performance you might have never imagined!

10. Reproduce Paper Results and Hyperparameter Tuning

If you wish to replicate results from the COLING 2018 paper, simply tweak the iteration settings in your configuration file. Tips for hyperparameter tuning can be found in the hyperparameter tuning guide.

11. Report Issue or Problem

Have questions or run into problems? Share your log file, configuration file, and sample data for prompt assistance. For more insights, updates, or to collaborate on AI development projects, stay connected with fxis.ai.

12. Future Plan

  • Document classification (working)
  • Support API usage
  • Upload trained models for various tasks
  • Enable loading pretrained ELMo parameters
  • Add BERT feature extraction layer

13. Update

  • 2018-Dec-17: NCRF++ v0.2, support for PyTorch 1.0
  • 2018-Mar-30: NCRF++ v0.1, initial version
  • 2018-Jan-06: added result comparison.

At fxis.ai, we believe that such advancements are crucial for the future of AI, as they enable more comprehensive and effective solutions. Our team is continually exploring new methodologies to push the envelope in artificial intelligence, ensuring that our clients benefit from the latest technological innovations.

Stay Informed with the Newest F(x) Insights and Blogs

Tech News and Blog Highlights, Straight to Your Inbox