Skip to content

Instantly share code, notes, and snippets.

@jhumigas
Last active June 30, 2020 01:28
Show Gist options
  • Save jhumigas/7b984c96d89f6f53e7ea3d0afa4f4b09 to your computer and use it in GitHub Desktop.
Save jhumigas/7b984c96d89f6f53e7ea3d0afa4f4b09 to your computer and use it in GitHub Desktop.
Augmenting the LSTM PoS tagger with Character-level features (PyTorch)
Display the source blob
Display the rendered blob
Raw
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@anirudhprabhu
Copy link

anirudhprabhu commented May 7, 2020

Hello @jhumigas,

I tried out the code you have compiled for the character level LSTM. It generates the following error (with traceback):
Can you help me figure out what has gone wrong?
Thank you.

IndexError                                Traceback (most recent call last)
<ipython-input-11-16c14b79baf2> in <module>
      6 inputs = prepare_sequence(training_data[0][0], word_to_ix)
      7 words_tensors = prepare_words_tensor(word_to_ix, char_to_ix)
----> 8 tag_scores = model(inputs, words_tensors)
      9 # print(tag_scores)
     10 

~/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
    530             result = self._slow_forward(*input, **kwargs)
    531         else:
--> 532             result = self.forward(*input, **kwargs)
    533         for hook in self._forward_hooks.values():
    534             hook_result = hook(self, input, result)

<ipython-input-8-6bb1b6181605> in forward(self, sentence_seq, words_tensor_dict)
     66             # Now here we will only keep the final hidden state of the character level LSTM
     67             # i.e lstm_char_out[-1]
---> 68             embeds_cat = torch.cat((embeds, lstm_char_out[-1]), dim=1)
     69 
     70             lstm_out, self.hidden_words = self.lstm_words(embeds_cat, self.hidden_words)

IndexError: Dimension out of range (expected to be in range of [-1, 0], but got 1)```

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment