source code in micrograd/micrograd /nn.py: class Neuron(Module)/call(self, x) is:
class Neuron(Module):
def __init__(self, nin, nonlin=True):
self.w = [Value(random.uniform(-1,1)) for _ in range(nin)]
self.b = Value(0)
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
when you ran it, it occurred:
Cell In[14], line 21, in Neuron.call(self, x)
19 def call(self, x):
20 act = sum(wi*xi for wi,xi in zip(self.w, x)), self.b
---> 21 return act.relu() if self.nonlin else act
AttributeError: 'tuple' object has no attribute 'relu'
so it should be changed as :
class Neuron(Module):
def __init__(self, nin, nonlin=True):
self.w = [Value(random.uniform(-1,1)) for _ in range(nin)]
self.b = Value(0)
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