Lua with torch for semantic similarity

142 views
Skip to first unread message

Kumaran C

unread,
Jul 21, 2017, 3:23:04 AM7/21/17
to torch7
Hi, 

I've executing semantic similarity using torch. For that i've initiate the variable of,

local Conv = torch.class('similarityMeasure.Conv')

in my code. But it throws,

while creating metatable similarityMeasure.Conv: bad argument #1 (similarityMeasure is an invalid module name)

And I've already installed Lua and torch for this execution. Please someone guide me to solve this issue.

Tasty Minerals

unread,
Jul 22, 2017, 8:05:58 AM7/22/17
to torch7
The error says that you don't have 'similarityMeasure.Conv' dependency.
This is not a Torch module but a custom one.
Please read textSimilarityConvNet package installation instructions carefully. 
Besides people already correctly answered to your question on stackoverflow.

Marti

unread,
Jul 25, 2017, 12:48:51 AM7/25/17
to torch7
The repo you use is updated recently here:
https://github.com/castorini/MP-CNN-Torch

Thanks.

Kumaran C

unread,
Jul 25, 2017, 8:01:14 AM7/25/17
to torch7
Hi, 

Updated code rectified my previous issues, But when i try to load the model file(modelSTS.trained.th) provided throws the following error,

Warning: Failed to load function from bytecode: binary string: not a precompiled chunkWarning: Failed to load function from bytecode: [string "2"]:1: unexpected symbol near '2'Warning: Failed to load function from bytecode: [string "4"]:1: unexpected symbol near '4'Warning: Failed to load function from bytecode: [string "2"]:1: unexpected symbol near '2'Warning: Failed to load function from bytecode: [string "4"]:1: unexpected symbol near '4'Warning: Failed to load function from bytecode: [string "2"]:1: unexpected symbol near '2'Warning: Failed to load function from bytecode: [string "2"]:1: unexpected symbol near '2'Warning: Failed to load function from bytecode: [string "4"]:1: unexpected symbol near '4'Warning: Failed to load function from bytecode: [string "2"]:1: unexpected symbol near '2'Warning: Failed to load function from bytecode: [string "4"]:1: unexpected symbol near '4'Warning: Failed to load function from bytecode: [string "2"]:1: unexpected symbol near '2'Warning: Failed to load function from bytecode: [string "2"]:1: unexpected symbol near '2'Warning: Failed to load function from bytecode: [string "4"]:1: unexpected symbol near '4'Warning: Failed to load function from bytecode: [string "2"]:1: unexpected symbol near '2'Warning: Failed to load function from bytecode: [string "4"]:1: unexpected symbol near '4'Warning: Failed to load function from bytecode: [string "2"]:1: unexpected symbol near '2'Warning: Failed to load function from bytecode: [string "2"]:1: unexpected symbol near '2'Warning: Failed to load function from bytecode: [string "4"]:1: unexpected symbol near '4'Warning: Failed to load function from bytecode: [string "2"]:1: unexpected symbol near '2'Warning: Failed to load function from bytecode: [string "4"]:1: unexpected symbol near '4'Warning: Failed to load function from bytecode: [string "2"]:1: unexpected symbol near '2'Warning: Failed to load function from bytecode: [string "2"]:1: unexpected symbol near '2'Warning: Failed to load function from bytecode: [string "4"]:1: unexpected symbol near '4'Warning: Failed to load function from bytecode: [string "2"]:1: unexpected symbol near '2'Warning: Failed to load function from bytecode: [string "4"]:1: unexpected symbol near '4'Warning: Failed to load function from bytecode: [string "2"]:1: unexpected symbol near '2'Warning: Failed to load function from bytecode: [string "2"]:1: unexpected symbol near '2'Warning: Failed to load function from bytecode: [string "4"]:1: unexpected symbol near '4'Warning: Failed to load function from bytecode: [string "2"]:1: unexpected symbol near '2'Warning: Failed to load function from bytecode: [string "4"]:1: unexpected symbol near '4'/torch/install/bin/lua: /torch/install/share/lua/5.2/torch/File.lua:259: read error: read 0 blocks instead of 1 at /torch/pkg/torch/lib/TH/THDiskFile.c:352
stack traceback:
[C]: in function 'readInt'
/torch/install/share/lua/5.2/torch/File.lua:259: in function 'readObject'
/torch/install/share/lua/5.2/torch/File.lua:368: in function 'readObject'
/torch/install/share/lua/5.2/torch/File.lua:369: in function 'readObject'
/torch/install/share/lua/5.2/nn/Module.lua:192: in function 'read'
/torch/install/share/lua/5.2/torch/File.lua:351: in function 'readObject'
/torch/install/share/lua/5.2/torch/File.lua:369: in function 'readObject'
/torch/install/share/lua/5.2/torch/File.lua:369: in function 'readObject'
/torch/install/share/lua/5.2/nn/Module.lua:192: in function 'read'
/torch/install/share/lua/5.2/torch/File.lua:351: in function 'readObject'
...
/torch/install/share/lua/5.2/torch/File.lua:369: in function 'readObject'
/torch/install/share/lua/5.2/torch/File.lua:369: in function 'readObject'
/torch/install/share/lua/5.2/nn/Module.lua:192: in function 'read'
/torch/install/share/lua/5.2/torch/File.lua:351: in function 'readObject'
/torch/install/share/lua/5.2/torch/File.lua:369: in function 'readObject'
/torch/install/share/lua/5.2/torch/File.lua:353: in function 'readObject'
/torch/install/share/lua/5.2/torch/File.lua:409: in function 'load'
testDeployTrainedModel.lua:85: in main chunk
[C]: in function 'dofile'
.../torch/install/lib/luarocks/rocks/trepl/scm-1/bin/th:150: in main chunk
[C]: in ?

