lua代码文件中的函数rembuff:floor()错误:尝试调用方法“ floor”(nil值)

时间:2018-09-05 14:24:48

标签: lua torch

在机器翻译数据集中,我已经在Lua中成功地对模型进行了预训练。现在我开始训练模型。

但是我在函数rembuff:floor() Error: Attempt to call method 'floor' (a nil value)中的Lua文件中收到错误

这是特定功能:

function MarginBatchBeamSearcher:nextSearchStep(t, batch_pred_inp, batch_ctx, beam_dec, beam_scorer,gold_scores, target, target_w, gold_rnn_state_dec, delts, losses, global_noise)

local K = self.K
local resval, resind, rembuff = self.resval, self.resind, self.rembuff
local finalval, finalind = self.finalval, self.finalind
self:synchDropout(t, global_noise)
-- pred_inp should be what was predicted at the last step
local outs = beam_dec:forward({batch_pred_inp, batch_ctx, unpack(self.prev_state)})
local all_scores = beam_scorer:forward(outs[#outs]) -- should be (batch_l*K) x V matrix
local V = all_scores:size(2)
local mistaken_preds = {}
for n = 1, self.batch_size do
  delts[n] = 0
  losses[n] = 0
  if t <= target_w[n]-1 then -- only do things if t <= length (incl end token) - 2
    local beam_size = #self.pred_pfxs[n]
    local nstart = (n-1)*K+1
    local nend = n*K
    local scores = all_scores:sub(nstart, nstart+beam_size-1):view(-1) -- scores for this example
    -- take top K
    torch.topk(resval, resind, scores, K, 1, true)
    -- see if we violated margin
    torch.min(finalval, finalind, resval, 1) -- resind[finalind[1]] is idx of K'th highest predicted word
    -- checking that true score at least 1 higher than K'th
    losses[n] = math.max(0, 1 - gold_scores[n][target[t+1][n]] + finalval[1])
    -- losses[n] = math.max(0, - gold_scores[n][target[t+1][n]] + finalval[1])
    if losses[n] > 0 then
      local parent_idx = math.ceil(resind[finalind[1]]/V)
      local pred_word = ((resind[finalind[1]]-1)%V) + 1
      mistaken_preds[n] = {prev = self.pred_pfxs[n][parent_idx], val = pred_word}
      delts[n] = 1 -- can change.....
    else
      -- put predicted next words in pred_inp
      rembuff:add(resind, -1) -- set rembuff = resind - 1
      rembuff:div(V)
      --if rembuff.floor then
      rembuff:floor() 

我无法纠正此错误: 请帮忙!

0 个答案:

没有答案