Named Entity Recognition (LSTM + CRF) - Tensorflow
This repo implements a NER model using Tensorflow (LSTM + CRF + chars embeddings).
A better implementation is available here, using tf.data
and tf.estimator
, and achieves an F1 of 91.21
State-of-the-art performance (F1 score between 90 and 91).
Check the blog post
Given a sentence, give a tag to each word. A classical application is Named Entity Recognition (NER). Here is an example
John lives in New York
B-PER O O B-LOC I-LOC
Similar to Lample et al. and Ma and Hovy.
make glove
Alternatively, you can download them manually here and update the glove_filename
entry in config.py
. You can also choose not to load pretrained word vectors by changing the entry use_pretrained
to False
in model/config.py
.
make run
Here is the breakdown of the commands executed in make run
:
model/config.py
.python build_data.py
python train.py
python evaluate.py
Data iterators and utils are in model/data_utils.py
and the model with training/test procedures is in model/ner_model.py
Training time on NVidia Tesla K80 is 110 seconds per epoch on CoNLL train set using characters embeddings and CRF.
The training data must be in the following format (identical to the CoNLL2003 dataset).
A default test file is provided to help you getting started.
John B-PER
lives O
in O
New B-LOC
York I-LOC
. O
This O
is O
another O
sentence
Once you have produced your data files, change the parameters in config.py
like
# dataset
dev_filename = "data/coNLL/eng/eng.testa.iob"
test_filename = "data/coNLL/eng/eng.testb.iob"
train_filename = "data/coNLL/eng/eng.train.iob"
This project is licensed under the terms of the apache 2.0 license (as Tensorflow and derivatives). If used for research, citation would be appreciated.