Import Dependencies¶

In [141]:
import math
import numpy as np
import matplotlib.pyplot as plt
%matplotlib inline

A Simple Function¶

In [142]:
def f(x):
    return 3*x**2 - 4*x + 5
In [143]:
f(3.0)
Out[143]:
20.0

Plot f For Different Values Of x¶

In [144]:
xs = np.arange(-5, 5, 0.25)
ys = f(xs)
plt.plot(xs, ys)
Out[144]:
[<matplotlib.lines.Line2D at 0x7f1647b75ac0>]

Finding The Derivative¶

A derivative lets you figure out how fast something is changing by looking at how it's changing over a really, really, really tiny amount of time. It's like taking a super close-up picture of something and seeing how it's changing just between two tiny moments.

In [126]:
from IPython.display import display, Math

derivative = r"\frac{d}{dx} f(x) = \lim_{h \to 0} \frac{f(x + h) - f(x)}{h}"
display(Math(derivative))
$\displaystyle \frac{d}{dx} f(x) = \lim_{h \to 0} \frac{f(x + h) - f(x)}{h}$
In [145]:
h = 0.000001
x = 2/3
(f(x + h) - f(x))/h
Out[145]:
2.999378523327323e-06

Les Get More Complex¶

In [146]:
def d(a, b, c):
    return a*b + c
In [147]:
h = 0.0001

# inputs
a = 2.0
b = -3.0
c = 10.0

d1 = d(a, b, c)

# find the derivative of d function wrt c by increasing c by a tiny amount
c += h

d2 = d(a, b, c)

print('d1', d1)
print('d2', d2)
print('slope', (d2 - d1)/h)
d1 4.0
d2 4.0001
slope 0.9999999999976694
In [148]:
h = 0.0001

# inputs
a = 2.0
b = -3.0
c = 10.0

d1 = d(a, b, c)

# find the derivative of d function wrt b by increasing b by a tiny amount
b += h

d2 = d(a, b, c)

print('d1', d1)
print('d2', d2)
print('slope', (d2 - d1)/h)
d1 4.0
d2 4.0002
slope 2.0000000000042206

Neural Network Node¶

In [163]:
class Value:
    def __init__(self, data, _children=(), _op='', label=''):
        self.data = data
        self.grad = 0.0 # derivative of l with respect to the value
        self._backward = lambda: None
        self._prev = set(_children)
        self._op = _op
        self.label = label

    def __repr__(self):
        return f"Value(data={self.data})"
    
    def __add__(self, other):
        other = other if isinstance(other, Value) else Value(other)
        out = Value(self.data + other.data, (self, other), '+')

        def _backward():
            self.grad += out.grad
            other.grad += out.grad
        out._backward = _backward

        return out
    
    def __mul__(self, other):
        other = other if isinstance(other, Value) else Value(other)
        out = Value(self.data * other.data, (self, other), '*')

        def _backward():
            self.grad += other.data * out.grad
            other.grad += self.data * out.grad
        out._backward = _backward

        return out

    def __pow__(self, other):
        assert isinstance(other, (int, float)), "only supporting int/float powers for now"
        out = Value(self.data**other, (self,), f'**{other}')

        def _backward():
            self.grad += (other * self.data**(other-1)) * out.grad
        out._backward = _backward

        return out

    def tanh(self):
        x = self.data
        t = (math.exp(2 * x) - 1) / (math.exp(2 * x) + 1)
        out = Value(t, (self,), 'tanh')

        def _backward():
            self.grad += (1 - t ** 2) * out.grad

        out._backward = _backward

        return out
    
    def relu(self):
        out = Value(0 if self.data < 0 else self.data, (self,), 'ReLU')

        def _backward():
            self.grad += (out.data > 0) * out.grad
        out._backward = _backward

        return out

    
    def tanh(self):
        x = self.data
        t = (math.exp(2 * x) - 1) / (math.exp(2 * x) + 1)
        out = Value(t, (self,), 'tanh')

        def _backward():
            self.grad += (1 - t ** 2) * out.grad

        out._backward = _backward

        return out
    
    def exp(self):
        x = self.data
        out = Value(math.exp(x), (self, ), 'exp')
        
        def _backward():
            self.grad += out.data * out.grad # NOTE: in the video I incorrectly used = instead of +=. Fixed here.
        
        out._backward = _backward
        return out

    def backward(self):
        # topological order all of the children in the graph
        topo = []
        visited = set()
        def build_topo(v):
            if v not in visited:
                visited.add(v)
                for child in v._prev:
                    build_topo(child)
                topo.append(v)
        build_topo(self)

        # go one variable at a time and apply the chain rule to get its gradient
        self.grad = 1
        for v in reversed(topo):
            v._backward()

    def __neg__(self): # -self
        return self * -1

    def __radd__(self, other): # other + self
        return self + other

    def __sub__(self, other): # self - other
        return self + (-other)

    def __rsub__(self, other): # other - self
        return other + (-self)

    def __rmul__(self, other): # other * self
        return self * other

    def __truediv__(self, other): # self / other
        return self * other**-1

    def __rtruediv__(self, other): # other / self
        return other * self**-1
In [150]:
a = Value(2.0, label='a')
b = Value(-3.0, label='b')
c = Value(10.0, label='c')
e = a*b; e.label = 'e'
d = e + c; d.label = 'd'
f = Value(-2.0, label='f')
L = d * f; L.label = 'L'
L
Out[150]:
Value(data=-8.0)

Graph Visualization Of Neural Network¶

In [80]:
from graphviz import Digraph


def trace(root):
    # builds a set of all nodes and edges in a graph
    nodes, edges = set(), set()

    def build(v):
        if v not in nodes:
            nodes.add(v)
            for child in v._prev:
                edges.add((child, v))
                build(child)

    build(root)
    return nodes, edges


def draw_dot(root):
    dot = Digraph(format='svg', graph_attr={'rankdir': 'LR'})  # LR = left to right

    nodes, edges = trace(root)
    for n in nodes:
        uid = str(id(n))
        # for any value in the graph, create a rectangular ('record') node for it
        dot.node(name=uid, label="{ %s | data %.4f | grad %.4f }" % (n.label, n.data, n.grad), shape='record')
        if n._op:
            # if this value is a result of some operation, create an op node for it
            dot.node(name=uid + n._op, label=n._op)
            # and connect this node to it
            dot.edge(uid + n._op, uid)

    for n1, n2 in edges:
        # connect n1 to the op node of n2
        dot.edge(str(id(n1)), str(id(n2)) + n2._op)

    return dot
In [157]:
draw_dot(L)
Out[157]:
%3 139733671979040 f data -1.9600 grad 4.0000 139733671378176* * 139733671979040->139733671378176* 139733671375920 data -6.2624 grad 0.0000 139733671375296+ + 139733671375920->139733671375296+ 139733671375920* * 139733671375920*->139733671375920 139733666494112 c data 9.9800 grad -2.0000 139733666494112->139733671375296+ 139733671378176 data -7.2865 grad 0.0000 139733671378176*->139733671378176 139733666495744 a data 2.0600 grad 6.0000 139733666495744->139733671375920* 139733671583600 b data -3.0400 grad -4.0000 139733671583600->139733671375920* 139733671375296 data 3.7176 grad 0.0000 139733671375296->139733671378176* 139733671375296+->139733671375296

Manual Backpropagation¶

Start here at the end and we're going to go reverse and calculate the gradient along all these intermediate values and really what we're computing for every single value here is the derivative of that node with respect to L.

The derivative of L with respect to L is just 1 and then we're going to derive what is the derivative of L with respect to f, with respect to d, with respect to c with respect to e, with respect to b, and with respect to a and in the neural network setting you'd be very interested in the derivative of basically this loss function L with respect to the weights of a neural network and here of course we have just these variables a, b, c and f but some of these will eventually represent the weights of a neural net and so we'll need to know how those weights are impacting the loss function.

We're interested basically in the derivative of the output with respect to some of its leaf nodes and those leaf nodes will be the weights of the neural net and the other leaf nodes of course will be the data itself but usually we will not want or use the derivative of the loss function with respect to data because the data is fixed but the weights will be iterated on using the gradient information.

In [152]:
def lol():
    h = 0.001

    a = Value(2.0, label='a')
    b = Value(-3.0, label='b')
    c = Value(10.0, label='c')
    e = a * b;
    e.label = 'e'
    d = e + c;
    d.label = 'd'
    f = Value(-2.0, label='f')
    L = d * f;
    L.label = 'L'
    L1 = L.data

    a = Value(2.0, label='a')
    b = Value(-3.0, label='b')
    b.data += h
    c = Value(10.0, label='c')
    e = a * b;
    e.label = 'e'
    d = e + c;
    d.label = 'd'
    f = Value(-2.0, label='f')
    L = d * f;
    L.label = 'L'
    L2 = L.data

    print((L2 - L1) / h)


lol()
-3.9999999999995595
In [97]:
display(Math(r"L = d*f"))
display(Math(r"\frac {dL} {dL} = 1"))
display(Math(r"\frac {dL} {df} = \frac {(d+h)*f - (d*f)} {h} = d"))
display(Math(r"\frac {dL} {dd} = f"))
$\displaystyle L = d*f$
$\displaystyle \frac {dL} {dL} = 1$
$\displaystyle \frac {dL} {df} = \frac {(d+h)*f - (d*f)} {h} = d$
$\displaystyle \frac {dL} {dd} = f$
In [153]:
L.grad = 1.0
f.grad = d.data
d.grad = f.data

Gradient check is when we are deriving gradients using backpropagation and getting the derivative with respect to all the intermediate results.

Numerical gradient is just estimating it using small step size.

Now we're getting to the crux of backpropagation. So this will be the most important node to understand because if you understand the gradient for this node you understand all of backpropagation and all of training of neural nets basically.

So we need to derive dL by dc in other words the derivative of L with respect to c. How is L sensitive to c so if we wiggle c how does that impact L.

We know how c impacts d and so just very intuitively if you know the impact that c is having on d and the impact d is having on L, we can calculate the impact of c on L.

In [98]:
display(Math(r"d = e+c"))
display(Math(r"\frac {dd} {dc} = \frac {(c+h) + e - (c+e)} {h} = 1.0"))
display(Math(r"\frac {dL} {de} = 1.0"))
$\displaystyle d = e+c$
$\displaystyle \frac {dd} {dc} = \frac {(c+h) + e - (c+e)} {h} = 1.0$
$\displaystyle \frac {dL} {de} = 1.0$

So, we know how L impacts d and now we know how c and e impact d, how do we put that information together to write dl by dc and the answer of course is the chain rule in calculus.

If a variable z depends on the variable y, which itself depends on the variable x (that is, y and z are dependent variables), then z depends on x as well, via the intermediate variable y. In this case, the chain rule is expressed as:

In [99]:
display(Math(r"\frac {dz} {dx} = \frac {dz} {dy} * \frac {dy} {dx}"))
$\displaystyle \frac {dz} {dx} = \frac {dz} {dy} * \frac {dy} {dx}$

What it means for us is a really exactly the same thing:

In [100]:
display(Math(r"\frac {dL} {dc} = \frac {dL} {dd} * \frac {dd} {dc}"))
$\displaystyle \frac {dL} {dc} = \frac {dL} {dd} * \frac {dd} {dc}$
In [154]:
c.grad = d.grad * 1
e.grad = d.grad * 1

Essentially the + just directly routes the gradients back.

In [104]:
display(Math(r"e = a * b"))
display(Math(r"\frac {dL} {da} = \frac {dL} {de} * \frac {de} {da}"))
display(Math(r"\frac {dL} {db} = \frac {dL} {de} * \frac {de} {db}"))
$\displaystyle e = a * b$
$\displaystyle \frac {dL} {da} = \frac {dL} {de} * \frac {de} {da}$
$\displaystyle \frac {dL} {db} = \frac {dL} {de} * \frac {de} {db}$
In [155]:
a.grad = e.grad * b.data
b.grad = e.grad * a.data

That's what back propagation is, just a recursive application of chain rule backwards through the computation graph.

