亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

Keras Tokenizer num_words 指定了什么?

Keras Tokenizer num_words 指定了什么?

慕沐林林 2023-09-26 14:20:53
鑒于這段代碼:from tensorflow.keras.preprocessing.text import Tokenizersentences = [    'i love my dog',    'I, love my cat',    'You love my dog!']tokenizer = Tokenizer(num_words = 1)tokenizer.fit_on_texts(sentences)word_index = tokenizer.word_indexprint(word_index)無論num_words=1或num_words=100,當我在 jupyter 筆記本上運行此單元時,我都會得到相同的輸出,而且我似乎無法理解它在標記化方面有何不同。{'愛': 1, '我的': 2, '我': 3, '狗': 4, '貓': 5, '你': 6}
查看完整描述

1 回答

?
慕田峪4524236

TA貢獻1875條經驗 獲得超5個贊

word_index 它只是整個文本語料庫的單詞到 id 的映射,無論 num_words 是什么


區別在用法上很明顯。例如,如果我們調用texts_to_sequences


sentences = [

    'i love my dog',

    'I, love my cat',

    'You love my dog!'

]


tokenizer = Tokenizer(num_words = 1+1)

tokenizer.fit_on_texts(sentences)

tokenizer.texts_to_sequences(sentences) # [[1], [1], [1]]

僅返回愛情 ID,因為最常見的單詞


反而


sentences = [

    'i love my dog',

    'I, love my cat',

    'You love my dog!'

]


tokenizer = Tokenizer(num_words = 100+1)

tokenizer.fit_on_texts(sentences)

tokenizer.texts_to_sequences(sentences) # [[3, 1, 2, 4], [3, 1, 2, 5], [6, 1, 2, 4]]

返回最常見的 100 個單詞的 id


查看完整回答
反對 回復 2023-09-26
  • 1 回答
  • 0 關注
  • 128 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號