kingomalek
(Djelassi Malek)
December 3, 2017, 7:05pm
1
Hello,
As far as I know, beam search’s final result is the path with the highest probability. Where can I can the value of this probability inside OpenNMT-lua ? is there a way to add some paths manually to the search tree ?
Hello,
The final scores are gathered here:
return feats
end
function Translator:translateBatch(batch)
local encStates, context = self.model.models.encoder:forward(batch)
if self.args.dump_input_encoding then
return encStates[#encStates]
end
-- if we have a language model - initialize lm state with BOS
local lmStates, lmContext
if self.lm then
local bos_inputs = torch.IntTensor(batch.size):fill(onmt.Constants.BOS)
if #self.lm.dicts.src.features > 0 then
local inputs = { bos_inputs }
if #self.lm.dicts.src.features > 1 then
table.insert(inputs, {})
for _ = 1, #self.lm.dicts.src.features do
table.insert(inputs[2], bos_inputs)
end
You can hack you way in the search tree in the code that is looking for the next candidates:
finished[finishedBatches[b]] = finishedHypotheses[b]
histories[finishedBatches[b]] = finishedHistory[b]
end
t = t + 1
remaining = beams[t]:getRemaining()
end
return finished, histories
end
-- Generate kBest tokens based on top scores.
function BeamSearcher:_findKBest(beams, vocabSize, kBest, expandedScores, expandedNormScores)
local function topk(tensor, ...)
if torch.typename(tensor) == 'torch.CudaHalfTensor' then
tensor = tensor:cuda()
end
return tensor:topk(...)
end
local t = #beams
I hope these entry points are useful to you.
kingomalek
(Djelassi Malek)
December 4, 2017, 9:14am
3
thank you this is very helpful