Let's see this power in action just very briefly. What we're going to do is we're going to nudge our inputs to try to make L go up.

In [156]:
a.data += 0.01 * a.grad
b.data += 0.01 * b.grad
c.data += 0.01 * c.grad
f.data += 0.01 * f.grad

# run the forward pass again
e = a * b
d = e + c
L = d * f
In [116]:
from IPython import display
display.Image("https://cs231n.github.io/assets/nn1/neuron_model.jpeg")
Out[116]:

So we want to eventually build up neural networks and in the simplest case these are multilateral perceptrons. This is a two layer neural net and it's got these hidden layers made up of neurons and these neurons are fully connected to each other. Biological neurons are very complicated devices but we have very simple mathematical models of a neuron, you have some inputs axis and then you have these synapses that have weights on them, the w's are weights and then the synapse interacts with the input to.

This neuron multiplicative so what flows to the cell body of this neuron is w times x but there's multiple inputs so there's many w times x's flowing into the cell body. The cell body has also like some bias so this is kind of like the inert innate sort of trigger (happiness) of this neuron so this bias can make it a bit more trigger happy or a bit less trigger happy regardless of the input.

Basically we're taking all the w times x of all the inputs adding the bias and then we take it through an activation function and this activation function is usually some kind of a squashing function like a sigmoid or tanh.

In [117]:
plt.plot(np.arange(-5,5,0.2), np.tanh(np.arange(-5,5,0.2))); plt.grid();
In [158]:
# inputs x1,x2
x1 = Value(2.0, label='x1')
x2 = Value(0.0, label='x2')
# weights w1,w2
w1 = Value(-3.0, label='w1')
w2 = Value(1.0, label='w2')
# bias of the neuron
b = Value(6.8813735870195432, label='b')
# x1*w1 + x2*w2 + b
x1w1 = x1*w1; x1w1.label = 'x1*w1'
x2w2 = x2*w2; x2w2.label = 'x2*w2'
x1w1x2w2 = x1w1 + x2w2; x1w1x2w2.label = 'x1*w1 + x2*w2'
n = x1w1x2w2 + b; n.label = 'n'
o = n.tanh(); o.label = 'o'
In [161]:
draw_dot(o)
Out[161]:
%3 139733671569920 n data 0.8814 grad 0.5000 139733671568912tanh tanh 139733671569920->139733671568912tanh 139733671569920+ + 139733671569920+->139733671569920 139733671568912 o data 0.7071 grad 1.0000 139733671568912tanh->139733671568912 139733671437888 x1*w1 + x2*w2 data -6.0000 grad 0.5000 139733671437888->139733671569920+ 139733671437888+ + 139733671437888+->139733671437888 139733671439472 w1 data -3.0000 grad 1.0000 139733671438512* * 139733671439472->139733671438512* 139733671438512 x1*w1 data -6.0000 grad 0.5000 139733671438512->139733671437888+ 139733671438512*->139733671438512 139733671438608 x2 data 0.0000 grad 0.5000 139733671439760* * 139733671438608->139733671439760* 139733671439184 b data 6.8814 grad 0.5000 139733671439184->139733671569920+ 139733671438704 x1 data 2.0000 grad -1.5000 139733671438704->139733671438512* 139733671439760 x2*w2 data 0.0000 grad 0.5000 139733671439760->139733671437888+ 139733671439760*->139733671439760 139733671438320 w2 data 1.0000 grad 0.0000 139733671438320->139733671439760*
In [129]:
display(Math(r"o = tanh(n)"))
display(Math(r"\frac {do} {dn} = 1 - tanh(n)^2"))
display(Math(r"\frac {do} {dn} = 1 - o^2"))
$\displaystyle o = tanh(n)$
$\displaystyle \frac {do} {dn} = 1 - tanh(n)^2$
$\displaystyle \frac {do} {dn} = 1 - o^2$

Let's get rid of doing backpropagation manually by implementing the backward function for a whole expression graph. We have to make sure that the backward function calculates the gradients of a node only after calculating the gradients of all the nodes ahead of it in the graph. To do this we'll do a topological sort on the graph.

topo = []
visited = set()
def build_topo(v):
  if v not in visited:
    visited.add(v)
    for child in v._prev:
      build_topo(child)
    topo.append(v)
build_topo(o)
topo
In [160]:
o.backward()
In [173]:
# inputs x1,x2
x1 = Value(2.0, label='x1')
x2 = Value(0.0, label='x2')
# weights w1,w2
w1 = Value(-3.0, label='w1')
w2 = Value(1.0, label='w2')
# bias of the neuron
b = Value(6.8813735870195432, label='b')
# x1*w1 + x2*w2 + b
x1w1 = x1*w1; x1w1.label = 'x1*w1'
x2w2 = x2*w2; x2w2.label = 'x2*w2'
x1w1x2w2 = x1w1 + x2w2; x1w1x2w2.label = 'x1*w1 + x2*w2'
n = x1w1x2w2 + b; n.label = 'n'
# ----
e = (2*n).exp()
o = (e - 1) / (e + 1)
# ----
o.label = 'o'
In [174]:
o.backward()
In [175]:
draw_dot(o)
Out[175]:
%3 139733671377408 data 1.7627 grad 0.2500 139733671378704exp exp 139733671377408->139733671378704exp 139733671377408* * 139733671377408*->139733671377408 139733667325456 data 0.1464 grad 4.8284 139733667324736* * 139733667325456->139733667324736* 139733667325456**-1 **-1 139733667325456**-1->139733667325456 139733671376928 n data 0.8814 grad 0.5000 139733671376928->139733671377408* 139733671376928+ + 139733671376928+->139733671376928 139734148398144 w1 data -3.0000 grad 1.0000 139734148397328* * 139734148398144->139734148397328* 139733672053344 x2*w2 data 0.0000 grad 0.5000 139733672052096+ + 139733672053344->139733672052096+ 139733672053344* * 139733672053344*->139733672053344 139734148350640 x2 data 0.0000 grad 0.5000 139734148350640->139733672053344* 139734148398288 b data 6.8814 grad 0.5000 139734148398288->139733671376928+ 139733671569632 w2 data 1.0000 grad 0.0000 139733671569632->139733672053344* 139733671378128 data 2.0000 grad 0.2203 139733671378128->139733671377408* 139733668684032 data 6.8284 grad -0.1036 139733668684032->139733667325456**-1 139733668684032+ + 139733668684032+->139733668684032 139733671378704 data 5.8284 grad 0.0429 139733671378704->139733668684032+ 139734148865760+ + 139733671378704->139734148865760+ 139733671378704exp->139733671378704 139734148397328 x1*w1 data -6.0000 grad 0.5000 139734148397328->139733672052096+ 139734148397328*->139734148397328 139733668684080 data 1.0000 grad -0.1036 139733668684080->139733668684032+ 139733667324736 o data 0.7071 grad 1.0000 139733667324736*->139733667324736 139734148865760 data 4.8284 grad 0.1464 139734148865760->139733667324736* 139734148865760+->139734148865760 139734148865808 data -1.0000 grad 0.1464 139734148865808->139734148865760+ 139733672052096 x1*w1 + x2*w2 data -6.0000 grad 0.5000 139733672052096->139733671376928+ 139733672052096+->139733672052096 139734148398000 x1 data 2.0000 grad -1.5000 139734148398000->139734148397328*

Try With PyTorch Tensors (Single Element Tensors)¶

In [178]:
import torch

x1 = torch.Tensor([2.0]).double()                ; x1.requires_grad = True
x2 = torch.Tensor([0.0]).double()                ; x2.requires_grad = True
w1 = torch.Tensor([-3.0]).double()               ; w1.requires_grad = True
w2 = torch.Tensor([1.0]).double()                ; w2.requires_grad = True
b = torch.Tensor([6.8813735870195432]).double()  ; b.requires_grad = True
n = x1*w1 + x2*w2 + b
o = torch.tanh(n)

print(o.data.item())
o.backward()

print('---')
print('x2', x2.grad.item())
print('w2', w2.grad.item())
print('x1', x1.grad.item())
print('w1', w1.grad.item())
0.7071066904050358
---
x2 0.5000001283844369
w2 0.0
x1 -1.5000003851533106
w1 1.0000002567688737

So basically torch can do what we did which is a special case when your tensors are all single element tensors. The big deal with PyTorch is that everything is significantly more efficient because we are working with these tensor objects and we can do lots of operations in parallel on all of these tensors but otherwise what we've built very much agrees with the api of PyTorch.

Implement Neuron, Layer, Multi Layer Perceptron¶

In [206]:
class Module:

    def zero_grad(self):
        for p in self.parameters():
            p.grad = 0

    def parameters(self):
        return []

class Neuron(Module):

    def __init__(self, nin, nonlin=True):  # nin is the number of inputs to this neuron, our example has three inputs
        self.w = [Value(random.uniform(-1,1)) for _ in range(nin)]  # w is the weights for these inputs
        self.b = Value(0)  #  bias controls the overall trigger happiness of this neuron
        self.nonlin = nonlin

    def __call__(self, x):
        act = sum((wi*xi for wi,xi in zip(self.w, x)), self.b)
        return act.relu() if self.nonlin else act

    def parameters(self):
        return self.w + [self.b]

    def __repr__(self):
        return f"{'ReLU' if self.nonlin else 'Linear'}Neuron({len(self.w)})"

class Layer(Module):  # Layer is just a list of neurons

    def __init__(self, nin, nout, **kwargs):  # nout is the number of neurons in a Layer
        self.neurons = [Neuron(nin, **kwargs) for _ in range(nout)]

    def __call__(self, x):
        out = [n(x) for n in self.neurons]
        return out[0] if len(out) == 1 else out

    def parameters(self):
        return [p for n in self.neurons for p in n.parameters()]

    def __repr__(self):
        return f"Layer of [{', '.join(str(n) for n in self.neurons)}]"

class MLP(Module):  # Layer feed into an MLP sequentially

    def __init__(self, nin, nouts):  # nouts is a list of the sizes of all the Layers that we want in our MLP
        sz = [nin] + nouts
        self.layers = [Layer(sz[i], sz[i+1], nonlin=i!=len(nouts)-1) for i in range(len(nouts))]

    def __call__(self, x):
        for layer in self.layers:
            x = layer(x)
        return x

    def parameters(self):
        return [p for layer in self.layers for p in layer.parameters()]

    def __repr__(self):
        return f"MLP of [{', '.join(str(layer) for layer in self.layers)}]"
