Skip to content
/ learn Public

A lightweight, simple, and modular machine learning library written in pure Lua.

License

Notifications You must be signed in to change notification settings

Polkm/learn

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Learn's api is something like a combination between Torch and Scikit Learn. The purpose of Learn is to provide a flexible and portable neural network implementation that only depends on Lua. Learn is not multithreaded and does not use hardware acceleration, if you are looking for a high performance library I would suggest looking at Torch instead.

Start using Learn

Learn can be installed as a submodule for your git project by using the command:

git submodule add https://github.com/Polkm/learn.git learn

After you have Learn installed you can use it in an existing Lua project.

require("learn/learn")

Set up your training data

-- XOR training data
local train_features = {{0, 0}, {0, 1}, {1, 0}, {1, 1}}
local train_labels = {{0}, {1}, {1}, {0}}

Set up your model

local n_input = #train_features[1]
local n_output = #train_labels[1]

local model = learn.model.nnet({modules = {
  learn.layer.linear({n_input = n_input, n_output = n_input * 3}),
  learn.transfer.sigmoid({}),
  learn.layer.linear({n_input = n_input * 3, n_output = n_output}),
  learn.transfer.sigmoid({}),
}})

By default nnet will use the MSE criterion, appropriate for regression tasks.

Train your model on your data

local epochs = 1000
local error = model.fit(train_features, train_labels, epochs)

Make predictions using your newly trained model

for _, prediction in pairs(model.predict(train_features)) do
  print(table.concat(prediction, ", "))
end

About

A lightweight, simple, and modular machine learning library written in pure Lua.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages