![](/img/trans.png)
[英]How to use tft.compute_and_apply_vocabulary and tft.tfidf correctly?
[英]Add reserved tokens to `tft.vocabulary`
我想将 append 个单词添加到tft.vocabulary
创建的词汇表中,这些词汇不是训练样本的一部分(即<mask>
和<pad>
标记)。
我在文档中看到tft.vocabulary
function 可以接受一个参数key_fn
文档说:
如果您想生成覆盖特定键的词汇表,请提供 key_fn。
但是对于下面的 key_fn,它仍然没有 append 词汇表中的<mask>
和<pad>
标记。
def _key_fn(x):
return tf.constant(['<mask>', '<pad>'])
vocab = tft.vocabulary(
words,
key_fn = lambda x : _key_fn(x),
top_k = config.VOCAB_SIZE
)
你想要达到什么目的?
我不认为key_fn
是相关的,因为它只影响词汇表的排序(以及提供的前 k 个)
你能在附加信息后计算出词汇表吗?
tft.vocabulary(tf.strings.join([words, <mask>, <pad>]), ...)
这将导致词汇表包含添加的后缀
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.