In [216]:
x = [2.0, 3.0, -1.0]
n = MLP(3, [4, 4, 1])
n(x)
Out[216]:
Value(data=0.5175318980563276)
In [217]:
draw_dot(n(x))
Out[217]:
%3 139731435225152 data 0.3618 grad 0.0000 139731433456544* * 139731435225152->139731433456544* 139731431637056 data -0.2394 grad 0.0000 139731433937120* * 139731431637056->139731433937120* 139731433619568 data 3.0000 grad 0.0000 139731433620192* * 139731433619568->139731433620192* 139731435225296 data -0.2721 grad 0.0000 139731433937072* * 139731435225296->139731433937072* 139731433185488 data -0.8590 grad 0.0000 139731433938272* * 139731433185488->139731433938272* 139731433185536 data 0.0000 grad 0.0000 139731433620384+ + 139731433185536->139731433620384+ 139731435225344 data 0.5978 grad 0.0000 139731433458416* * 139731435225344->139731433458416* 139731445113136 data 0.5399 grad 0.0000 139731433937600* * 139731445113136->139731433937600* 139731433185584 data -0.8253 grad 0.0000 139731432247200* * 139731433185584->139731432247200* 139731433185728 data 0.0000 grad 0.0000 139731433620912+ + 139731433185728->139731433620912+ 139731433185776 data -0.5252 grad 0.0000 139731435172288* * 139731433185776->139731435172288* 139731433185824 data -0.5612 grad 0.0000 139731435174064* * 139731433185824->139731435174064* 139731433185968 data 0.0000 grad 0.0000 139731431477936+ + 139731433185968->139731431477936+ 139731433620144 data -1.0122 grad 0.0000 139731432247008+ + 139731433620144->139731432247008+ 139731433620144+ + 139731433620144+->139731433620144 139731433620192 data 2.3796 grad 0.0000 139731433620624+ + 139731433620192->139731433620624+ 139731433620192*->139731433620192 139731433186160 data 0.3771 grad 0.0000 139731433621344* * 139731433186160->139731433621344* 139731433456544 data 0.4333 grad 0.0000 139731433457648+ + 139731433456544->139731433457648+ 139731433456544*->139731433456544 139731433620384 data -0.7592 grad 0.0000 139731433620384->139731433620624+ 139731433620384+->139731433620384 139731433456784 data -1.3665 grad 0.0000 139731433456928+ + 139731433456784->139731433456928+ 139731433456784* * 139731433456784*->139731433456784 139731433620624 data 1.6205 grad 0.0000 139731433620672+ + 139731433620624->139731433620672+ 139731433620624+->139731433620624 139731433620672 data 1.1978 grad 0.0000 139731433620720ReLU ReLU 139731433620672->139731433620720ReLU 139731433620672+->139731433620672 139731433620720 data 1.1978 grad 0.0000 139731433620720->139731433456544* 139731433620720->139731432247200* 139731433935488* * 139731433620720->139731433935488* 139731433620720->139731433937600* 139731433620720ReLU->139731433620720 139731433456928 data -2.5910 grad 0.0000 139731433456928->139731433457648+ 139731433456928+->139731433456928 139731433186688 data 0.4227 grad 0.0000 139731433621008* * 139731433186688->139731433621008* 139731433620912 data 0.0000 grad 0.0000 139731433620912->139731433620144+ 139731433620912+->139731433620912 139731433620960 data -1.0000 grad 0.0000 139731433620960->139731433621008* 139731433186832 data 0.8572 grad 0.0000 139731435174256* * 139731433186832->139731435174256* 139731433457168 data -1.2245 grad 0.0000 139731433457168->139731433456928+ 139731433457168+ + 139731433457168+->139731433457168 139731433621008 data -0.4227 grad 0.0000 139731433621008->139731433620672+ 139731433621008*->139731433621008 139731433187072 data 0.6486 grad 0.0000 139731431477744* * 139731433187072->139731431477744* 139731445114624 data 0.0000 grad 0.0000 139731433938896+ + 139731445114624->139731433938896+ 139731431024384 data -2.2617 grad 0.0000 139731431024480ReLU ReLU 139731431024384->139731431024480ReLU 139731431024384+ + 139731431024384+->139731431024384 139731433457456 data -0.0000 grad 0.0000 139731433459376+ + 139731433457456->139731433459376+ 139731433457456* * 139731433457456*->139731433457456 139731433457504 data 0.0000 grad 0.0000 139731433458752* * 139731433457504->139731433458752* 139731433457504ReLU ReLU 139731433457504ReLU->139731433457504 139731431024480 data 0.0000 grad 0.0000 139731431024480->139731433458416* 139731431024480ReLU->139731431024480 139731433621344 data 0.0000 grad 0.0000 139731433621344->139731433620912+ 139731433621344*->139731433621344 139731445114816 data 0.7203 grad 0.0000 139731433936304* * 139731445114816->139731433936304* 139731433457648 data -2.1577 grad 0.0000 139731433457648->139731433457504ReLU 139731433457648+->139731433457648 139731433621536 data -1.0122 grad 0.0000 139731433621536->139731433620144+ 139731433621536* * 139731433621536*->139731433621536 139731433187408 data 0.0000 grad 0.0000 139731435174736+ + 139731433187408->139731435174736+ 139731433457888 data 0.5175 grad 0.0000 139731433459184+ + 139731433457888->139731433459184+ 139731433457888+ + 139731433457888+->139731433457888 139731433187600 data -0.6643 grad 0.0000 139731431478800* * 139731433187600->139731431478800* 139731435227456 data 0.0842 grad 0.0000 139731433458944* * 139731435227456->139731433458944* 139731435227504 data 0.0000 grad 0.0000 139731433458080+ + 139731435227504->139731433458080+ 139731433187744 data 0.0000 grad 0.0000 139731435174640+ + 139731433187744->139731435174640+ 139731433458080 data 0.0000 grad 0.0000 139731433458080->139731433459376+ 139731433458080+->139731433458080 139731433187792 data -0.3796 grad 0.0000 139731435173152* * 139731433187792->139731435173152* 139731435227648 data 0.1477 grad 0.0000 139731433935104* * 139731435227648->139731433935104* 139731435227696 data -0.1307 grad 0.0000 139731435227696->139731433457456* 139731435227792 data -0.9047 grad 0.0000 139731435227792->139731433456784* 139731433458416 data 0.0000 grad 0.0000 139731433458416->139731433458080+ 139731433458416*->139731433458416 139731433458752 data -0.0000 grad 0.0000 139731433458752->139731433459184+ 139731433458752*->139731433458752 139731435252848 data 0.3650 grad 0.0000 139731433938704* * 139731435252848->139731433938704* 139731433188512 data -0.2250 grad 0.0000 139731433188512->139731433621536* 139731435228368 data 0.0000 grad 0.0000 139731433935872+ + 139731435228368->139731433935872+ 139731433458944 data 0.5175 grad 0.0000 139731433458944->139731433457888+ 139731433458944*->139731433458944 139731433188752 data 0.7932 grad 0.0000 139731433188752->139731433620192* 139731433459184 data 0.5175 grad 0.0000 139731433459184+->139731433459184 139731433188896 data 0.6709 grad 0.0000 139731435174352* * 139731433188896->139731435174352* 139731433188944 data 0.4047 grad 0.0000 139731435173632* * 139731433188944->139731435173632* 139731445116496 data 0.9803 grad 0.0000 139731433937456* * 139731445116496->139731433937456* 139731433189040 data 0.8776 grad 0.0000 139731435173200* * 139731433189040->139731435173200* 139731433459376 data 0.0000 grad 0.0000 139731433459376->139731433457888+ 139731433459376+->139731433459376 139731432246960 data -0.2609 grad 0.0000 139731432246960->139731432247008+ 139731432246960* * 139731432246960*->139731432246960 139731432247008 data -1.2731 grad 0.0000 139731432247008->139731431024384+ 139731432247008+->139731432247008 139731435228944 data -0.4707 grad 0.0000 139731435228944->139731433458752* 139731433189184 data 0.5194 grad 0.0000 139731435174976* * 139731433189184->139731435174976* 139731433189232 data -0.1728 grad 0.0000 139731433189232->139731432246960* 139731432247200 data -0.9886 grad 0.0000 139731432247200->139731431024384+ 139731432247200*->139731432247200 139731431477360 data 2.0000 grad 0.0000 139731431477360->139731431477744* 139731433935056 data 0.0000 grad 0.0000 139731433936688+ + 139731433935056->139731433936688+ 139731433935056+ + 139731433935056+->139731433935056 139731433935104 data 0.0000 grad 0.0000 139731433935104->139731433935872+ 139731433935104*->139731433935104 139731435172240 data 3.0000 grad 0.0000 139731435172240->139731435174976* 139731435172288 data 0.5252 grad 0.0000 139731435175648+ + 139731435172288->139731435175648+ 139731435172288*->139731435172288 139731431477744 data 1.2972 grad 0.0000 139731431477744->139731431477936+ 139731431477744*->139731431477744 139731433935488 data -0.8124 grad 0.0000 139731433936112+ + 139731433935488->139731433936112+ 139731433935488*->139731433935488 139731431477936 data 1.2972 grad 0.0000 139731435173968+ + 139731431477936->139731435173968+ 139731431477936+->139731431477936 139731435172528 data -1.0000 grad 0.0000 139731435172528->139731435172288* 139731431478224 data 3.0000 grad 0.0000 139731431478224->139731431478800* 139731433935872 data 0.0000 grad 0.0000 139731433935872->139731433457168+ 139731433935872+->139731433935872 139731435172960 data 3.9745 grad 0.0000 139731435172960->139731435175648+ 139731435172960+ + 139731435172960+->139731435172960 139731433936112 data -2.3680 grad 0.0000 139731433936160ReLU ReLU 139731433936112->139731433936160ReLU 139731433936112+->139731433936112 139731435173152 data -0.7592 grad 0.0000 139731435173152->139731433620384+ 139731435173152*->139731435173152 139731433936160 data 0.0000 grad 0.0000 139731433936160->139731433457456* 139731433936160ReLU->139731433936160 139731435173200 data 2.6328 grad 0.0000 139731435173200->139731435172960+ 139731435173200*->139731435173200 139731433936304 data 1.0880 grad 0.0000 139731433938608+ + 139731433936304->139731433938608+ 139731433936304*->139731433936304 139731431478800 data -1.9928 grad 0.0000 139731431478800->139731435173968+ 139731431478800*->139731431478800 139731435173632 data 0.8095 grad 0.0000 139731435173632->139731435174640+ 139731435173632*->139731435173632 139731435173680 data 2.3677 grad 0.0000 139731435174784+ + 139731435173680->139731435174784+ 139731435173680+ + 139731435173680+->139731435173680 139731433936688 data -1.0772 grad 0.0000 139731433936928+ + 139731433936688->139731433936928+ 139731433936688+->139731433936688 139731435173872 data 3.0000 grad 0.0000 139731435173872->139731435173200* 139731433936928 data -1.5556 grad 0.0000 139731433936928->139731433936112+ 139731433936928+->139731433936928 139731435173968 data -0.6956 grad 0.0000 139731435175456+ + 139731435173968->139731435175456+ 139731435173968+->139731435173968 139731435174064 data 0.5612 grad 0.0000 139731435174064->139731435175456+ 139731435174064*->139731435174064 139731433937072 data -1.2245 grad 0.0000 139731433937072->139731433457168+ 139731433937072*->139731433937072 139731435174112 data 2.0000 grad 0.0000 139731435174112->139731435173632* 139731433937120 data -1.0772 grad 0.0000 139731433937120->139731433936688+ 139731433937120*->139731433937120 139731435174208 data -1.0000 grad 0.0000 139731435174208->139731435174256* 139731435174256 data -0.8572 grad 0.0000 139731435174256->139731435174784+ 139731435174256*->139731435174256 139731433937312 data 6.1458 grad 0.0000 139731433937312->139731433458944* 139731433937312ReLU ReLU 139731433937312ReLU->139731433937312 139731435174352 data 1.3417 grad 0.0000 139731435174352->139731435174736+ 139731435174352*->139731435174352 139731433937456 data 4.4110 grad 0.0000 139731433938032+ + 139731433937456->139731433938032+ 139731433937456*->139731433937456 139731433937600 data 0.6467 grad 0.0000 139731433937696+ + 139731433937600->139731433937696+ 139731433937600*->139731433937600 139731435174640 data 0.8095 grad 0.0000 139731435174640->139731435173680+ 139731435174640+->139731435174640 139731435223792 data 0.0000 grad 0.0000 139731435223792->139731433935056+ 139731435174688 data 2.0000 grad 0.0000 139731435174688->139731435174352* 139731433937696 data 6.1458 grad 0.0000 139731433937696->139731433937312ReLU 139731433937696+->139731433937696 139731435174736 data 1.3417 grad 0.0000 139731435174736->139731435172960+ 139731435174736+->139731435174736 139731435174784 data 1.5104 grad 0.0000 139731435174832ReLU ReLU 139731435174784->139731435174832ReLU 139731435174784+->139731435174784 139731435174832 data 1.5104 grad 0.0000 139731435174832->139731433456784* 139731435174832->139731432246960* 139731435174832->139731433936304* 139731433938176* * 139731435174832->139731433938176* 139731435174832ReLU->139731435174832 139731435174976 data 1.5582 grad 0.0000 139731435174976->139731435173680+ 139731435174976*->139731435174976 139731433938032 data 4.4110 grad 0.0000 139731433938032->139731433938608+ 139731433938032+->139731433938032 139731433938176 data -0.4784 grad 0.0000 139731433938176->139731433936928+ 139731433938176*->139731433938176 139731433938272 data -0.0000 grad 0.0000 139731433938272->139731433935056+ 139731433938272*->139731433938272 139731435175360 data 4.4996 grad 0.0000 139731435175360->139731433621536* 139731435175360->139731433937072* 139731435175360->139731433937120* 139731435175360->139731433937456* 139731435175360ReLU ReLU 139731435175360ReLU->139731435175360 139731435175456 data -0.1344 grad 0.0000 139731435175696ReLU ReLU 139731435175456->139731435175696ReLU 139731435175456+->139731435175456 139731435175600 data 2.0000 grad 0.0000 139731435175600->139731435173152* 139731433938608 data 5.4990 grad 0.0000 139731433938608->139731433937696+ 139731433938608+->139731433938608 139731435175648 data 4.4996 grad 0.0000 139731435175648->139731435175360ReLU 139731435175648+->139731435175648 139731433479904 data -0.6782 grad 0.0000 139731433479904->139731433935488* 139731435175696 data 0.0000 grad 0.0000 139731435175696->139731433621344* 139731435175696->139731433935104* 139731435175696->139731433938272* 139731435175696->139731433938704* 139731435175696ReLU->139731435175696 139731433938704 data 0.0000 grad 0.0000 139731433938704->139731433938896+ 139731433938704*->139731433938704 139731433479952 data -0.3167 grad 0.0000 139731433479952->139731433938176* 139731435175792 data -1.0000 grad 0.0000 139731435175792->139731435174064* 139731433938896 data 0.0000 grad 0.0000 139731433938896->139731433938032+ 139731433938896+->139731433938896
In [218]:
xs = [
  [2.0, 3.0, -1.0],
  [3.0, -1.0, 0.5],
  [0.5, 1.0, 1.0],
  [1.0, 1.0, -1.0],
]
ys = [1.0, -1.0, -1.0, 1.0] # desired targets
In [219]:
ypred = [n(x) for x in xs]
ypred
Out[219]:
[Value(data=0.5175318980563276),
 Value(data=0.5035516656057866),
 Value(data=0.1992187635752545),
 Value(data=0.19200404755000194)]

