Skip to main content

Demo library

Project description

cobweb

the cobweb is a tiny neural network library that I created to gain deeper understanding of how neural nets are working underneath.

Installation

first of all checkout the requirements.txt

and simply use pip install cubweb command

basics

let's create a simple NN using cobweb

first you need to import MLP (model)

from cobweb.mlp import MLP

now we will create our model object.

you should pass your input (your training data) size as the first argument

and a list of tuples for each layer input size and it's activation function name

for instance imagine we want a NN with 4 layers such that the first layer has 12 neurons with tanh activation

the second layer has 8 neurons with tanh activation

the third layer has 4 neurons with the relu activation function

and the last layer has 3 neuron with the softmax activation functin and our inputs are 1*3 arrays.

our model will be created like this:

m = MLP(3,[(12,'tanh'),(8,"tanh"),(4,"relu"),(3,"softmax")])

[!TIP]

the default activation is relu so if you just pass a number or a tuple just with one elemnt like these are valid!

m = MLP(3,[(12,'tanh'),(8,"tanh"),(4,),(3,"softmax")])

m = MLP(3,[(12,'tanh'),(8,"tanh"),4,(3,"softmax")])

list of activations

you can pass these as activatins

  • "relu"

  • "tanh"

  • "softmax"

[!WARNING]

make sure you are always using the softmax activation with the cross_entropy loss and as the last layer!

because of the backpropagation of softmax and cross_entropy loss if you use it in other ways maybe lead to error or your network doesn't learn.

in other activations and losses you are totally free.

training the NN

now let's train our NN

for this we will use **m.update()**

update method gets these as input:

  • training data batch

  • target datas

  • loss_function (as str)

  • number of epochs

  • learning rate

by running this line of code our NN will be training:

m.update(x,y,loss_function="cross_entropy",epochs=100,learning_rate=0.01)

[!TIP]

the default valu for loss_function is "mse" which is MSE(mean squared error) loss.

the default value for epochs is 100

the default value for learning rate is 0.01

list of loss functions

  • "mse" for MSE

  • "mae" for MAE

  • "cross_entropy" for categorical cross entropy

also even you can use r2 score as loss function by passing "r2"

Credit

special tahnks to Andrej Karpathy

I learned the most of these codes by his Micro Grad.

Project details


Download files

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

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

cubweb-0.1.3-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file cubweb-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: cubweb-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.10.7

File hashes

Hashes for cubweb-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 26d3548b9c5d1d70a4a84ed31188eb4def02bef2817274ad25378bcc0216234b
MD5 cd5487b99883e73df40cb0238e1bb774
BLAKE2b-256 601d9a77e5970475c5f53429fec7c019f86309f197a05227fedaea89905179fa

See more details on using hashes here.

Supported by

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