This is a follow-up to my earlier question Lua: Semantic Similarity using Neural Networks.
For Semantic similarity I've execute the following code,
include('Conv.lua')
modelTrained = torch.load("download_local_location/modelSTS.trained.th", 'ascii')
modelTrained.convModel:evaluate()
modelTrained.softMaxC:evaluate()
local linputs = torch.zeros(rigth_sentence_length, emd_dimension)
linpus = XassignEmbeddingValuesX
local rinputs = torch.zeros(left_sentence_length, emd_dimension)
rinpus = XassignEmbeddingValuesX
local part2 = modelTrained.convModel:forward({linputs, rinputs})
local output = modelTrained.softMaxC:forward(part2)
local val = torch.range(0, 5, 1):dot(output:exp())
return val/5
And Execute it using the following command in terminal,
> th similarity.lua
But the error it displays is,
while creating metatable similarityMeasure.Conv: bad argument #1 (similarityMeasure is an invalid module name)
stack traceback:
[C]: in function 'newmetatable'
/torch/install/share/lua/5.2/torch/init.lua:102: in function 'class'
.../textSimilarityConvNet-master/Conv.lua:1: in main chunk
[C]: in function 'dofile'
/torch/install/share/lua/5.2/paths/init.lua:84: in function 'dofile'
/torch/install/share/lua/5.2/torch/init.lua:49: in function 'include'
similarity.lua:1: in main chunk
[C]: in function 'dofile'
.../torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk
[C]: in ?
First few lines in Conv.lua is,
local Conv = torch.class('similarityMeasure.Conv')
function Conv:__init(config)
self.mem_dim = config.mem_dim or 150
self.learning_rate = config.learning_rate or 0.01
self.batch_size = config.batch_size or 1 --25
self.num_layers = config.num_layers or 1
self.reg = config.reg or 1e-4
self.structure = config.structure or 'lstm' -- {lstm, bilstm}
self.sim_nhidden = config.sim_nhidden or 150
self.task = config.task or 'sic' -- or 'vid'
-- word embedding
self.emb_vecs = config.emb_vecs
self.emb_dim = config.emb_vecs:size(2)
Please guide me to solve this.
You are missing the similarityMeasure module (and likely other modules as well). I'm guessing that the things you are missing are dependencies that are not included with the default Torch installation. The installation instructions in the Github respository's readme file say the following:
Please install Torch deep learning library. We recommend this local
installation which includes all required packages our tool needs,
simply follow the instructions here: https://github.com/torch/distro
If you installed Torch some other way, try doing it using the linked distro instead and see if that fixes the problem.
It should work. Also the repo has been recently updated.
https://github.com/castorini/MP-CNN-Torch
Once you installed the torch library properly, then you can check and see the newly added/provided testDeployment.lua file, as an example to see how to use the trained model properly.
Related
I am having a problem with calling Lua built-in functions using Scribunto.
I created basic module Module:Item
local p = {};
function p.test(frame)
print("Hello World!")
end
return p
Which I call in different page as {{#invoke: Item | test}}
and I receive a following error:
Lua error in Module:Item at line 3: attempt to call global 'print' (a nil value).
Backtrace:
1. (tail call): ?
2. Module:Item:3: in function "chunk"
3. mw.lua:511: ?
4. (tail call): ?
5. [C]: in function "xpcall"
6. MWServer.lua:99: in function "handleCall"
7. MWServer.lua:313: in function "dispatch"
8. MWServer.lua:52: in function "execute"
9. mw_main.lua:7: in main chunk
10. [C]: ?
Since print is Lua built-in function I have the feeling the problem will be somewhere in setting on the pc.
However, when I imported wiki Infoboxes, they are working OK.
Versions:
Linux Mint Tara - Cinnamon based on ubuntu 18
MediaWiki 1.31.7
Scribunto (106fbf4) 17:24, 15 May 2018
Lua 5.1.5
Any help pointing where the problem can be is highly appreciated.
Scribunto intentionally doesn't include print. The "Removed functions and packages" section in its manual says this about it:
This was discussed on wikitech-l and it was decided that it should be omitted in favour of return values, to improve code quality. If necessary, mw.log() may be used to output information to the debug console.
I'm learning the torch following the tutorials provided by torch team. When I typed lines below as provided by 'NNGraph Tutorial', sth unexpected happened:
-- it is common style to mark inputs with identity nodes for clarity.
input = nn.Identity()()
-- each hidden layer is achieved by connecting the previous one
-- here we define a single hidden layer network
h1 = nn.Tanh()(nn.Linear(20, 10)(input))
output = nn.Linear(10, 1)(h1)
mlp = nn.gModule({input}, {output})
x = torch.rand(20)
dx = torch.rand(1)
mlp:updateOutput(x)
mlp:updateGradInput(x, dx)
mlp:accGradParameters(x, dx)
-- draw graph (the forward graph, '.fg')
-- this will produce an SVG in the runtime directory
graph.dot(mlp.fg, 'MLP', 'MLP')
itorch.image('MLP.svg')
Error information:
...s/noahcao/torch/install/share/lua/5.2/graph/graphviz.lua:157: graphviz library could not be loaded.
stack traceback:
/Users/noahcao/torch/install/share/lua/5.2/itorch/main.lua:167: in function </Users/noahcao/torch/install/share/lua/5.2/itorch/main.lua:160>
[C]: in function 'error'
...s/noahcao/torch/install/share/lua/5.2/graph/graphviz.lua:157: in function 'graphvizFile'
...s/noahcao/torch/install/share/lua/5.2/graph/graphviz.lua:197: in function 'dot'
[string "-- it is common style to mark inputs with ide..."]:18: in main chunk
[C]: in function 'xpcall'
/Users/noahcao/torch/install/share/lua/5.2/itorch/main.lua:210: in function </Users/noahcao/torch/install/share/lua/5.2/itorch/main.lua:174>
(...tail calls...)
/Users/noahcao/torch/install/share/lua/5.2/lzmq/poller.lua:75: in function 'poll'
...s/noahcao/torch/install/share/lua/5.2/lzmq/impl/loop.lua:307: in function 'poll'
...s/noahcao/torch/install/share/lua/5.2/lzmq/impl/loop.lua:325: in function 'sleep_ex'
...s/noahcao/torch/install/share/lua/5.2/lzmq/impl/loop.lua:370: in function 'start'
/Users/noahcao/torch/install/share/lua/5.2/itorch/main.lua:389: in main chunk
[C]: in function 'require'
(command line):1: in main chunk
[C]: in ?
But I checked the graphviz.lua file, that seems OK. I couldn't understand what the information wants to tell me.
I have also faced the same issue. This solved my issue:
# Mac users
brew install graphviz
# Debian/Ubuntu users
sudo apt-get install graphviz -y
Hope this might help someone.
Please check this link for Graph package of Torch.
I have lua 5.2, Torch version 7, Ubuntu version 14.04 trusty Installed
I am trying to run the following code
++++++++++++++++++++++code++++++++++++++++++++++++++++++++++++++++++++
require 'neuralconvo' require 'xlua'
-- Load Dataset
print("--Loading Dataset")
dataset=neuralconvo.Dataset(neuralconvo.CornellMovieDiaogs("data/cornell_movie_diaogs"),
{ loadFirst = options.dataset,
minWordFreq = options.minWordFreq
})
--Build Model
model = neuralconvo.Seq2Seq(dataset.wordsCount, options.hiddenSize) model.goToken = dataset.goToken
model.eosToken=dataset.eosToken
--Training Parameters
model.criterion=nn.SequencerCriterion(nn.ClassNLLCriterion())
model.learningRaw = options.learningRate
model.momentum = otions.momentum
local decayFactor = (options.minLR - options.learningRate)/options.saturateEpoch local minMeanError = nil
--Enable Cuda
if options.cuda then
require 'cutorch'
require 'cunn'
elseif options.opencl then
require 'cltorch'
require 'clnn'
model:cl()
end
-- Train Model using backpropogation
for epoch = 1,options.maxEpoch do
local errors = torch.Tensor(dataset.examplesCount):fill(0)
local timer=torch.timer()
local i=1
for examples in dataset:batches(options.batchSize) do
collectgarbage()
for _, example in ipairs(examples) do
local input, target = unpack(examples) do
if options.cuda then
input = input:cuda()
target = target:cuda()
elseif options.opencl then
input = input:cl()
target = target:cl()
end
local err=model:train(input, target)
if err ~= err then
error("Invalid error! Exiting.")
end
errors[i] = err
xlua.progress(i, dataset.examplesCount)
i=i+1
end
end
timer:stop()
--Save the model if not Improved
if minMeanError == nil or errors:mean() < minMeanError then
print("\n(Saving model...)")
torch.save("data/model.t7",model)
minMeanError=errors:mean()
end
-- Update Learning Rate
model.learningRate = model.learningRate + decayFactor
model.learningRate = math.max(options.minLR,model.learningRate)
end
end
=============================================================
I get the following error
luajit: error loading module 'libpaths' from file '/home/guru99u2/torch/install/lib/lua/5.2/libpaths.so':
/home/guru99u2/torch/install/lib/lua/5.2/libpaths.so: undefined symbol: luaL_setfuncs
stack traceback:
[C]: at 0x00450240
[C]: in function 'require'
/home/guru99u2/torch/install/share/lua/5.2/paths/init.lua:1: in main chunk
[C]: in function 'require'
/home/guru99u2/torch/install/share/lua/5.2/torch/init.lua:12: in main chunk
[C]: in function 'require'
./neuralconvo.lua:1: in main chunk
[C]: in function 'require'
bot.lua:1: in main chunk
[C]: at 0x00404d60
Something went wrong during the installation process (or you didn't clean the previous version) as you are trying to use modules built for Lua 5.2 with the interpreter that supports Lua 5.1 ABI (LuaJIT in this case). As the result you get that error undefined symbol: luaL_setfuncs because the dynamic library expects to have the function, but the loaded interpreter doesn't provide it.
Torch supports both LuaJIT and Lua 5.2, but you need to run ./clean.sh script as indicated in the documentation when switching Lua versions.
I am a newbies to torch. I have trainined my model according to 2 classes via this instruction https://github.com/soumith/imagenet-multiGPU.torch (number of classes is modifed) then, I wantted to test my model. These lines of codes are writen in instruction for testing:
dofile('donkey.lua')
img = testHook({loadSize}, 'test.jpg')
model = torch.load('model_10.t7')
if img:dim() == 3 then
img = img:view(1, img:size(1), img:size(2), img:size(3))
end
predictions = model:forward(img:cuda())
I got errors at the initial line of codes while I was trying to write.
When I try to write ;
th> dofile('donkey.lua')
I get these errors;
th> dofile("donkey.lua")
donkey.lua:18: attempt to index global 'opt' (a nil value)
stack traceback:
donkey.lua:18: in main chunk
[C]: in function 'dofile'
[string "_RESULT={dofile("donkey.lua")}"]:1: in main chunk
[C]: in function 'xpcall'
/home/leo/torch/install/share/lua/5.1/trepl/init.lua:651: in function 'repl'
...leo/torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:199: in main chunk
[C]: at 0x00406670
I don't know what to do. Thanks for helping.
You need to run opts.lua before running donkey.lua using
th> dofile("opts.lua")
Check main.lua and make sure, you are not missing any other dependencies.
Google's Deep Q Network for Atari Games is here.
https://github.com/rahular/deepmind-dqn
When I run it with GPU setting
./run_gpu <game name>
I had this error
../torch/bin/luajit: ./convnet.lua:22: attempt to call local 'convLayer' (a nil value)
stack traceback:
./convnet.lua:22: in function 'network'
./NeuralQLearner.lua:89: in function '__init'
...einforcement_Learning/torch/share/lua/5.1/torch/init.lua:51: in function <...einforcement_Learning/torch/share/lua/5.1/torch/init.lua:47>
[C]: at 0x7f419423d380
./initenv.lua:133: in function 'setup'
train_agent.lua:52: in main chunk
[C]: at 0x00406230
The code that caused this issue is in this file https://github.com/rahular/deepmind-dqn/blob/master/dqn/convnet.lua
and it is in this function
function create_network(args)
local net = nn.Sequential()
net:add(nn.Reshape(unpack(args.input_dims)))
--- first convolutional layer
local convLayer = nn.SpatialConvolution
if args.gpu >= 0 then
net:add(nn.Transpose({1,2},{2,3},{3,4}))
convLayer = nn.SpatialConvolutionCUDA
end
net:add(convLayer(args.hist_len*args.ncols, args.n_units[1],
args.filter_size[1], args.filter_size[1],
args.filter_stride[1], args.filter_stride[1],1))
net:add(args.nl())
The net:add(convLayer( is 22th line.
I used gpu setting so it seems
convLayer = nn.SpatialConvolutionCUDA
caused convLayer to be nil.
Does anyone know why nn.SpatialConvolutionCUDA returns a nil ?
Did the code originally come with GPU support, or did you add it yourself?
You should replaced the depreceated layers, i.e. replace:
net:add(nn.Transpose({1,2},{2,3},{3,4}))
convLayer = nn.SpatialConvolutionCUDA
with
convLayer = nn.SpatialConvolution
Check the documentation for the layers.
Edit: Use this branch, I fixed it for GPU support.
Found the solution.
using this github branch
https://github.com/soumith/deepmind-atari
After cloning this branch, then install cutorch and cunn using luarocks.
Now you can run the code.