ajhalthor / Transformer-Neural-Network

Code Transformer neural network components piece by piece
MIT License
295 stars 157 forks source link

IndexError: index out of range in self #12

Open AlessandroB1298 opened 4 months ago

AlessandroB1298 commented 4 months ago

Hello I am using a this repo to convert English to Italian and I keep running into this error I kept all the code the same except for the vocab dictionaries which are shown below

english_vocabulary = [START_TOKEN, ' ', '!', '"', '#', '$', '%', '&', "'", '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', '<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '[', '\\\\', ']', '^', '_', '', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~', '_', PADDING_TOKEN, END_TOKEN] `

italian_vocabulary = [START_TOKEN, ' ', '!', '"', '#', '$', '%', '&', "'", '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', ':', '<', '=', '>', '?', '@', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'Z', 'À', 'È', 'É', 'Ì', 'Í', 'Ò', 'Ó', 'Ù', '[', '\\\\', ']', '^', '_', '', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'z', 'à', 'è', 'é', 'ì', 'í', 'ò', 'ó', 'ù', '{', '|', '}', '~', '_', PADDING_TOKEN, END_TOKEN] `

Besides that, all the code is the same just updated from kn->it and the naming for Kannada -> italian

Epoch 0 Traceback (most recent call last): File "/Users/alessandrobongiorno/Desktop/singularity/research/transformers/gpt-3/train/train.py", line 213, in <module> it_predictions = transformer( File "/Users/alessandrobongiorno/.pyenv/versions/3.9.19/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1532, in _wrapped_call_impl return self._call_impl(*args, **kwargs) File "/Users/alessandrobongiorno/.pyenv/versions/3.9.19/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1541, in _call_impl return forward_call(*args, **kwargs) File "/Users/alessandrobongiorno/Desktop/singularity/research/transformers/gpt-3/train/../model/model.py", line 301, in forward x = self.encoder(x, encoder_self_attention_mask, start_token=enc_start_token, end_token=enc_end_token) File "/Users/alessandrobongiorno/.pyenv/versions/3.9.19/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1532, in _wrapped_call_impl return self._call_impl(*args, **kwargs) File "/Users/alessandrobongiorno/.pyenv/versions/3.9.19/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1541, in _call_impl return forward_call(*args, **kwargs) File "/Users/alessandrobongiorno/Desktop/singularity/research/transformers/gpt-3/train/../model/model.py", line 178, in forward x = self.sentence_embedding(x, start_token, end_token) File "/Users/alessandrobongiorno/.pyenv/versions/3.9.19/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1532, in _wrapped_call_impl return self._call_impl(*args, **kwargs) File "/Users/alessandrobongiorno/.pyenv/versions/3.9.19/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1541, in _call_impl return forward_call(*args, **kwargs) File "/Users/alessandrobongiorno/Desktop/singularity/research/transformers/gpt-3/train/../model/model.py", line 71, in forward x = self.embedding(x) File "/Users/alessandrobongiorno/.pyenv/versions/3.9.19/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1532, in _wrapped_call_impl return self._call_impl(*args, **kwargs) File "/Users/alessandrobongiorno/.pyenv/versions/3.9.19/lib/python3.9/site-packages/torch/nn/modules/module.py", line 1541, in _call_impl return forward_call(*args, **kwargs) File "/Users/alessandrobongiorno/.pyenv/versions/3.9.19/lib/python3.9/site-packages/torch/nn/modules/sparse.py", line 163, in forward return F.embedding( File "/Users/alessandrobongiorno/.pyenv/versions/3.9.19/lib/python3.9/site-packages/torch/nn/functional.py", line 2264, in embedding return torch.embedding(weight, input, padding_idx, scale_grad_by_freq, sparse) IndexError: index out of range in self (env) alessandrobongiorno@Alessandros-Air train % I believe the error is coming from this line

self.embedding = nn.Embedding(self.vocab_size, d_model)

If anyone has any ideas I would really appreciate it

Ji2-yadav commented 3 months ago

I am getting the same error. Let me know if you have figured it out. Thanks!