Can someone help me to solve this issue.

Marti

unread,
Jul 25, 2017, 9:46:48 PM7/25/17
to torch7
Looks like this is model reading problem only..

Make sure the model file is downloaded correctly and the model readin function is in ascii model (as in the testDeployment example script). I can run everything at my end.

Kumaran C

unread,
Jul 26, 2017, 6:44:08 AM7/26/17
to torch7
I'm trying to create a model file by running the trainSIC.lua file. But it creates the pred file in prediction directory. Please clarify me the concepts of creating the model file using pred file.

Thanks in advance

Marti

unread,
Jul 26, 2017, 9:32:17 PM7/26/17
to torch7
Yes. Without any modification tranSic.lua is supposed to generate the output file: which is "the pred file in prediction directory". So no problem on this.

Saving the trained model is another thing, but simple. Simply do:

--- Save the model
torch.save(filename, model).

-- load the model
model = torch.load(filename)

The model variable is the trained model. You can check this:
https://stackoverflow.com/questions/33288006/torch-lua-how-to-save-a-trained-neural-network-model-to-file

Kumaran C

unread,
Jul 31, 2017, 6:06:21 AM7/31/17
to torch7
I've write an lua file to create an model file But it replaces the existing pred file to some unreadable format, Following is the generator file,

//ModelGenerator.lua
require('torch')
require('nn')
model = nn.Sequential()
torch.save('results-dependency.1l.150d.pred',model)

Can someone help me to solve this issue.

Thanks in advance



On Friday, July 21, 2017 at 12:53:04 PM UTC+5:30, Kumaran C wrote:

Marti

unread,
Aug 2, 2017, 4:26:41 PM8/2/17
to torch7
torch.save('results-
dependency.1l.150d.pred',model)

Because you are using the same file name for model saving, therefore your existing pred file is replaced.

Simply do:
torch.save('model-saved.th',model)

You will no longer have this overriding issue.

Kumaran C

unread,
Aug 4, 2017, 2:36:30 AM8/4/17
to torch7
Hi Marti,

In your torch command there is no inclusion of pred file in it. I'm having some 12 pred files so please mention where we need to add pred file in it.

>  torch.save('model-saved.th',model)


Thanks in advance

On Friday, July 21, 2017 at 12:53:04 PM UTC+5:30, Kumaran C wrote:

Marti

unread,
Aug 4, 2017, 3:41:15 PM8/4/17
to torch7
pred files ARE the output of the model, not the model itself.

In the codes, one pred file is generated for each training-testing epoch. Therefore the number of the pred files depends on how many epoches you run with the training scripts.

This command, >torch.save('model-saved.th',model), saves the entire model weights to a file. And this model file (name: 'mode-saved.th') actually has nothing to do with the pred files. The model file and pred file are two different things.

The whole idea here is to save the model weights (model file name: 'mode-saved.th'), so you can reuse the model later. This process has nothing to do with the pred files. Please read the codes and you will figure out what is going on there. Thanks.
Reply all
Reply to author
Forward
0 new messages