An implementation of a linear chain CRF in PyTorch.
To train a model, run python train_crf.py
.
To set custom training parameters, create a config.json
file (we recommend that you do this in the configs/
folder for record-keeping). Then, run: python train_crf.py --config config/path/to/config.json
.
There are two types of features: the transition features between different hidden states given by a transitions table, and features from observations to each hidden timestep given by either a stack of convolutional layers or by a stack of bidirectional LSTMs.
- Viterbi algorithm
- Forward Algorithm
- Sutton, McCallum, An Introduction to Conditional Random Fields,
https://arxiv.org/abs/1011.4088
Credit to Robert Guthrie's PyTorch's NLP tutorial for insight into good ways of structuring
a BiLSTM-based CRF code in PyTorch:
http://pytorch.org/tutorials/beginner/nlp/advanced_tutorial.html
The functions in dynamic.py
are also variations of code contained in the above tutorial.