Package: edunn
edunn:brain: Learn how modern, modular Neural Networks work by implementing a PyTorch/Keras-like framework.edunnis a very simple library that contains the basic elements to define, train and usemodularNeural Networks using just Python and Numpy (full example).importedunnasnnx,y=load_data()din,n_classes=4,10layers=[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)Weremovethe key parts ofedunnthat deal with layers, initializers, error functions, backpropagation and optimizers. Then, through our guides, we helpyoureimplementthe key parts ofedunn. We also provide various automated tests along the way for you to check your solutions.Supported languages:SpanishEnglish (coming soon):rainbow: Whyedunn?There are many excellent courses and books that teach you how to program neural networks from the ground up such asCS231n: Convolutional Neural Networks for Visual Recognition, Andrew Ng'sMachine Learningor Sebastian Rascha'sPython Machine Learning. However, while these are great for understanding the basics usingnumpy, they use monolithic neural network models that make it difficult to understand how that code translates to other frameworks such aspytorchortensorflow.Alternatively,Andrew Ng'sDeep LearningorFastAIbuild modular networks out oftensorflowor basicpytorchoperators 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 derivebackwardmethods and bring along other goodies.Implementingedunnallows 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 magicpytorchortensorflowbring along. Of course,edunnguides 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 bereimplementingedunn, since we provide a reference implementation you can check when in doubt with your solutions.:heavy_plus_sign: Pre-requisite knowledgeThe 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:Read and write object-oriented python code, including subclassing and method overriding.Understand Numpy, basic linear algebra and calculus and be able to translate  mathematical operations to Numpy code.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 totensorflow/kerasorpytorch.:wrench: Download and setupDo not clonethis repository if you want to useedunnas 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:Download areleasefor your language. If you prefer the command line, usewget, replacingeswith your preferred language (onlyesis currently supported):wget https://github.com/facundoq/edunn/blob/main/releases/edunn-es.zipUnzip toedunnor other folder name you choose:unzip es.zip -d edunn && cd edunnMake sure Python3.6 or greater, pip3 and venv are installed:python3--version
pip3--version&&python3-c"import venv"&&echo"venv is installed"Create a virtualenv environment and install the dependencies in the requirements filerequirements.txt:python3-mvenvnnenvsourcennvenv/bin/activate
pipinstall-rrequirements.txtAlternatively, you can use yourcondadistribution or another such tool to create a virtual environment and install the required libraries foredunn(listed insiderequirements.txt).Run jupyter and follow the guides:jupyternotebook:pill: Solutions and bugs :bug:edunnis 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 areference implementationin theedunnfolder of the library you can consult.Alternatively, you may consult public forums such asstack overflow,r/neuralnetworksorr/MachineLearningPlease,onlyfile an issueif there is an actual bugor feature request, not if you can't solve the exercises.:package: Reference implementation and usage as libraryYou canpip install edunnto use the reference implementation of the library to train models and use them. Indeed, the API is very simple:importedunnasnnx,y,n_classes=...# load datan,din=x.shape# Model definitionlayers=[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, wedo not recommendfor serious projects since the library isvery slowand 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.:busts_in_silhouette: ContributingWe'd like your help to expandedunnwith more guides/layers/optimizers. Check out ourcontribution guide!