The first one is -0.36 but we'd like it to be one so we should push this one higher and similarly we'd want to adjust the remaining predictions as well. How do we make the neural net and how do we tune the weights to better predict the desired targets. The trick used in deep learning to achieve this is to calculate a single number that somehow measures the total performance of your neural net and we call this single number the loss

The loss is a single number that we're going to define that basically measures how well the neural net is performing right now we have the intuitive sense that it's not performing very well. So, the loss will be high and we'll want to minimize the loss in this particular case what we're going to do is we're going to implement the mean squared error loss.

In [220]:
loss = sum((yout - ygt) ** 2 for ygt, yout in zip(ys, ypred))
loss
Out[220]:
Value(data=4.584426182625607)
In [221]:
loss.backward()
In [222]:
draw_dot(loss)
Out[222]:
%3 139731433750592 data 0.2328 grad 1.0000 139731433750832+ + 139731433750592->139731433750832+ 139731433750592**2 **2 139731433750592**2->139731433750592 139731435225152 data 0.3618 grad 0.0000 139731435174256* * 139731435225152->139731435174256* 139731433610304* * 139731435225152->139731433610304* 139731433776128* * 139731435225152->139731433776128* 139733472768112* * 139731435225152->139733472768112* 139731433947248 data 2.0736 grad -0.1334 139731433950320ReLU ReLU 139731433947248->139731433950320ReLU 139731433947248+ + 139731433947248+->139731433947248 139731435225296 data -0.2721 grad 0.0000 139731430489008* * 139731435225296->139731430489008* 139731435175648* * 139731435225296->139731435175648* 139731433609536* * 139731435225296->139731433609536* 139731433775360* * 139731435225296->139731433775360* 139731433849040 data -0.2723 grad 0.0000 139731433849088ReLU ReLU 139731433849040->139731433849088ReLU 139731433849040+ + 139731433849040+->139731433849040 139731433750784 data 0.0000 grad 1.0000 139731433750784->139731433750832+ 139731435225344 data 0.5978 grad 1.4677 139731435172816* * 139731435225344->139731435172816* 139731433610832* * 139731435225344->139731433610832* 139731433776656* * 139731435225344->139731433776656* 139733472768304* * 139731435225344->139733472768304* 139731433619712 data 6.1458 grad -0.0813 139731435174592* * 139731433619712->139731435174592* 139731433619712ReLU ReLU 139731433619712ReLU->139731433619712 139731433750832 data 0.2328 grad 1.0000 139731433751456+ + 139731433750832->139731433751456+ 139731433750832+->139731433750832 139731433947440 data 1.0000 grad -0.0397 139731433771120* * 139731433947440->139731433771120* 139731433849088 data 0.0000 grad -0.9661 139731433849088->139731433776656* 139731433849088ReLU->139731433849088 139731433619856 data 4.4110 grad -0.0813 139731433619904+ + 139731433619856->139731433619904+ 139731433619856* * 139731433619856*->139731433619856 139731433947536 data -0.0000 grad 2.3984 139731433950656+ + 139731433947536->139731433950656+ 139731433947536* * 139731433947536*->139731433947536 139731433619904 data 4.4110 grad -0.0813 139731433621296+ + 139731433619904->139731433621296+ 139731433619904+->139731433619904 139731433751024 data 1.0000 grad 3.0071 139731433751072+ + 139731433751024->139731433751072+ 139731433751072 data 1.5036 grad 3.0071 139731433751264**2 **2 139731433751072->139731433751264**2 139731433751072+->139731433751072 139731433849376 data -0.4686 grad 0.0000 139731433849568+ + 139731433849376->139731433849568+ 139731433849376* * 139731433849376*->139731433849376 139731433947776 data -0.0157 grad -0.0497 139731433951136+ + 139731433947776->139731433951136+ 139731433947776+ + 139731433947776+->139731433947776 139731433620144 data 0.0000 grad 0.1261 139731435175408* * 139731433620144->139731435175408* 139731433620144ReLU ReLU 139731433620144ReLU->139731433620144 139731433751264 data 2.2607 grad 1.0000 139731433751264->139731433751456+ 139731433751264**2->139731433751264 139731433849568 data -0.4686 grad 0.0000 139731433849952+ + 139731433849568->139731433849952+ 139731433849568+->139731433849568 139731433620240 data 0.6467 grad -0.0813 139731433620336+ + 139731433620240->139731433620336+ 139731433620240* * 139731433620240*->139731433620240 139731434373904 data 0.3354 grad 0.1980 139731434374336+ + 139731434373904->139731434374336+ 139731434373904+ + 139731434373904+->139731434373904 139731433947968 data 0.5612 grad -0.0497 139731433947968->139731433951136+ 139731433947968* * 139731433947968*->139731433947968 139731433620336 data 6.1458 grad -0.0813 139731433620336->139731433619712ReLU 139731433620336+->139731433620336 139731433751456 data 2.4934 grad 1.0000 139731433752080+ + 139731433751456->139731433752080+ 139731433751456+->139731433751456 139731433849760 data -0.4964 grad 0.0000 139731433849760->139731433849952+ 139731433849760* * 139731433849760*->139731433849760 139731433456592 data 3.0000 grad -0.0304 139731433457552* * 139731433456592->139731433457552* 139731434374096 data 1.0000 grad 0.1738 139731434374144* * 139731434374096->139731434374144* 139731433948112 data -1.0000 grad 0.0279 139731433948112->139731433947968* 139731434374144 data 0.8776 grad 0.1980 139731434374144->139731434374336+ 139731434374144*->139731434374144 139731433456688 data 2.3677 grad -0.0585 139731436042656+ + 139731433456688->139731436042656+ 139731433456688+ + 139731433456688+->139731433456688 139731433620528 data 0.0000 grad 0.0000 139731435174832+ + 139731433620528->139731435174832+ 139731433620528* * 139731433620528*->139731433620528 139731433948208 data 0.6709 grad -0.1334 139731433950080+ + 139731433948208->139731433950080+ 139731433948208+ + 139731433948208+->139731433948208 139731433751648 data 1.0000 grad 2.3984 139731433751696+ + 139731433751648->139731433751696+ 139731433849952 data -0.9650 grad 0.0000 139731433850336+ + 139731433849952->139731433850336+ 139731433849952+->139731433849952 139731433751696 data 1.1992 grad 2.3984 139731433751888**2 **2 139731433751696->139731433751888**2 139731433751696+->139731433751696 139731433456832 data -1.0000 grad -0.0502 139731433456880* * 139731433456832->139731433456880* 139731434374336 data 1.2130 grad 0.1980 139731434374960+ + 139731434374336->139731434374960+ 139731434374336+->139731434374336 139731433456880 data -0.8572 grad -0.0585 139731433456880->139731436042656+ 139731433456880*->139731433456880 139731433620720 data -2.3680 grad 0.0000 139731433620720->139731433620144ReLU 139731433620720+ + 139731433620720+->139731433620720 139731433948400 data 0.8776 grad -0.1334 139731433948400->139731433950080+ 139731433948400* * 139731433948400*->139731433948400 139731433850144 data -0.0212 grad 0.0000 139731433850144->139731433850336+ 139731433850144* * 139731433850144*->139731433850144 139731433620816 data 1.0880 grad -0.0813 139731433620816->139731433621296+ 139731433620816* * 139731433620816*->139731433620816 139731433751888 data 1.4381 grad 1.0000 139731433751888->139731433752080+ 139731433751888**2->139731433751888 139731434374528 data 1.0000 grad -0.1040 139731434374768* * 139731434374528->139731434374768* 139731433948544 data 1.0000 grad -0.1171 139731433948544->139731433948400* 139731433620912 data 0.0000 grad -0.0813 139731433621200+ + 139731433620912->139731433621200+ 139731433620912* * 139731433620912*->139731433620912 139731433948640 data -1.0000 grad 0.0701 139731433948688* * 139731433948640->139731433948688* 139731433850336 data -0.9862 grad 0.0000 139731433850720+ + 139731433850336->139731433850720+ 139731433850336+->139731433850336 139731433752080 data 3.9316 grad 1.0000 139731433752704+ + 139731433752080->139731433752704+ 139731433752080+->139731433752080 139731433948688 data 0.5252 grad -0.1334 139731433948688->139731433947248+ 139731433948688*->139731433948688 139731434374768 data -0.5252 grad 0.1980 139731434374768->139731434374960+ 139731434374768*->139731434374768 139731434374816 data 0.6879 grad 0.1980 139731433530704* * 139731434374816->139731433530704* 139731433532384* * 139731434374816->139731433532384* 139731433607856* * 139731434374816->139731433607856* 139731434374816->139731433609536* 139731434374816ReLU ReLU 139731434374816ReLU->139731434374816 139731433850528 data -0.0000 grad 0.0000 139731433850528->139731433850720+ 139731433850528* * 139731433850528*->139731433850528 139731433621200 data 0.0000 grad -0.0813 139731433621200->139731433619904+ 139731433621200+->139731433621200 139731433752272 data -1.0000 grad -1.6160 139731433752320+ + 139731433752272->139731433752320+ 139731433752320 data -0.8080 grad -1.6160 139731433752512**2 **2 139731433752320->139731433752512**2 139731433752320+->139731433752320 139731433457456 data 2.6328 grad -0.0797 139731433458080+ + 139731433457456->139731433458080+ 139731433457456* * 139731433457456*->139731433457456 139731433621296 data 5.4990 grad -0.0813 139731433621296->139731433620336+ 139731433621296+->139731433621296 139731434374960 data 0.6879 grad 0.1980 139731434374960->139731434374816ReLU 139731434374960+->139731434374960 139731433457504 data 1.3417 grad -0.0797 139731433457504->139731433458080+ 139731433457504+ + 139731433457504+->139731433457504 139731433949024 data 0.1992 grad 2.3984 139731433949024->139731433950656+ 139731433949024+ + 139731433949024+->139731433949024 139731433850720 data -0.9862 grad 0.0000 139731433850768ReLU ReLU 139731433850720->139731433850768ReLU 139731433850720+->139731433850720 139731433457552 data 1.5582 grad -0.0585 139731433457552->139731433456688+ 139731433457552*->139731433457552 139731433850768 data 0.0000 grad 0.2111 139731433777040* * 139731433850768->139731433777040* 139731433850768ReLU->139731433850768 139731434375104 data 0.5000 grad 0.0589 139731434375344* * 139731434375104->139731434375344* 139731433752512 data 0.6529 grad 1.0000 139731433752512->139731433752704+ 139731433752512**2->139731433752512 139731433949216 data 0.6486 grad -0.0497 139731433949216->139731433947776+ 139731433949216+ + 139731433949216+->139731433949216 139731433752704 data 4.5844 grad 1.0000 139731433752704+->139731433752704 139731434375344 data 0.2024 grad 0.1455 139731434375872+ + 139731434375344->139731434375872+ 139731434375344*->139731434375344 139731433851056 data 0.1991 grad -0.1361 139731433851248+ + 139731433851056->139731433851248+ 139731433851056* * 139731433851056*->139731433851056 139731434375392 data 0.5194 grad 0.1455 139731434376112+ + 139731434375392->139731434376112+ 139731434375392* * 139731434375392*->139731434375392 139731433949408 data -0.6643 grad -0.0497 139731433949408->139731433947776+ 139731433949408* * 139731433949408*->139731433949408 139731433457936 data 2.0000 grad -0.0237 139731433457984* * 139731433457936->139731433457984* 139731433457984 data 0.8095 grad -0.0585 139731433458032+ + 139731433457984->139731433458032+ 139731433457984*->139731433457984 139731435227456 data 0.0842 grad 3.6214 139731433950512* * 139731435227456->139731433950512* 139731435591616* * 139731435227456->139731435591616* 139731435227456->139731435174592* 139731433777424* * 139731435227456->139731433777424* 139731433458032 data 0.8095 grad -0.0585 139731433458032->139731433456688+ 139731433458032+->139731433458032 139731435227504 data 0.0000 grad 2.8246 139731435175264+ + 139731435227504->139731435175264+ 139731433611024+ + 139731435227504->139731433611024+ 139731433776848+ + 139731435227504->139731433776848+ 139733472768496+ + 139731435227504->139733472768496+ 139731434375536 data 1.0000 grad 0.0756 139731434375536->139731434375392* 139731433458080 data 3.9745 grad -0.0797 139731433458176+ + 139731433458080->139731433458176+ 139731433458080+->139731433458080 139731433949552 data 1.0000 grad 0.0330 139731433949552->139731433949408* 139731433851248 data 0.1991 grad -0.1361 139731433851632+ + 139731433851248->139731433851632+ 139731433851248+->139731433851248 139731435227648 data 0.1477 grad 0.0000 139731435227648->139731433620528* 139731433852736* * 139731435227648->139731433852736* 139731430486128* * 139731435227648->139731430486128* 139731433609152* * 139731435227648->139731433609152* 139731433458176 data 4.4996 grad -0.0797 139731433458992ReLU ReLU 139731433458176->139731433458992ReLU 139731433458176+->139731433458176 139731435227696 data -0.1307 grad 0.0000 139731435227696->139731435175408* 139731433611216* * 139731435227696->139731433611216* 139731435227696->139731433777040* 139733472769936* * 139731435227696->139733472769936* 139731433851440 data 2.0328 grad -0.1361 139731433851440->139731433851632+ 139731433851440* * 139731433851440*->139731433851440 139731435227792 data -0.9047 grad 0.0000 139731435172528* * 139731435227792->139731435172528* 139731430490016* * 139731435227792->139731430490016* 139731433609920* * 139731435227792->139731433609920* 139731433775744* * 139731435227792->139731433775744* 139731433949840 data 0.6709 grad -0.1334 139731433949840->139731433948208+ 139731433949840* * 139731433949840*->139731433949840 139731434375872 data 0.2024 grad 0.1455 139731434375872->139731434376112+ 139731434375872+->139731434375872 139731434375920 data 1.0000 grad 0.1247 139731434375968* * 139731434375920->139731434375968* 139731433851632 data 2.2319 grad -0.1361 139731433852016+ + 139731433851632->139731433852016+ 139731433851632+->139731433851632 139731434375968 data 0.8572 grad 0.1455 139731434376496+ + 139731434375968->139731434376496+ 139731434375968*->139731434375968 139731433949984 data 1.0000 grad -0.0895 139731433949984->139731433949840* 139731433950080 data 1.5484 grad -0.1334 139731433950080->139731433947248+ 139731433950080+->139731433950080 139731434376112 data 0.7218 grad 0.1455 139731434376112->139731434376496+ 139731434376112+->139731434376112 139731433851824 data 0.0482 grad -0.1361 139731433851824->139731433852016+ 139731433851824* * 139731433851824*->139731433851824 139731432246240 data -1.5556 grad 0.0000 139731432246240->139731433620720+ 139731432246240+ + 139731432246240+->139731432246240 139731433950320 data 2.0736 grad -0.1334 139731433950320->139731433849760* 139731433950320->139731433851440* 139731433774912* * 139731433950320->139731433774912* 139731433950320->139731433775360* 139731433950320ReLU->139731433950320 139731433852016 data 2.2801 grad -0.1361 139731433852400+ + 139731433852016->139731433852400+ 139731433852016+->139731433852016 139731435228368 data 0.0000 grad 0.0000 139731430488768+ + 139731435228368->139731430488768+ 139731435228368->139731435174832+ 139731433609344+ + 139731435228368->139731433609344+ 139731433775168+ + 139731435228368->139731433775168+ 139731433458992 data 4.4996 grad -0.0797 139731433458992->139731433619856* 139731433458992->139731435175648* 139731433936880* * 139731433458992->139731433936880* 139731433937792* * 139731433458992->139731433937792* 139731433458992ReLU->139731433458992 139731434376496 data 1.5790 grad 0.1455 139731434376544ReLU ReLU 139731434376496->139731434376544ReLU 139731434376496+->139731434376496 139731433950512 data 0.1992 grad 2.3984 139731433950512->139731433949024+ 139731433950512*->139731433950512 139731434376544 data 1.5790 grad 0.1455 139731433531088* * 139731434376544->139731433531088* 139731433532768* * 139731434376544->139731433532768* 139731433608240* * 139731434376544->139731433608240* 139731434376544->139731433609920* 139731434376544ReLU->139731434376544 139731433852208 data 0.0000 grad -0.1361 139731433852208->139731433852400+ 139731433852208* * 139731433852208*->139731433852208 139731433950608 data 0.0000 grad 2.3984 139731433950608->139731433949024+ 139731433950608+ + 139731433950608+->139731433950608 139731433950656 data 0.1992 grad 2.3984 139731433950656->139731433751696+ 139731433950656+->139731433950656 139731433459184 data 3.0000 grad -0.0699 139731433459184->139731433457456* 139731434376688 data -0.1898 grad 0.1091 139731433529552+ + 139731434376688->139731433529552+ 139731434376688+ + 139731434376688+->139731434376688 139731433852400 data 2.2801 grad -0.1361 139731433852448ReLU ReLU 139731433852400->139731433852448ReLU 139731433852400+->139731433852400 139731433852448 data 2.2801 grad -0.1361 139731433852448->139731433777424* 139731433852448ReLU->139731433852448 139731433459328 data 0.5252 grad -0.0797 139731433459328->139731433458176+ 139731433459328* * 139731433459328*->139731433459328 139731433950848 data 0.6486 grad -0.0497 139731433950848->139731433949216+ 139731433950848* * 139731433950848*->139731433950848 139731434376880 data -0.1898 grad 0.1091 139731434376880->139731434376688+ 139731434376880* * 139731434376880*->139731434376880 139731435228944 data -0.4707 grad 0.0000 139731435228944->139731433947536* 139731435592576* * 139731435228944->139731435592576* 139731435173440* * 139731435228944->139731435173440* 139731433777808* * 139731435228944->139731433777808* 139731433459472 data -1.0000 grad 0.0418 139731433459472->139731433459328* 139731433950992 data 1.0000 grad -0.0322 139731433950992->139731433950848* 139731434377024 data 0.5000 grad -0.0414 139731434377024->139731434376880* 139731433852736 data 0.0805 grad 0.0000 139731433852736->139731433775168+ 139731433852736*->139731433852736 139731432247152 data -0.8124 grad 0.0000 139731432247152->139731433620720+ 139731432247152* * 139731432247152*->139731432247152 139731434377120 data 1.0000 grad 0.0865 139731434377168* * 139731434377120->139731434377168* 139731433951136 data 0.5455 grad -0.0497 139731433951184ReLU ReLU 139731433951136->139731433951184ReLU 139731433951136+->139731433951136 139731434377168 data 0.7932 grad 0.1091 139731434377168->139731433529552+ 139731434377168*->139731434377168 139731433951184 data 0.5455 grad -0.0497 139731433951184->139731433849376* 139731433951184->139731433851056* 139731433951184->139731433852736* 139731433773616* * 139731433951184->139731433773616* 139731433951184ReLU->139731433951184 139731433328848 data 0.4881 grad 1.7977 139731433328848->139733472768304* 139731433328848ReLU ReLU 139731433328848ReLU->139731433328848 139731433328896 data 0.2113 grad 0.0000 139731433331008+ + 139731433328896->139731433331008+ 139731433328896* * 139731433328896*->139731433328896 139731433328992 data 0.4881 grad 1.7977 139731433331200+ + 139731433328992->139731433331200+ 139731433328992+ + 139731433328992+->139731433328992 139731433329424 data 0.8784 grad 1.7977 139731433330192+ + 139731433329424->139731433330192+ 139731433329424+ + 139731433329424+->139731433329424 139731433329712 data -0.0000 grad 1.7977 139731433329712->139731433331200+ 139731433329712* * 139731433329712*->139731433329712 139731433329808 data -1.0000 grad 0.0000 139731433330144* * 139731433329808->139731433330144* 139731433330000 data -0.1962 grad 1.7977 139731433330000->139731433330192+ 139731433330000* * 139731433330000*->139731433330000 139731435591088 data 0.5036 grad 3.0071 139731435591184+ + 139731435591088->139731435591184+ 139731435591088+ + 139731435591088+->139731435591088 139731433330144 data -0.7932 grad 0.0000 139731433332640+ + 139731433330144->139731433332640+ 139731433330144*->139731433330144 139731435591184 data 0.5036 grad 3.0071 139731435591184->139731433751072+ 139731435591184+->139731435591184 139731433330192 data 0.6822 grad 1.7977 139731433330192->139731433328992+ 139731433330192+->139731433330192 139731433330384 data -0.1941 grad 1.7977 139731433330384->139731433328992+ 139731433330384* * 139731433330384*->139731433330384 139731433330480 data -2.0010 grad 0.0000 139731430486608+ + 139731433330480->139731430486608+ 139731433330480+ + 139731433330480+->139731433330480 139731435591520 data 1.0000 grad 0.0000 139731435592768* * 139731435591520->139731435592768* 139731433330576 data -2.0010 grad 0.0000 139731433330576->139731433330480+ 139731433330576* * 139731433330576*->139731433330576 139731435591616 data 0.2118 grad 3.0071 139731435591616->139731435591088+ 139731435591616*->139731435591616 139731435591760 data 0.3243 grad 0.0000 139731435592432+ + 139731435591760->139731435592432+ 139731435591760* * 139731435591760*->139731435591760 139731433330816 data 3.0000 grad 0.0000 139731433331632* * 139731433330816->139731433331632* 139731433330864 data 0.8784 grad 1.7977 139731433330864->139731433329424+ 139731433330864* * 139731433330864*->139731433330864 139731435591952 data 0.3354 grad 0.1980 139731435591952->139731434373904+ 139731435591952* * 139731435591952*->139731435591952 139731433331008 data -1.7206 grad 0.0000 139731433331344ReLU ReLU 139731433331008->139731433331344ReLU 139731433331008+->139731433331008 139731435592048 data 0.0000 grad 0.0737 139731433530320* * 139731435592048->139731433530320* 139731433532000* * 139731435592048->139731433532000* 139731433607472* * 139731435592048->139731433607472* 139731435592048->139731433609152* 139731435592048ReLU ReLU 139731435592048ReLU->139731435592048 139731433331200 data 0.4881 grad 1.7977 139731433331200->139731433328848ReLU 139731433331200+->139731433331200 139731435592192 data 1.0000 grad 0.0000 139731435593584* * 139731435592192->139731435593584* 139731435592240 data 0.5000 grad 0.0000 139731435592240->139731435591760* 139731433331344 data 0.0000 grad -1.3469 139731433331344->139731433329712* 139731430487760* * 139731433331344->139731430487760* 139731430488192* * 139731433331344->139731430488192* 139731433331344->139733472768112* 139731433331344ReLU->139731433331344 139731435592384 data 0.2918 grad 3.0071 139731435592384->139731435591088+ 139731435592384+ + 139731435592384+->139731435592384 139731435592432 data 0.3243 grad 0.0000 139731435592816+ + 139731435592432->139731435592816+ 139731435592432+->139731435592432 139731433331536 data -0.2088 grad 0.0000 139731433331536->139731430486608+ 139731433331536* * 139731433331536*->139731433331536 139731435592576 data -0.0000 grad 3.0071 139731435592576->139731435591184+ 139731435592576*->139731435592576 139731433331632 data -1.1388 grad 0.0000 139731433332400+ + 139731433331632->139731433332400+ 139731433331632*->139731433331632 139731435592720 data -0.9012 grad 0.0000 139731435592720->139731435592048ReLU 139731435592720+ + 139731435592720+->139731435592720 139731435592768 data -0.5612 grad 0.0000 139731435592768->139731435592720+ 139731435592768*->139731435592768 139731435592816 data -0.3400 grad 0.0000 139731435592816->139731435592720+ 139731435592816+->139731435592816 139731433332160 data 0.5000 grad 0.0000 139731433332160->139731433328896* 139731433332400 data -1.1388 grad 0.0000 139731433332400->139731433332640+ 139731433332400+->139731433332400 139731435593584 data -0.6643 grad 0.0000 139731435593584->139731435592816+ 139731435593584*->139731435593584 139731435593632 data 0.5000 grad 0.1328 139731435593632->139731435591952* 139731433332640 data -1.9320 grad 0.0000 139731433332640->139731433331008+ 139731433332640+->139731433332640 139731433529552 data 0.6034 grad 0.1091 139731433529984+ + 139731433529552->139731433529984+ 139731433529552+->139731433529552 139731433529744 data 1.0000 grad 0.0461 139731433529792* * 139731433529744->139731433529792* 139731433529792 data 0.4227 grad 0.1091 139731433529792->139731433529984+ 139731433529792*->139731433529792 139731433529984 data 1.0261 grad 0.1091 139731433530032ReLU ReLU 139731433529984->139731433530032ReLU 139731433529984+->139731433529984 139731433530032 data 1.0261 grad 0.1091 139731433531472* * 139731433530032->139731433531472* 139731433533152* * 139731433530032->139731433533152* 139731433608624* * 139731433530032->139731433608624* 139731433530032->139731433610304* 139731433530032ReLU->139731433530032 139731433530320 data 0.0000 grad 0.0000 139731433530512+ + 139731433530320->139731433530512+ 139731433530320*->139731433530320 139731433530512 data 0.0000 grad 0.0000 139731433530896+ + 139731433530512->139731433530896+ 139731433530512+->139731433530512 139731433530704 data -0.1547 grad 0.0000 139731433530704->139731433530896+ 139731433530704*->139731433530704 139731433530896 data -0.1547 grad 0.0000 139731433531280+ + 139731433530896->139731433531280+ 139731433530896+->139731433530896 139731433531088 data -0.2728 grad 0.0000 139731433531088->139731433531280+ 139731433531088*->139731433531088 139731433531280 data -0.4275 grad 0.0000 139731433531664+ + 139731433531280->139731433531664+ 139731433531280+->139731433531280 139731433531472 data -0.8468 grad 0.0000 139731433531472->139731433531664+ 139731433531472*->139731433531472 139731433531664 data -1.2743 grad 0.0000 139731433531712ReLU ReLU 139731433531664->139731433531712ReLU 139731433531664+->139731433531664 139731433531712 data 0.0000 grad 1.4338 139731433531712->139731433610832* 139731433531712ReLU->139731433531712 139731433532000 data -0.0000 grad 0.0000 139731433532192+ + 139731433532000->139731433532192+ 139731433532000*->139731433532000 139731433532192 data 0.0000 grad 0.0000 139731433532576+ + 139731433532192->139731433532576+ 139731433532192+->139731433532192 139731433532384 data -0.1647 grad 0.0000 139731433532384->139731433532576+ 139731433532384*->139731433532384 139731433532576 data -0.1647 grad 0.0000 139731433532960+ + 139731433532576->139731433532960+ 139731433532576+->139731433532576 139731433532768 data -0.5001 grad 0.0000 139731433532768->139731433532960+ 139731433532768*->139731433532768 139731433532960 data -0.6648 grad 0.0000 139731433533344+ + 139731433532960->139731433533344+ 139731433532960+->139731433532960 139731433533152 data -0.6959 grad 0.0000 139731433533152->139731433533344+ 139731433533152*->139731433533152 139731433533344 data -1.3607 grad 0.0000 139731433533392ReLU ReLU 139731433533344->139731433533392ReLU 139731433533344+->139731433533344 139731433533392 data 0.0000 grad -0.3134 139731433533392->139731433611216* 139731433533392ReLU->139731433533392 139731430486128 data 0.3439 grad 0.0000 139731430486128->139731430488768+ 139731430486128*->139731430486128 139731433402528 data 1.1350 grad -0.1562 139731433402864+ + 139731433402528->139731433402864+ 139731433402528+ + 139731433402528+->139731433402528 139731433402576 data 1.1234 grad -0.1282 139731433403008ReLU ReLU 139731433402576->139731433403008ReLU 139731433402576+ + 139731433402576+->139731433402576 139731430486224 data 0.8503 grad 0.2532 139731430486272+ + 139731430486224->139731430486272+ 139731430486224+ + 139731430486224+->139731430486224 139731430486272 data 1.7055 grad 0.2532 139731430489968+ + 139731430486272->139731430489968+ 139731430486272+->139731430486272 139731430486368 data -2.5657 grad 0.0000 139731430489056+ + 139731430486368->139731430489056+ 139731430486368+ + 139731430486368+->139731430486368 139731433402768 data -1.9928 grad 0.0000 139731433405120+ + 139731433402768->139731433405120+ 139731433402768* * 139731433402768*->139731433402768 139731433402816 data 0.5000 grad 0.0820 139731433402912* * 139731433402816->139731433402912* 139731435172336 data 0.5175 grad -0.9649 139731435174496+ + 139731435172336->139731435174496+ 139731435172336+ + 139731435172336+->139731435172336 139731433402864 data 0.8724 grad -0.1562 139731433403584ReLU ReLU 139731433402864->139731433403584ReLU 139731433402864+->139731433402864 139731433402912 data -0.2626 grad -0.1562 139731433402912->139731433402864+ 139731433402912*->139731433402912 139731435172432 data 1.9458 grad 0.7703 139731431478176+ + 139731435172432->139731431478176+ 139731435172432+ + 139731435172432+->139731435172432 139731430486608 data -2.2099 grad 0.0000 139731430486608->139731430486368+ 139731430486608+->139731430486608 139731435172480 data 0.0000 grad -0.9649 139731435172480->139731435172336+ 139731435172480+ + 139731435172480+->139731435172480 139731433403008 data 1.1234 grad -0.1282 139731433403008->139731433330384* 139731430487040* * 139731433403008->139731430487040* 139731430488864* * 139731433403008->139731430488864* 139731433403008->139731430490016* 139731433403008ReLU->139731433403008 139731435172528 data -1.3665 grad 0.0000 139731435173872+ + 139731435172528->139731435173872+ 139731435172528*->139731435172528 139731433403056 data 3.0000 grad 0.0000 139731433403056->139731433402768* 139731430486848 data 2.5147 grad 0.2532 139731430487136ReLU ReLU 139731430486848->139731430487136ReLU 139731430486848+ + 139731430486848+->139731430486848 139731433403296 data -1.0000 grad -0.0666 139731433405360* * 139731433403296->139731433405360* 139731435172816 data 0.0000 grad -0.9649 139731435172816->139731435175264+ 139731435172816*->139731435172816 139731433403344 data 0.6948 grad -0.1282 139731433403344->139731433402576+ 139731433403344+ + 139731433403344+->139731433403344 139731430487040 data 0.8092 grad 0.2532 139731430487040->139731430489968+ 139731430487040*->139731430487040 139731433403440 data 1.2972 grad 0.0000 139731433404976+ + 139731433403440->139731433404976+ 139731433403440* * 139731433403440*->139731433403440 139731430487088 data 0.0000 grad -0.3929 139731430487088->139733472769936* 139731430487088ReLU ReLU 139731430487088ReLU->139731430487088 139731430487136 data 2.5147 grad 0.2532 139731430487136->139731435591616* 139731430487136ReLU->139731430487136 139731433403584 data 0.8724 grad -0.1562 139731433403584->139731433330000* 139731433403584->139731433331536* 139731430488096* * 139731433403584->139731430488096* 139731433403584->139731430489008* 139731433403584ReLU->139731433403584 139731435173104 data -1.0000 grad -0.5117 139731435173536* * 139731435173104->139731435173536* 139731433403680 data -0.8776 grad -0.1562 139731433403680->139731433402528+ 139731433403680* * 139731433403680*->139731433403680 139731433403872 data -1.0000 grad -0.1370 139731433403872->139731433403680* 139731435173440 data -0.0000 grad -0.9649 139731435173440->139731435174496+ 139731435173440*->139731435173440 139731433403968 data 2.0126 grad -0.1562 139731433403968->139731433402528+ 139731433403968+ + 139731433403968+->139731433403968 139731435173536 data 0.6643 grad 0.7703 139731435173536->139731431478176+ 139731435173536*->139731435173536 139731430487760 data 0.0000 grad 0.2532 139731430487760->139731430486848+ 139731430487760*->139731430487760 139731435173872 data -2.5910 grad 0.0000 139731435175168+ + 139731435173872->139731435175168+ 139731435173872+->139731435173872 139731430488096 data 0.8552 grad 0.2532 139731430488096->139731430486272+ 139731430488096*->139731430488096 139731430488192 data -0.0000 grad 0.0000 139731430488192->139731430489056+ 139731430488192*->139731430488192 139731433404640 data 3.0000 grad -0.0519 139731433405168* * 139731433404640->139731433405168* 139731433404736 data 0.5612 grad 0.0000 139731433405888+ + 139731433404736->139731433405888+ 139731433404736* * 139731433404736*->139731433404736 139731435174256 data 0.4333 grad 0.0000 139731435174256->139731435175168+ 139731435174256*->139731435174256 139731433404784 data 1.2142 grad -0.1282 139731433404784->139731433403344+ 139731433404784+ + 139731433404784+->139731433404784 139731430488480 data 0.8503 grad 0.2532 139731430488480->139731430486224+ 139731430488480* * 139731430488480*->139731430488480 139731433404976 data 1.2972 grad 0.0000 139731433404976->139731433405120+ 139731433404976+->139731433404976 139731435174496 data 0.5175 grad -0.9649 139731434893120+ + 139731435174496->139731434893120+ 139731435174496+->139731435174496 139731433405024 data -1.0000 grad 0.0000 139731433405024->139731433404736* 139731435174544 data 3.0000 grad 0.4996 139731435174928* * 139731435174544->139731435174928* 139731433405120 data -0.6956 grad 0.0000 139731433405120->139731433405888+ 139731433405120+->139731433405120 139731435174592 data 0.5175 grad -0.9649 139731435174592->139731435172336+ 139731435174592*->139731435174592 139731430488768 data 0.3439 grad 0.0000 139731430489920+ + 139731430488768->139731430489920+ 139731430488768+->139731430488768 139731433405168 data 1.2142 grad -0.1282 139731433405168->139731433404784+ 139731433405168*->139731433405168 139731430488864 data -0.3558 grad 0.0000 139731430488864->139731430486368+ 139731430488864*->139731430488864 139731435174832 data 0.0000 grad 0.0000 139731435174976+ + 139731435174832->139731435174976+ 139731435174832+->139731435174832 139731433405360 data -0.5194 grad -0.1282 139731433405360->139731433403344+ 139731433405360*->139731433405360 139731430489008 data -0.2374 grad 0.0000 139731430489008->139731430489920+ 139731430489008*->139731430489008 139731430489056 data -2.5657 grad 0.0000 139731430489056->139731430487088ReLU 139731430489056+->139731430489056 139731435174928 data 1.9458 grad 0.7703 139731435174928->139731435172432+ 139731435174928*->139731435174928 139731435174976 data -1.2245 grad 0.0000 139731435174976->139731435173872+ 139731435174976+->139731435174976 139731433405648 data 0.4286 grad -0.1282 139731433405648->139731433402576+ 139731433405648* * 139731433405648*->139731433405648 139731435175168 data -2.1577 grad 0.0000 139731435175744ReLU ReLU 139731435175168->139731435175744ReLU 139731435175168+->139731435175168 139731435175264 data 0.0000 grad -0.9649 139731435175264->139731435172480+ 139731435175264+->139731435175264 139731433405840 data 0.5000 grad -0.1099 139731433405840->139731433405648* 139731433405888 data -0.1344 grad 0.0000 139731433406176ReLU ReLU 139731433405888->139731433406176ReLU 139731433405888+->139731433405888 139731435175408 data -0.0000 grad -0.9649 139731435175408->139731435172480+ 139731435175408*->139731435175408 139731433406032 data 2.0000 grad -0.0534 139731433185920* * 139731433406032->139731433185920* 139731433406176 data 0.0000 grad -0.0297 139731433406176->139731433620528* 139731433406176->139731433620912* 139731433936736* * 139731433406176->139731433936736* 139731433937888* * 139731433406176->139731433937888* 139731433406176ReLU->139731433406176 139731435175648 data -1.2245 grad 0.0000 139731435175648->139731435174976+ 139731435175648*->139731435175648 139731435175744 data 0.0000 grad 0.4542 139731435175744->139731435173440* 139731435175744ReLU->139731435175744 139731430489920 data 0.1065 grad 0.0000 139733472768160+ + 139731430489920->139733472768160+ 139731430489920+->139731430489920 139731430489968 data 2.5147 grad 0.2532 139731430489968->139731430486848+ 139731430489968+->139731430489968 139731430490016 data -1.0164 grad 0.0000 139731430490016->139733472768160+ 139731430490016*->139731430490016 139731431637056 data -0.2394 grad 0.0000 139731431637056->139731433849760* 139731431637056->139731433331536* 139731431637056->139731433532384* 139731431637056->139731433936880* 139731431477312 data 2.0126 grad -0.1562 139731431477312->139731433403968+ 139731431477312* * 139731431477312*->139731431477312 139731431477360 data -0.2806 grad 0.7703 139731431478272+ + 139731431477360->139731431478272+ 139731431477360* * 139731431477360*->139731431477360 139731433771120 data 0.4047 grad -0.0980 139731433771216+ + 139731433771120->139731433771216+ 139731433771120*->139731433771120 139731433935056 data 1.6205 grad -0.0439 139731433937216+ + 139731433935056->139731433937216+ 139731433935056+ + 139731433935056+->139731433935056 139731431477456 data 2.3294 grad 0.7703 139731431477456->139731433330576* 139731431477456->139731433330864* 139731431477456->139731430486128* 139731431477456->139731430488480* 139731431477456ReLU ReLU 139731431477456ReLU->139731431477456 139731433771216 data 0.4047 grad -0.0980 139731433771456+ + 139731433771216->139731433771456+ 139731433771216+->139731433771216 139731433607472 data 0.0000 grad 0.2020 139731433607664+ + 139731433607472->139731433607664+ 139731433607472*->139731433607472 139731433935248 data -0.9886 grad 0.0000 139731433937744+ + 139731433935248->139731433937744+ 139731433935248* * 139731433935248*->139731433935248 139731431477648 data 3.0000 grad -0.1048 139731431477648->139731431477312* 139731433771456 data 0.9241 grad -0.0980 139731433772800+ + 139731433771456->139731433772800+ 139731433771456+->139731433771456 139731433607664 data 0.0000 grad 0.2020 139731433608048+ + 139731433607664->139731433608048+ 139731433607664+->139731433607664 139731433935488 data -0.7592 grad -0.0439 139731433935488->139731433935056+ 139731433935488+ + 139731433935488+->139731433935488 139731433771648 data -1.0000 grad -0.0840 139731433772992* * 139731433771648->139731433772992* 139731433607856 data 0.6743 grad 0.2020 139731433607856->139731433608048+ 139731433607856*->139731433607856 139731433608048 data 0.6743 grad 0.2020 139731433608432+ + 139731433608048->139731433608432+ 139731433608048+->139731433608048 139731433771888 data -0.3796 grad 0.0000 139731433772080+ + 139731433771888->139731433772080+ 139731433771888* * 139731433771888*->139731433771888 139731431478176 data 2.6101 grad 0.7703 139731431478176->139731431478272+ 139731431478176+->139731431478176 139731431478224 data 0.5000 grad -0.4323 139731431478224->139731431477360* 139731431478272 data 2.3294 grad 0.7703 139731431478272->139731431477456ReLU 139731431478272+->139731431478272 139731433608240 data 1.1374 grad 0.2020 139731433608240->139731433608432+ 139731433608240*->139731433608240 139731433772080 data -0.3796 grad 0.0000 139731433773040+ + 139731433772080->139731433773040+ 139731433772080+->139731433772080 139731433608432 data 1.8117 grad 0.2020 139731433608816+ + 139731433608432->139731433608816+ 139731433608432+->139731433608432 139731433936208 data -0.4227 grad -0.0439 139731433936208->139731433937216+ 139731433936208* * 139731433936208*->139731433936208 139731433608624 data 0.5540 grad 0.2020 139731433608624->139731433608816+ 139731433608624*->139731433608624 139731433772512 data 1.0000 grad -0.0509 139731433772560* * 139731433772512->139731433772560* 139731433936400 data -1.0122 grad 0.0000 139731433938320+ + 139731433936400->139731433938320+ 139731433936400+ + 139731433936400+->139731433936400 139731433772560 data 0.5194 grad -0.0980 139731433772560->139731433771456+ 139731433772560*->139731433772560 139731433608816 data 2.3658 grad 0.2020 139731433608864ReLU ReLU 139731433608816->139731433608864ReLU 139731433608816+->139731433608816 139731433772656 data 0.0669 grad -0.0980 139731433772656->139731433850144* 139731433772656->139731433851824* 139731433773952* * 139731433772656->139731433773952* 139731433772656->139731433775744* 139731433772656ReLU ReLU 139731433772656ReLU->139731433772656 139731433608864 data 2.3658 grad 0.2020 139731433608864->139731433950512* 139731433608864ReLU->139731433608864 139731433772800 data 0.0669 grad -0.0980 139731433772800->139731433772656ReLU 139731433772800+->139731433772800 139731433936688 data -0.7592 grad -0.0439 139731433936688->139731433935488+ 139731433936688* * 139731433936688*->139731433936688 139731433936736 data -0.0000 grad 0.0000 139731433937024+ + 139731433936736->139731433937024+ 139731433936736*->139731433936736 139731433609152 data 0.0000 grad 0.0000 139731433609152->139731433609344+ 139731433609152*->139731433609152 139731433772992 data -0.8572 grad -0.0980 139731433772992->139731433772800+ 139731433772992*->139731433772992 139731433936880 data -1.0772 grad 0.0000 139731433938128+ + 139731433936880->139731433938128+ 139731433936880*->139731433936880 139731433773040 data 0.4136 grad 0.0000 139731433774384+ + 139731433773040->139731433774384+ 139731433773040+->139731433773040 139731433936976 data 0.0000 grad -0.5769 139731433936976->139731435172816* 139731433936976ReLU ReLU 139731433936976ReLU->139731433936976 139731433937024 data 0.0000 grad 0.0000 139731433937024->139731433938128+ 139731433937024+->139731433937024 139731433609344 data 0.0000 grad 0.0000 139731433609728+ + 139731433609344->139731433609728+ 139731433609344+->139731433609344 139731433773232 data 0.7932 grad 0.0000 139731433773232->139731433773040+ 139731433773232* * 139731433773232*->139731433773232 139731433937120 data 3.0000 grad -0.0348 139731433937600* * 139731433937120->139731433937600* 139731433609536 data -0.1872 grad 0.0000 139731433609536->139731433609728+ 139731433609536*->139731433609536 139731433937216 data 1.1978 grad -0.0439 139731433937264ReLU ReLU 139731433937216->139731433937264ReLU 139731433937216+->139731433937216 139731433773376 data 1.0000 grad 0.0000 139731433773376->139731433773232* 139731433937264 data 1.1978 grad -0.0439 139731433937264->139731433620240* 139731433937264->139731432247152* 139731433937264->139731435174256* 139731433937264->139731433935248* 139731433937264ReLU->139731433937264 139731433773424 data 0.2057 grad 0.0000 139731433774720+ + 139731433773424->139731433774720+ 139731433773424+ + 139731433773424+->139731433773424 139731433937312 data 2.0000 grad 0.0167 139731433937312->139731433936688* 139731433937408 data -1.0000 grad -0.0185 139731433937408->139731433936208* 139731433609728 data -0.1872 grad 0.0000 139731433610112+ + 139731433609728->139731433610112+ 139731433609728+->139731433609728 139731433773616 data 0.2057 grad 0.0000 139731433773616->139731433773424+ 139731433773616*->139731433773616 139731433937552 data 0.0000 grad 0.0000 139731433937552->139731433936400+ 139731433937552+ + 139731433937552+->139731433937552 139731433937600 data 2.3796 grad -0.0439 139731433937600->139731433935056+ 139731433937600*->139731433937600 139731433609920 data -1.4286 grad 0.0000 139731433609920->139731433610112+ 139731433609920*->139731433609920 139731433937744 data -2.2617 grad 0.0000 139731433937744->139731433936976ReLU 139731433937744+->139731433937744 139731433937792 data -1.0122 grad 0.0000 139731433937792->139731433936400+ 139731433937792*->139731433937792 139731433610112 data -1.6158 grad 0.0000 139731433610496+ + 139731433610112->139731433610496+ 139731433610112+->139731433610112 139731433773952 data -0.0116 grad 0.0000 139731433774000+ + 139731433773952->139731433774000+ 139731433773952*->139731433773952 139731433774000 data -0.2723 grad 0.0000 139731433774000->139731433849040+ 139731433774000+->139731433774000 139731433937888 data 0.0000 grad 0.0000 139731433937888->139731433937552+ 139731433937888*->139731433937888 139731433774096 data -0.0000 grad 0.0000 139731433774096->139731433849040+ 139731433774096* * 139731433774096*->139731433774096 139731433610304 data 0.3712 grad 0.0000 139731433610304->139731433610496+ 139731433610304*->139731433610304 139731433774240 data 1.0000 grad 0.0000 139731433774240->139731433771888* 139731433938128 data -1.0772 grad 0.0000 139731433938128->139731432246240+ 139731433938128+->139731433938128 139731433610496 data -1.2446 grad 0.0000 139731433610544ReLU ReLU 139731433610496->139731433610544ReLU 139731433610496+->139731433610496 139731433610544 data 0.0000 grad -1.1290 139731433610544->139731433947536* 139731433610544ReLU->139731433610544 139731433774384 data -0.0090 grad 0.0000 139731433774432ReLU ReLU 139731433774384->139731433774432ReLU 139731433774384+->139731433774384 139731433774432 data 0.0000 grad -0.0735 139731433774432->139731433850528* 139731433774432->139731433852208* 139731433774432->139731433774096* 139731433774432->139731433776128* 139731433774432ReLU->139731433774432 139731433938320 data -1.2731 grad 0.0000 139731433938320->139731433937744+ 139731433938320+->139731433938320 139731433774528 data -1.0000 grad 0.0000 139731433774576* * 139731433774528->139731433774576* 139731433774576 data -0.4227 grad 0.0000 139731433774576->139731433774384+ 139731433774576*->139731433774576 139731433610832 data 0.0000 grad 2.3984 139731433610832->139731433611024+ 139731433610832*->139731433610832 139731433774720 data -0.2607 grad 0.0000 139731433774720->139731433774000+ 139731433774720+->139731433774720 139731433479904 data -0.6782 grad 0.0000 139731433479904->139731433850528* 139731433479904->139731432247152* 139731433479904->139731433533152* 139731433479904->139731430488192* 139731433479952 data -0.3167 grad 0.0000 139731433479952->139731433850144* 139731433479952->139731433532768* 139731433479952->139731430488864* 139731431024288* * 139731433479952->139731431024288* 139731433611024 data 0.0000 grad 2.3984 139731433611024->139731433950608+ 139731433611024+->139731433611024 139731433774912 data -0.4665 grad 0.0000 139731433774912->139731433774720+ 139731433774912*->139731433774912 139731433938848 data -0.2609 grad 0.0000 139731433938848->139731433938320+ 139731433938848* * 139731433938848*->139731433938848 139731433611216 data -0.0000 grad 2.3984 139731433611216->139731433950608+ 139731433611216*->139731433611216 139731433775168 data 0.0805 grad 0.0000 139731433775552+ + 139731433775168->139731433775552+ 139731433775168+->139731433775168 139731433185488 data -0.8590 grad 0.0000 139731433185488->139731433849376* 139731433185488->139731433330576* 139731433185488->139731433532000* 139731433185488->139731433936736* 139731433185536 data 0.0000 grad 0.0652 139731433185536->139731434376688+ 139731433185536->139731433332400+ 139731433185536->139731433935488+ 139731433185536->139731433772080+ 139731433775360 data -0.5643 grad 0.0000 139731433775360->139731433775552+ 139731433775360*->139731433775360 139731433185584 data -0.8253 grad 0.0000 139731433185584->139731433329712* 139731433185584->139731433531472* 139731433185584->139731433935248* 139731433185584->139731433774096* 139731445113136 data 0.5399 grad 0.1099 139731445113136->139731433620240* 139731445113136->139731433852208* 139731445113136->139731430487760* 139731445113136->139731433608624* 139731433185728 data 0.0000 grad 1.7977 139731433185728->139731433329424+ 139731433185728->139731433530512+ 139731433185728->139731433773424+ 139731433185728->139731433937552+ 139731433775552 data -0.4837 grad 0.0000 139731433775936+ + 139731433775552->139731433775936+ 139731433775552+->139731433775552 139731433185776 data -0.5252 grad 0.3330 139731433185776->139731433948688* 139731433185776->139731434374768* 139731433185776->139731433459328* 139731433185776->139731433402912* 139731433185824 data -0.5612 grad 0.4348 139731433185824->139731433947968* 139731433185824->139731435592768* 139731433185824->139731433404736* 139731433185824->139731431477360* 139731433185920 data 1.3417 grad -0.0797 139731433185920->139731433457504+ 139731433185920*->139731433185920 139731433775744 data -0.0605 grad 0.0000 139731433775744->139731433775936+ 139731433775744*->139731433775744 139731433185968 data 0.0000 grad 0.7207 139731433185968->139731433949216+ 139731433185968->139731435592432+ 139731433185968->139731435172432+ 139731433185968->139731433404976+ 139731433186112 data 2.0000 grad 0.0000 139731433186112->139731433403440* 139731433775936 data -0.5443 grad 0.0000 139731433776320+ + 139731433775936->139731433776320+ 139731433775936+->139731433775936 139731433186160 data 0.3771 grad 4.1877 139731433186160->139731433330864* 139731433186160->139731433530320* 139731433186160->139731433773616* 139731433186160->139731433937888* 139731433776128 data 0.0000 grad 0.0000 139731433776128->139731433776320+ 139731433776128*->139731433776128 139731433776320 data -0.5443 grad 0.0000 139731433776368ReLU ReLU 139731433776320->139731433776368ReLU 139731433776320+->139731433776320 139731433776368 data 0.0000 grad 0.7607 139731433776368->139731433777808* 139731433776368ReLU->139731433776368 139731433186688 data 0.4227 grad 0.1529 139731433186688->139731433328896* 139731433186688->139731433529792* 139731433186688->139731433936208* 139731433186688->139731433774576* 139731433186832 data 0.8572 grad 0.2380 139731433186832->139731433456880* 139731433186832->139731434375968* 139731433186832->139731433405648* 139731433186832->139731433772992* 139731433776656 data 0.0000 grad -1.6160 139731433776656->139731433776848+ 139731433776656*->139731433776656 139731431024288 data -0.4784 grad 0.0000 139731431024288->139731432246240+ 139731431024288*->139731431024288 139731433776848 data 0.0000 grad -1.6160 139731433777232+ + 139731433776848->139731433777232+ 139731433776848+->139731433776848 139731433187072 data 0.6486 grad 2.2613 139731433187072->139731433950848* 139731433187072->139731435591760* 139731433187072->139731433403440* 139731433187072->139731435174928* 139731445114624 data 0.0000 grad 0.2379 139731445114624->139731433621200+ 139731445114624->139731433851248+ 139731445114624->139731430486224+ 139731445114624->139731433607664+ 139731433777040 data -0.0000 grad -1.6160 139731433777040->139731433777232+ 139731433777040*->139731433777040 139731445114816 data 0.7203 grad 0.4716 139731445114816->139731433620816* 139731445114816->139731433851824* 139731445114816->139731430487040* 139731445114816->139731433608240* 139731433187408 data 0.0000 grad -0.1712 139731433187408->139731434373904+ 139731433187408->139731433948208+ 139731433187408->139731433457504+ 139731433187408->139731433403968+ 139731433777232 data 0.0000 grad -1.6160 139731433777616+ + 139731433777232->139731433777616+ 139731433777232+->139731433777232 139731433187600 data -0.6643 grad -0.8200 139731433187600->139731433949408* 139731433187600->139731435593584* 139731433187600->139731433402768* 139731433187600->139731435173536* 139731433777424 data 0.1920 grad -1.6160 139731433777424->139731433777616+ 139731433777424*->139731433777424 139731433187744 data 0.0000 grad -0.1392 139731433187744->139731433458032+ 139731433187744->139731434375872+ 139731433187744->139731433404784+ 139731433187744->139731433771216+ 139731433187792 data -0.3796 grad -0.0332 139731433187792->139731434376880* 139731433187792->139731433331632* 139731433187792->139731433771888* 139731433187792->139731433936688* 139731433777616 data 0.1920 grad -1.6160 139731433778000+ + 139731433777616->139731433778000+ 139731433777616+->139731433777616 139731433777808 data -0.0000 grad -1.6160 139731433777808->139731433778000+ 139731433777808*->139731433777808 139731433778000 data 0.1920 grad -1.6160 139731433778000->139731433752320+ 139731433778000+->139731433778000 139731435252848 data 0.3650 grad 0.5156 139731435252848->139731433620912* 139731435252848->139731433851056* 139731435252848->139731430488480* 139731435252848->139731433607472* 139731433188512 data -0.2250 grad 1.5683 139731433188512->139731433330000* 139731433188512->139731433530704* 139731433188512->139731433937792* 139731433188512->139731433774912* 139731433188752 data 0.7932 grad -0.0226 139731433188752->139731434377168* 139731433188752->139731433330144* 139731433188752->139731433773232* 139731433188752->139731433937600* 139731433778720 data -1.0000 grad -0.9649 139731433778720->139731434893120+ 139731433188896 data 0.6709 grad -0.6622 139731433188896->139731433949840* 139731433188896->139731435591952* 139731433188896->139731431477312* 139731433188896->139731433185920* 139731433188944 data 0.4047 grad -0.5268 139731433188944->139731434375344* 139731433188944->139731433457984* 139731433188944->139731433405168* 139731433188944->139731433771120* 139731445116496 data 0.9803 grad -0.2880 139731445116496->139731433619856* 139731445116496->139731433851440* 139731445116496->139731430488096* 139731445116496->139731433607856* 139731433189040 data 0.8776 grad -0.0182 139731433189040->139731434374144* 139731433189040->139731433948400* 139731433189040->139731433457456* 139731433189040->139731433403680* 139731434893120 data -0.4825 grad -0.9649 139731434893120->139731433750592**2 139731434893120+->139731434893120 139731433189184 data 0.5194 grad 0.0000 139731433189184->139731433457552* 139731433189184->139731434375392* 139731433189184->139731433405360* 139731433189184->139731433772560* 139731433189232 data -0.1728 grad 2.0196 139731433189232->139731433330384* 139731433189232->139731433531088* 139731433189232->139731433773952* 139731433189232->139731433938848* 139733472768112 data 0.0000 grad 0.0000 139733472768784+ + 139733472768112->139733472768784+ 139733472768112*->139733472768112 139733472768160 data -0.9099 grad 0.0000 139733472768160->139733472768784+ 139733472768160+->139733472768160 139733472768304 data 0.2918 grad 3.0071 139733472768304->139733472768496+ 139733472768304*->139733472768304 139733472768496 data 0.2918 grad 3.0071 139733472768496->139731435592384+ 139733472768496+->139733472768496 139733472768784 data -0.9099 grad 0.0000 139733472769840ReLU ReLU 139733472768784->139733472769840ReLU 139733472768784+->139733472768784 139733472769840 data 0.0000 grad -1.4155 139733472769840->139731435592576* 139733472769840ReLU->139733472769840 139733472769936 data -0.0000 grad 3.0071 139733472769936->139731435592384+ 139733472769936*->139733472769936 139731436042512 data 1.5104 grad -0.0585 139731436042512->139731433620816* 139731436042512->139731435172528* 139731436042512->139731433938848* 139731436042512->139731431024288* 139731436042512ReLU ReLU 139731436042512ReLU->139731436042512 139731436042656 data 1.5104 grad -0.0585 139731436042656->139731436042512ReLU 139731436042656+->139731436042656 139731435223792 data 0.0000 grad 0.0000 139731435223792->139731433849568+ 139731435223792->139731433330480+ 139731435223792->139731433532192+ 139731435223792->139731433937024+

