第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Keras - 從順序 API 到函數(shù)式 API 的轉(zhuǎn)換

Keras - 從順序 API 到函數(shù)式 API 的轉(zhuǎn)換

慕勒3428872 2021-07-07 14:58:46
我一直在關(guān)注 Towards Data Science 關(guān)于 word2vec 和 skip-gram 模型的教程,但我偶然發(fā)現(xiàn)了一個(gè)我無法解決的問題,盡管搜索了很多并嘗試了多個(gè)不成功的解決方案。https://towardsdatascience.com/understanding-feature-engineering-part-4-deep-learning-methods-for-text-data-96c44370bbfa由于使用了 keras.layers 中的 Merge 層,它向您展示了如何構(gòu)建 skip-gram 模型架構(gòu)的步驟似乎已被棄用。我試圖做的是將他的一段代碼(在 Keras 的 Sequential API 中實(shí)現(xiàn))轉(zhuǎn)換為 Functional API,以通過將其替換為 keras.layers.Dot 層來解決 Merge 層的棄用問題。但是,我仍然停留在將兩個(gè)模型(詞和上下文)合并到最終模型中的這一步,其架構(gòu)必須是這樣的:這是作者使用的代碼:from keras.layers import Mergefrom keras.layers.core import Dense, Reshapefrom keras.layers.embeddings import Embeddingfrom keras.models import Sequential# build skip-gram architectureword_model = Sequential()word_model.add(Embedding(vocab_size, embed_size,                         embeddings_initializer="glorot_uniform",                         input_length=1))word_model.add(Reshape((embed_size, )))context_model = Sequential()context_model.add(Embedding(vocab_size, embed_size,                  embeddings_initializer="glorot_uniform",                  input_length=1))context_model.add(Reshape((embed_size,)))model = Sequential()model.add(Merge([word_model, context_model], mode="dot"))model.add(Dense(1, kernel_initializer="glorot_uniform", activation="sigmoid"))model.compile(loss="mean_squared_error", optimizer="rmsprop")
查看完整描述

1 回答

?
holdtom

TA貢獻(xiàn)1805條經(jīng)驗(yàn) 獲得超10個(gè)贊

您正在將Model實(shí)例傳遞給圖層,但是由于錯(cuò)誤表明您需要將 Keras 張量(即圖層或模型的輸出)傳遞給 Keras 中的圖層。你在這里有兩個(gè)選擇。一種是像這樣使用實(shí)例的.output屬性Model:


dot_output = layers.dot([word_model.output, context_model.output], axes=1, normalize=False)

或者等效地,您可以直接使用輸出張量:


dot_output = layers.dot([word_reshape, context_reshape], axes=1, normalize=False)

此外,您需要應(yīng)用Dense層,然后將層的dot_output實(shí)例Input作為 的輸入傳遞Model。所以:


model_output = layers.Dense(1, kernel_initializer='glorot_uniform',

                            activation='sigmoid')(dot_output)


model = Model([word_input, context_input], model_output)


查看完整回答
反對 回復(fù) 2021-07-13
  • 1 回答
  • 0 關(guān)注
  • 338 瀏覽
慕課專欄
更多

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號