patrickloeber / pytorch-chatbot

Simple chatbot implementation with PyTorch.
MIT License
420 stars 334 forks source link

TypeError: linear(): argument 'input' (position 1) must be Tensor, not ReLU #29

Open GreenyPM opened 8 months ago

GreenyPM commented 8 months ago

I've made it to 12:54 in the 3rd part of his series, and I have come to a roadblock in the code. I cannot find a way to work around it. Any advice or potential fixes help. Thanks!

Output [nltk_data] Downloading package punkt to [nltk_data] C:\Users\AlienUser\AppData\Roaming\nltk_data... [nltk_data] Package punkt is already up-to-date! Traceback (most recent call last): File "c:\Users\AlienUser\Documents\PyTorchBot\train.py", line 85, in outputs = model(words) File "C:\Users\AlienUser\Documents\PyTorchBot\venv\lib\site-packages\torch\nn\modules\module.py", line 1511, in _wrapped_call_impl return self._call_impl(*args, kwargs) File "C:\Users\AlienUser\Documents\PyTorchBot\venv\lib\site-packages\torch\nn\modules\module.py", line 1520, in _call_impl return forward_call(*args, *kwargs) File "c:\Users\AlienUser\Documents\PyTorchBot\model.py", line 15, in forward out = self.l2(out) File "C:\Users\AlienUser\Documents\PyTorchBot\venv\lib\site-packages\torch\nn\modules\module.py", line 1511, in _wrapped_call_impl return self._call_impl(args, kwargs) File "C:\Users\AlienUser\Documents\PyTorchBot\venv\lib\site-packages\torch\nn\modules\module.py", line 1520, in _call_impl return forward_call(*args, **kwargs) File "C:\Users\AlienUser\Documents\PyTorchBot\venv\lib\site-packages\torch\nn\modules\linear.py", line 116, in forward return F.linear(input, self.weight, self.bias) TypeError: linear(): argument 'input' (position 1) must be Tensor, not ReLU

Link to Video: https://www.youtube.com/watch?v=Da-iHgrmHYg

SrijanSriv211 commented 8 months ago

Can you share your model.py code? Maybe there is some problem in it.

Pranay281202 commented 8 months ago

import torch import torch.nn as nn

class YourModel(nn.Module): def init(self, input_size, hidden_size, output_size): super(YourModel, self).init() self.l1 = nn.Linear(input_size, hidden_size) self.relu = nn.ReLU() # ReLU activation function self.l2 = nn.Linear(hidden_size, output_size)

def forward(self, x):
    out = self.l1(x)
    out = self.relu(out)  # Apply ReLU activation
    out = self.l2(out)
    return out

Create an instance of your model

model = YourModel(input_size, hidden_size, output_size)

Assuming 'words' is your input tensor

outputs = model(words)