繁体   English   中英

将保留标记添加到“tft.vocabulary”

[英]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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM