Skip to main content

edunn

🧠 Learn how modern, modular Neural Networks work by implementing a PyTorch/Keras-like framework.

edunn is a very simple library that contains the basic elements to define, train and use modular Neural Networks using just Python and Numpy (full example).

import edunn as nn
x,y = load_data()
din,n_classes=4,10
layers = [nn.Linear(din,10),
          nn.Bias(10),
          nn.ReLU(),
          nn.Linear(10,n_classes),
          nn.Bias(n_classes),
          nn.Softmax()
          ]

model = nn.Sequential(layers)
print(model.summary())
error = nn.MeanError(nn.CrossEntropyWithLabels())
optimizer = nn.GradientDescent(lr=0.1,epochs=3000,batch_size=32)
history = optimizer.optimize(model,x,y,error)
nn.plot.plot_history(history)

We remove the key parts of edunn that deal with layers, initializers, error functions, backpropagation and optimizers. Then, through our guides, we help you reimplement the key parts of edunn. We also provide various automated tests along the way for you to check your solutions.

Supported languages:

🌈 Why edunn?

There are many excellent courses and books that teach you how to program neural networks from the ground up such as CS231n: Convolutional Neural Networks for Visual Recognition, Andrew Ng's Machine Learning or Sebastian Rascha's Python Machine Learning. However, while these are great for understanding the basics using numpy, they use monolithic neural network models that make it difficult to understand how that code translates to other frameworks such as pytorch or tensorflow.

Alternatively, Andrew Ng's Deep Learning or FastAI build modular networks out of tensorflow or basic pytorch operators instead of numpy. This is great for building complex models quickly, but there's still a lot of magic under the hood. Both frameworks automatically derive backward methods and bring along other goodies.

Implementing edunn allows you to understand how modern neural networks frameworks work and fills the gap between those types of learning. You get to program a full neural network framework, without all the magic pytorch or tensorflow bring along. Of course, edunn guides help you out along the way and provide a clear path to complete the implementation of the library. Also, in this case you'd actually be reimplementing edunn, since we provide a reference implementation you can check when in doubt with your solutions.

➕ Pre-requisite knowledge

The guides are intended for learners with some experience with Python, Numpy and Neural Networks. We have included explanations of what you must implement, but learners still should be able to:

  1. Read and write object-oriented python code, including subclassing and method overriding.
  2. Understand Numpy, basic linear algebra and calculus and be able to translate mathematical operations to Numpy code.
  3. Understand the basic ideas in modern modular Neural Network frameworks, such as models, layers, optimizers, batches, backward and forward passes, and specially backpropagation. It is also helpful but not necessary to have previous exposure to tensorflow/keras or pytorch.

🔧 Download and setup

Do not clone this repository if you want to use edunn as a learning exercise. Instead, follow these steps to get a working environment for the guides. These instructions assume a working installation of python3 (3.6 or greater), pip3 and virtualenv. The installations of those vary wildly with OS/distribution so it's up to you to get a setup working.

Afterward:

  1. Download a release for your language. If you prefer the command line, use wget, replacing es with your preferred language (only es is currently supported):

    wget https://github.com/facundoq/edunn/blob/main/releases/edunn-es.zip

  2. Unzip to edunn or other folder name you choose:

    unzip es.zip -d edunn && cd edunn

  3. Make sure Python3.6 or greater, pip3 and venv are installed:

    python3 --version
    pip3 --version && 
    python3 -c "import venv" && echo "venv is installed"
    
  4. Create a virtualenv environment and install the dependencies in the requirements file requirements.txt:

    python3 -m venv nnenv
    source nnvenv/bin/activate
    pip install -r requirements.txt
    

Alternatively, you can use your conda distribution or another such tool to create a virtual environment and install the required libraries for edunn (listed inside requirements.txt).

  1. Run jupyter and follow the guides:
jupyter notebook

💊 Solutions and bugs 🐛

edunn is designed so that you can automatically test your implementations. However, it is intended to be used as a set of exercises in a course or seminar. Please address all questions regarding the material to your instructor.

This repository also has a reference implementation in the edunn folder of the library you can consult.

Alternatively, you may consult public forums such as stack overflow, r/neuralnetworks or r/MachineLearning

Please, only file an issue if there is an actual bug or feature request, not if you can't solve the exercises.

📦 Reference implementation and usage as library

You can pip install edunn to use the reference implementation of the library to train models and use them. Indeed, the API is very simple:

import edunn as nn

x, y, n_classes = ...  # load data 
n, din = x.shape

# Model definition
layers = [nn.Linear(din, 10),
          nn.Bias(10),
          nn.ReLU(),
          nn.Linear(10, 20),
          nn.Bias(20),
          nn.TanH(),
          nn.Linear(10, n_classes),
          nn.Bias(n_classes),
          nn.Softmax()
          ]

model = nn.Sequential(layers)
print(model.summary())

error = nn.MeanError(nn.CrossEntropyWithLabels())
optimizer = nn.StochasticGradientDescent(lr=0.001, epochs=1000, batch_size=32)
history = optimizer.optimize(model, x, y, error)

However, we do not recommend for serious projects since the library is very slow and not meant for neither research nor production environments. The reference implementation is mostly focused on being easy to understand so that learners can check their implementations.

👥 Contributing

We'd like your help to expand edunn with more guides/layers/optimizers. Check out our contribution guide!

Metadata

Release files for edunn 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for edunn 0.1.6
File Size Uploaded Provenance Actions
edunn-0.1.6.tar.gz 152.8 kB Without provenance Details for edunn-0.1.6.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for edunn 0.1.6
File Interpreter ABI Platform Actions
edunn-0.1.6-py3-none-any.whl Python 3 none any Details for edunn-0.1.6-py3-none-any.whl

Total release size: 322.2 kB

Release files / edunn-0.1.6.tar.gz

Download URL edunn-0.1.6.tar.gz
Size 152.8 kB
Tags Source
SHA-256 checksum
How to use checksums
510262deda378ff2c375b005f90eb6db5ecb46cf0d4d3b2b232cc6e042225346
BLAKE2b-256 checksum
How to use checksums
37fdeaf436361fee8f2883f0047b1a4ecc59e0d28662dac18c5dce989fd208b5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.8.10

Release files / edunn-0.1.6-py3-none-any.whl

Download URL edunn-0.1.6-py3-none-any.whl
Size 169.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
2cf7942852333d3c10dba88bbc816b5a8114b2fad2f10564babb3a3d93701e4d
BLAKE2b-256 checksum
How to use checksums
e64e927310d45adb26f61e1e9bc6e91af38de4a9e8bb7c4a29427a1fe8cd331a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.0 CPython/3.8.10

Security for edunn 0.1.6

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.6 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page