![](/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.