v0.1.1 · MIT licensed
Neural networks in a few lines of Python.
pymlkit is a dependency-free multi-layer perceptron library. A C core for speed, a thin Python wrapper for comfort.
dev@pymlkit: ~/xor
dev@pymlkit:~/xor$ pip install pymlkitSuccessfully installed pymlkit-0.1.1dev@pymlkit:~/xor$ python xor.py[==========] 100% Epoch: 0/300 Loss: 0.117050[==========] 100% Epoch: 100/300 Loss: 0.000218[==========] 100% Epoch: 200/300 Loss: 0.000098Finished training 300, 300 epochs[0, 0] -> 0.019[0, 1] -> 0.993[1, 0] -> 0.993[1, 1] -> 0.005dev@pymlkit:~/xor$
Define, fit, predict.
Stack dense layers, pick a loss, call fit. Flat Python lists in, flat Python lists out. Save weights to a compact binary file and load them back later.
from pymlkit import Network, Activations, Losses
model = Network(2) # 2 inputs
model.add_dense(16, Activations.ReLU)
model.add_dense(1, Activations.Sigmoid)
model.set_loss(Losses.HalfMSE)
model.fit(train_x, train_y, lr=0.1, epochs=100, batch=16)
print(model.forward([0.1, 0.2])) # -> [0.93]
model.export("model.mlk")C core
Dense layers, backprop and mini-batch SGD in plain C. Training runs at native speed, no interpreter in the hot loop.
Zero dependencies
No NumPy, no PyTorch. A wheel is a few kilobytes and the Python side is one small file you can read in minutes.
Seven methods
Network, add_dense, set_loss, fit, forward, backward, export and load. The whole API fits in your head.
Runs in the browser
Ships a WebAssembly wheel. Pyodide installs it with micropip, so you can train a network without leaving this site.
