karpathy / karpathy/micrograd

Homework Assignment Error with softmax activation function

Open
#22 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Jupyter Notebook
Stars
17.6k
Forks
2.8k
PR merge metrics
No merged PRs in 30d

Description

Hi @karpathy
I was solving the [assignment](https://colab.research.google.com/drive/1FPTx1RXtBfc4MaTkf7viZZD4U2F9gtKN?usp=sharing) as mentioned in the YouTube video. In the Softmax function, I was getting the following error `TypeError: unsupported operand type(s) for +: 'int' and 'Value'`

This is the line where I am getting the error
```
def softmax(logits):
counts = [logit.exp() for logit in logits]
denominator = sum(counts) #Here I am getting the Typeerror
out = [c / denominator for c in counts]
return out
```

And, my __add__ function in Value Class is the following
```
def __add__(self, other): # exactly as in the video
other = other if isinstance(other, Value) else Value(other)
out = Value(self.data + other.data, (self, other), '+')

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

return out
```

So my query is on the sum of list function. It is probably similar to counts[i].__add__(counts[i+1]) and then we keep on adding to the result till the end of the list. So this add function should work well. But I am not sure why it is not working, am I missing something?
Thanks in advance

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.