将保留令牌添加到“tft.vocabulary”

发布于 2025-01-19 22:17:59 字数 536 浏览 4 评论 0原文

我想将单词附加到由tft.vocabulary创建的词汇中,这些词汇不是培训样本的一部分(即; 令牌)。

我在文档中看到tft.vocabulary函数可以采用一个参数key_fn,该文档说:

供应key_fn如果您想生成带有特定键覆盖的词汇。

但是,在下面的键_FN的情况下,它仍然不会附加< bask>< 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

)

I would like to append words to the vocabulary created by tft.vocabulary that are not a part of the training samples (i.e. <mask> and <pad> tokens).

I see in the docs that the tft.vocabulary function can take an argument key_fn which the docs says:

Supply key_fn if you would like to generate a vocabulary with coverage over specific keys.

but with the key_fn below it still does not append the <mask> and <pad> tokens to the vocabulary.


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

)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

海的爱人是光 2025-01-26 22:17:59

你想要实现什么目标?

我不认为 key_fn 相关,因为它只影响词汇表的顺序(以及提供的前 k 个)。

您可以在附加添加的信息后计算词汇表吗?

tft.vocabulary(tf.strings.join([words,,]), ...)

这将导致词汇表包含添加的后缀

What is it that you're trying to achieve?

I don't think that key_fn is related as it only affects the ordering of the vocabulary (and top k when provided)

Could you compute the vocabulary after appending the added information?

tft.vocabulary(tf.strings.join([words, <mask>, <pad>]), ...)

This would result in the vocabulary including the added suffix

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文