Skip to content

Commit

Permalink
Format probabilities as a table w/ columns.
Browse files Browse the repository at this point in the history
  • Loading branch information
macournoyer committed Dec 17, 2015
1 parent 4cd74d9 commit d66fdaa
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions eval.lua
Original file line number Diff line number Diff line change
Expand Up @@ -39,13 +39,19 @@ function pred2sent(wordIds, i)
return tokenizer.join(words)
end

function printProbabilities(wordIds, probabilities, i)
local words = {}
function printProbabilityTable(wordIds, probabilities, num)
print(string.rep("-", num * 22))

for p, wordId in ipairs(wordIds) do
local word = dataset.id2word[wordId[i]]
print(string.format("%-23s(%4d%%)", word, probabilities[p][i] * 100))
local line = "| "
for i = 1, num do
local word = dataset.id2word[wordId[i]]
line = line .. string.format("%-10s(%4d%%)", word, probabilities[p][i] * 100) .. " | "
end
print(line)
end

print(string.rep("-", num * 22))
end

function say(text)
Expand All @@ -62,9 +68,6 @@ function say(text)
print(">> " .. pred2sent(wordIds))

if options.debug then
for i = 1, 4 do
print(string.rep("-", 30))
printProbabilities(wordIds, probabilities, i)
end
printProbabilityTable(wordIds, probabilities, 4)
end
end

0 comments on commit d66fdaa

Please sign in to comment.