Skip to main content

Minimal autograd engine using numpy with minimal implementation of pyTorch or Jax like library for traning NNs.

Project description

embedML

pytorch like machine learning framework from scratch I started the repo with building a simple compiler for embeded platfroms, but later decided to make a self contained abstract baby machine learning framework.

Could be used mostly for the Educational purpose as well. Easy and full python implemtation using numpy. Smaller sibling or framworks like pytorch or jax :) and useful to see how the behind the scene of those bigger platfrom.

and it is only less than 200 lines of code!

Instal

pip install embedml

Example tarinig simiar to pytorch:

y = model(x)
loss = criterion(y, t)
loss.backward()   
opt.step()
opt.zero_grad()

or like this implement the gradient decent:

params = model.get_parameters()
for param in params:
  param -= param.grad * self.lr

Example of differentiation of a funtion

form Jax example:

from jax import grad
import jax.numpy as jnp

def tanh(x):  # Define a function
  y = jnp.exp(-2.0 * x)
  return (1.0 - y) / (1.0 + y)

grad_tanh = grad(tanh)  # Obtain its gradient function
print(grad_tanh(1.0))   # Evaluate it at x = 1.0
# prints 0.4199743

and similar (backward gradient) with embedML:

import numpy as np
from embedml.tensor import Tensor

def tanh(x):  # Define a function
    y = (-2 * x).exp()
    return (1 - y).div((1 + y))

x = Tensor(np.array(1))
y = tanh(x)
y.backward()

print(x.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

embedml-0.1.1-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file embedml-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: embedml-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 5.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.8.9

File hashes

Hashes for embedml-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4f4537d6f9d3b48e39ff4ae5e35cd620241ba49bce680821dc15feba0b563a47
MD5 45527c83a6dcc1b124085de7042e990e
BLAKE2b-256 37938be3eec70d721a8e33901f96a250917cd63d2576de2d2826e2209b574c5c

See more details on using hashes here.

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