頂我在火炬下面LSTM模型實現,這是我從這裏拿了: https://github.com/wojzaremba/lstm/blob/master/main.luaLSTM在CNN
我有一個關於下面這段代碼的問題:
local function create_network()
local x = nn.Identity()()
local y = nn.Identity()()
local prev_s = nn.Identity()()
local i = {[0] = LookupTable(params.vocab_size,
params.rnn_size)(x)}
local next_s = {}
local split = {prev_s:split(2 * params.layers)}
for layer_idx = 1, params.layers do
local prev_c = split[2 * layer_idx - 1]
local prev_h = split[2 * layer_idx]
local dropped = nn.Dropout(params.dropout)(i[layer_idx - 1])
local next_c, next_h = lstm(dropped, prev_c, prev_h)
table.insert(next_s, next_c)
table.insert(next_s, next_h)
i[layer_idx] = next_h
end
local h2y = nn.Linear(params.rnn_size, params.vocab_size)
local dropped = nn.Dropout(params.dropout)(i[params.layers])
local pred = nn.LogSoftMax()(h2y(dropped))
local err = nn.ClassNLLCriterion()({pred, y})
local module = nn.gModule({x, y, prev_s},
{err, nn.Identity()(next_s)})
module:getParameters():uniform(-params.init_weight, params.init_weight)
return transfer_data(module)
end
在嵌入部分lstm輸入,代碼在處理ptb數據庫時使用LookupTable
層,現在我想知道如何使用LookupTable
來定義其他嵌入到不同類型的數據。特別地,輸入是RGB圖像,並且嵌入將是CNN模型之一,例如沒有完全連接層的AlexNet。 (https://gist.github.com/gcr/0bab9929dfee95164a4d)
它對我來說看起來太模糊。 有更好的設計爲此目的? 如何在CNN模型上創建LSTM?