The gradients on the input data are not that useful to us and that's because the input data seems to be not changeable.

In the gradient descent scheme we are thinking of the gradient as a vector pointing in the direction of increased loss and so in gradient descent we are modifying p data by a small step size in the direction of the gradient so the step size as an example could be like a very small number like 0.01.

In [234]:
num_cycles = 20

for k in range(num_cycles):
    # forward pass
    ypred = [n(x) for x in xs]
    loss = sum((yout - ygt) ** 2 for ygt, yout in zip(ys, ypred))
    # backward pass
    for p in n.parameters():
        # one of the most common bug while developing neural nets
        # we need to make sure that we reset these gradients to zero so that when we do backward all of them start at zero and the actual backward pass accumulates them
        p.grad = 0.0

the loss derivatives into the grads
    loss.backward()
    # update
    for p in n.parameters():
        p.data += -0.01 * p.grad
    print(k, loss.data)
0 0.11832011527709294
1 0.11417681052240584
2 0.11027143730563282
3 0.106269781481659
4 0.10244766346102194
5 0.09865353670187882
6 0.09492791181761162
7 0.09134004461101422
8 0.08772623971249013
9 0.08433593022783775
10 0.08088983621120385
11 0.07761585022930426
12 0.07438070404238775
13 0.07123154090030628
14 0.06820558197668769
15 0.06518795943070937
16 0.06236848949480526
17 0.05951865866702462
18 0.05683920451412121
19 0.054193312325887685
In [235]:
ypred
Out[235]:
[Value(data=1.1280609047338137),
 Value(data=-0.9414863019548612),
 Value(data=-0.9727950652871139),
 Value(data=0.8166158249112135)]
In [ ]: