默认情况下,当oov_token=True时,keras是如何推断出词汇量不足的标记的。
根据keras的官方文档,它告诉我们,如果给定,它将被添加到word_index中,并用于替换text_to_sequence调用过程中的词汇量不足的单词。但是,如果没有显式地指定oov_token=True,则没有太多的细节。
发布于 2022-04-19 14:03:24
假设您指的是oov_token of tf.keras.preprocessing.text.Tokenizer,那么您应该看看源代码,以了解在引擎盖下发生了什么。在text_to_sequence方法中,您可以看到oov_token的索引为oov_token=True添加了两次
word_index中找不到序列中的单词时,这是映射到唯一整数值的词汇表中每个单词的字典。num_words和i作为某个单词的索引时,等于或高于num_words。以下是相关代码:
vect = []
for w in seq:
i = self.word_index.get(w)
if i is not None:
if num_words and i >= num_words:
if oov_token_index is not None:
vect.append(oov_token_index)
else:
vect.append(i)
elif self.oov_token is not None:
vect.append(oov_token_index)
yield vect另外,这里您可以看到,如果oov_token设置为True,则它总是得到索引1。
https://stackoverflow.com/questions/71925661
复制相似问题