首页 > 解决方案 > lua 代码文件中的函数 rembuff:floor() 出错:尝试调用方法“floor”(一个 nil 值)

问题描述

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

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

这是特定的功能:

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() 

我无法纠正这个错误:请帮助!

标签: luatorch

解决方案


推荐阅读