Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

support UTF-8 start_text #52

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions LanguageModel.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ require 'VanillaRNN'
require 'LSTM'

local utils = require 'util.utils'
local utf8 = require 'lua-utf8'


local LM, parent = torch.class('nn.LanguageModel', 'nn.Module')
Expand Down Expand Up @@ -122,9 +123,9 @@ end


function LM:encode_string(s)
local encoded = torch.LongTensor(#s)
for i = 1, #s do
local token = s:sub(i, i)
local encoded = torch.LongTensor(utf8.len(s))
for i = 1, utf8.len(s) do
local token = utf8.sub(s, i, i)
local idx = self.token_to_idx[token]
assert(idx ~= nil, 'Got invalid idx')
encoded[i] = idx
Expand Down
1 change: 0 additions & 1 deletion sample.lua
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ cmd:option('-gpu_backend', 'cuda')
cmd:option('-verbose', 0)
local opt = cmd:parse(arg)


local checkpoint = torch.load(opt.checkpoint)
local model = checkpoint.model

Expand Down
3 changes: 2 additions & 1 deletion torch-rnn-scm-1.rockspec
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ description = {
dependencies = {
"torch >= 7.0",
"nn >= 1.0",
"luautf8 >= 1.2",
}
build = {
type = "builtin",
Expand All @@ -23,4 +24,4 @@ build = {
["torch-rnn.VanillaRNN"] = "VanillaRNN.lua",
["torch-rnn.TemporalCrossEntropyCriterion"] = "TemporalCrossEntropyCriterion.lua",
}
}
}