linear_crf
linear_crf¶
- class hanlp.components.mtl.tasks.pos.LinearCRFDecoder(hidden_size, num_labels, crf=False)[source]¶
A linear layer with an optional CRF (Lafferty et al. 2001) layer on top of it.
- Parameters
hidden_size – Size of hidden states.
num_labels – Size of tag set.
crf –
True
to enable CRF (Lafferty et al. 2001).
- forward(contextualized_embeddings: torch.FloatTensor, batch: Dict[str, torch.Tensor], mask=None)[source]¶
- Parameters
contextualized_embeddings – Hidden states for contextual layer.
batch – A dict of a batch.
mask – Mask for tokens.
- Returns
Logits. Users are expected to call
CRF.decode
on these emissions during decoding andCRF.forward
during training.