NER with BiLSTM and CRFs
Implementing a BiLSTM network with CRFs requires adding a CRF layer on top of the BiLSTM network developed above. However, a CRF is not a core part of the TensorFlow or Keras layers. It is available through the tensorflow_addons
or tfa
package. The first step is to install this package:
!pip install tensorflow_addons==0.11.2
There are many sub-packages, but the convenience functions for the CRF are in the tfa.text
subpackage:
Figure 3.3: tfa.text methods
While low-level methods for implementing the CRF layer are provided, a high-level layer-like construct is not provided. The implementation of a CRF requires a custom layer, a loss function, and a training loop. Post training, we will look at how to implement a customized inference function that will use Viterbi decoding.
Implementing the custom CRF layer, loss, and model
Similar to the flow above, there will be an embedding layer and a BiLSTM layer. The output of the BiLSTM needs...