Closed lopozz closed 1 year ago
This is the model @kmkurn . It is a stack of BERT-LSTM-CRF:
def init(self, config, doCRF = 'off'):
super(IndexerBert, self).init()
self.num_labels = config.num_labels
self.LSTM_hidden_dim = 250
self.bert = BertModel.from_pretrained("bert-base-uncased")
self.dropout = nn.Dropout(p=0.5)
self.lstm = nn.LSTM(input_size = config.hidden_size,
hidden_size = self.LSTM_hidden_dim,
batch_first=True,
bidirectional=True,
dropout=0.05)
self.crf = CRF(self.num_labels, batch_first=True)
self.classifier2 = nn.Linear(self.LSTM_hidden_dim*2, 2)
# Freeze BERT parameters
for name, param in list(self.bert.named_parameters())[:-50]:
param.requires_grad = False
def forwardCRF(self, input_ids, attention_mask = None, token_type_ids = None):
output, pooled_output = self.bert(input_ids,
attention_mask,
token_type_ids,
return_dict=False)
dropout_output = self.dropout(output)
input, (h_0, c_0) = self.lstm(dropout_output) # (batch, seq_len, 500)
linear_output = self.classifier2(input) # (batch, seq_len, 2)
return linear_output ```
Also, the prediction looks like this [1, 0, 1, 0, 1, 0, 1, 0, ...]. So just a sequence of alternated 1s and 0s. I don't know if it could help you to better understand my problem
Hi, thanks for using the library. One potential issue is that you convert the scores to long for the CRF. The scores are supposed to be floats. Can you try replacing scores.long()
with just scores
when calling both model.crf()
and model.crf.decode()
?
Hi, @kmkurn I had a similar problem that @vijay120 had. I also have this issue and the start, end, and transition scores do not update.