kmkurn / pytorch-crf

(Linear-chain) Conditional random field in PyTorch.
https://pytorch-crf.readthedocs.io
MIT License
944 stars 152 forks source link

issues about the parameter "num_tags" of the CRF()? #98

Closed XFR1998 closed 2 years ago

XFR1998 commented 2 years ago

I would like to know the the parameter "num_tags" of the CRF()? should the tagset={'O':0, 'B':1, 'I':2, '': 3, '': 4} include these two labels:'', ''?

because I need to ensure the hidden_size in the fully connected layer follow the lstm self.fc = nn.Linear(configs.hidden_size*self.num_directions, num_tags)
crf.decode(emissions=lstm_feats, mask=mask_tensor)

Thanks~

kmkurn commented 2 years ago

Hi, I'm not sure I understand the question. Basically, num_tags should be set to the size of possible tags for a token. So, if your task is NER with 3 entities: PER, LOC, and ORG, then you'll have 7 tags: O, B-PER, I-PER, B-LOC, I-LOC, B-ORG, and I-ORG. So, you set num_tags=7. Let me know if you still have questions.