juntaoy / biaffine-ner

Named Entity Recognition as Dependency Parsing
Apache License 2.0
350 stars 39 forks source link

关于mask 的问题 #12

Open LLLLLLoki opened 4 years ago

LLLLLLoki commented 4 years ago

请问为什么要mask的时候为什么保留左上角中的右上角的值,有什么理由吗,这个过程是怎么推理出来的呢?

juntaoy commented 4 years ago

没看懂你的问题能从新解释一下不:)

LLLLLLoki commented 4 years ago
text_len_mask = tf.sequence_mask(text_len, maxlen=max_sentence_length) # [num_sentence, max_sentence_length]
#tf.logical_and 逻辑且 false ture = false
candidate_scores_mask = tf.logical_and(tf.expand_dims(text_len_mask,[1]),tf.expand_dims(text_len_mask,[2])) #[num_sentence, max_sentence_length,max_sentence_length]
#生成左上角是True 的方阵[B,M,M]
sentence_ends_leq_starts = tf.tile(tf.expand_dims(tf.logical_not(tf.sequence_mask(tf.range(max_sentence_length),max_sentence_length)), 0),[num_sentences,1,1]) #[num_sentence, max_sentence_length,max_sentence_length]
candidate_scores_mask = tf.logical_and(candidate_scores_mask,sentence_ends_leq_starts)

flattened_candidate_scores_mask = tf.reshape(candidate_scores_mask,[-1]) #

就是在求candidate_ner_scores 时候用到的mask ,它不是一个类似于这样的矩阵吗 1 1 1 1 0 0 0 0 1 1 1 0 0 0 0 0 1 1 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0

LLLLLLoki commented 4 years ago

我知道gold label 是一个(l + 1) * l /2,为什么在选择用上述方法mask candidate_ner_scores,这个过程是怎么推理得到的?为什么不mask 成其他形状,比如右上角全是1 或者右下角

juntaoy commented 4 years ago

这个mask在flatten以后就刚好对应gold label的indices (0,0),(0,1)...(1,1)... 变成其他形状就不match gold label了啊