Skip to main content

a beautifully simplistic ml framework

Project description

froog unit test badge num downloads badge

froog the frog
froog: fast real-time optimization of gradients
a beautifully compact machine-learning library
homepage | documentation | pip

froog is an easy-to-read machine-learning library.

froog is meant for those looking to get into machine learning, who want to understand how the underlying machine learning framework's code works before they are ultra-optimized (which all modern ml libraries are).

froog encapsulates everything from linear regression to convolutional neural networks

all of this in under 1000 lines.

Installation

pip install froog

More information on downloading froog in the installation docs.

Features

Sneak Peek

from froog.tensor import Tensor
from froog.nn import Linear
import froog.optim as optim

class mnistMLP:
  def __init__(self):
    self.l1 = Tensor(Linear(784, 128))
    self.l2 = Tensor(Linear(128, 10))

  def forward(self, x):
    return x.dot(self.l1).relu().dot(self.l2).logsoftmax()

model = mnistMLP()
optim = optim.SGD([model.l1, model.l2], lr=0.001)

Overview

The most fundamental concept in all of froog and machine learning is the Tensor. A tensor is simply a matrix of matrices (more accurately a multi-dimensional array).

You can create a Tensor in froog by:

import numpy as np
from froog.tensor import Tensor

my_tensor = Tensor([1,2,3])

Notice how we had to import numpy. If you want to create a Tensor manually make sure that it is a Numpy array!

Learn more about froog Tensors here.

Actually creating something

Okay cool, so now you know that froog's main datatype is a Tensor and uses NumPy in the background. How do I actually build a model?

We wanted to make it as simple as possible for you to do so.

Here's an example of how to create an MNIST multi-layer perceptron (MLP)

from froog.tensor import Tensor
import froog.optim as optim
from froog.nn import Linear

class mnistMLP:
  def __init__(self):
    self.l1 = Tensor(Linear(784, 128))
    self.l2 = Tensor(Linear(128, 10))

  def forward(self, x):
    return x.dot(self.l1).relu().dot(self.l2).logsoftmax()

model = mnistMLP()
optim = optim.SGD([model.l1, model.l2], lr=0.001)

You can also create a convolutional neural net by

class SimpleConvNet:
  def __init__(self):
    conv_size = 5
    channels = 17
    self.c1 = Tensor(Linear(channels,1,conv_size,conv_size))     # (num_filters, color_channels, kernel_h, kernel_w)
    self.l1 = Tensor(Linear((28-conv_size+1)**2*channels, 128))  # (28-conv+1)(28-conv+1) since kernel isn't padded
    self.l2 = Tensor(Linear(128, 10))                            # MNIST output is 10 classes

  def forward(self, x):
    x.data = x.data.reshape((-1, 1, 28, 28))                          # get however many number of imgs in batch
    x = x.conv2d(self.c1).relu()                                      # pass through conv first
    x = x.reshape(shape=(x.shape[0], -1))
    return x.dot(self.l1).relu().dot(self.l2).logsoftmax()

Contributing

Pull requests will be merged if they:

  • increase simplicity
  • increase functionality
  • increase efficiency

More info on contributing

Documentation

Need more information about how froog works? Visit the documentation.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

froog-0.2.8.tar.gz (18.5 kB view hashes)

Uploaded Source

Built Distribution

froog-0.2.8-py3-none-any.whl (19.0 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page