获取BERT embedding表征的方法

1.获取句子的embedding

(用来做语义相似度计算的任务)

output_layer = model.get_pooled_output()
def get_pooled_output(self):
  return self.pooled_output

2.获取词级别的embedding

用来做seq2seq,ner任务

 def get_sequence_output(self):
    """Gets final hidden layer of encoder.

    Returns:
      float Tensor of shape [batch_size, seq_length, hidden_size] corresponding
      to the final hidden of the transformer encoder.
    """
    return self.sequence_output

 

你可能感兴趣的:(获取BERT embedding表征的方法)