Search code examples
luamachine-learningtorch

What is correct usage of DataSource with torch/dp library


I am new to both programming language lua and torch library. I am trying to get some machine learning algorithms to work ASAP. I tried to get neural nets using dp library using example here. But I am unable to get my dataset into the form to feed into learning algorithm. I think my best and also initial guess was to do this:

train_set = dp.DataSet(dataset[1], dataset[2]) 
test_set = dp.DataSet(test_dataset[1], test_dataset[2])

ds = dp.DataSource(train_set=train_set, test_set=test_set)

Which gives error: filename.lua:56: ')' expected near '='

Where dataset[ 1] is a torch.Tensor containing information about the data and dataset[2] is torch.Tensor of binary information about the data I would like know.

Hope it is not a stupid syntax error.


Solution

  • Yep, this is a syntax error. Lua has no named arguments. Lua adepts use table to emulate such a feature.

    So, try this: dp.DataSource({train_set=train_set, test_set=test_set}) or just dp.DataSource{train_set=train_set, test_set=test_set} (you can remove parenthesis if a function has one parameter).