首先,“均值”或“第一”池的结果并不适用于所有令牌,因此您必须更改
call()函数:
elif self.pooling == "mean": result = self.bert(inputs=bert_inputs, signature="tokens", as_dict=True)["sequence_output" ] pooled = result
在build_model中,更改为:
embedding_size = 768in_id = Input(shape=(max_seq_length,), name="input_ids") in_mask = Input(shape=(max_seq_length,), name="input_masks")in_segment = Input(shape=(max_seq_length,), name="segment_ids")bert_inputs = [in_id, in_mask, in_segment] bert_output = BertLayer(n_fine_tune_layers=12, pooling="mean")(bert_inputs) bert_output = Reshape((max_seq_length, embedding_size))(bert_output)bilstm = Bidirectional(LSTM(128, dropout=0.2,recurrent_dropout=0.2,return_sequences=True))(bert_output)output = Dense(output_size, activation="softmax")(bilstm)



