kmkurn / pytorch-crf

(Linear-chain) Conditional random field in PyTorch.

Home Page:https://pytorch-crf.readthedocs.io

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

issues about crf.decode()?

XFR1998 opened this issue · comments

What is the meaning about the 'mask' parameter of the crf.decode()? Could you provide an example about how to use it?
When I combine lstm with crf, how can I do this?
Thanks~

Hi, thanks for using the library.

The mask parameter is to indicate which input tokens are actual words (i.e. not padding/special tokens). So if you have an input of length 3 stored in a tensor of length 5, you should set the mask to be [True, True, True, False, False]. To use the CRF layer on top of an LSTM, let the LSTM compute the emission score tensor of shape BxNxT, and pass this tensor to the CRF as the emissions argument. B=batch size, N=sequence length, T=number of tags.

Thanks for your detailed reply.😄

No worries 😄 I assume this is solved so I'm closing the issue.