I was not sure if setting this issue as a Bug because I may be doing something wrong, but I cannot use LSTM for DocumentRNNEmbeddings. I do the same thing you do in Tutorial 5:
from flair.embeddings import WordEmbeddings, DocumentRNNEmbeddings
glove_embedding = WordEmbeddings('glove')
document_lstm_embeddings = DocumentRNNEmbeddings([glove_embedding], rnn_type='LSTM')
and then I try to get the embeddings of my document:
sentence = Sentence("This is an example of document")
document_embeddings.embed(sentence)
my_embedding = sentence.get_embedding()
But I get the following error:
KeyError Traceback (most recent call last)
<ipython-input-9-c18b521697f5> in <module>()
23 sentence = Sentence(document)
24
---> 25 document_embeddings.embed(sentence)
26
27 embeddings.append(sentence.get_embedding().tolist())
2 frames
/usr/local/lib/python3.6/dist-packages/torch/nn/modules/rnn.py in forward(self, input, hx)
206
207 self.check_forward_args(input, hx, batch_sizes)
--> 208 _impl = _rnn_impls[self.mode]
209 if batch_sizes is None:
210 result = _impl(input, hx, self._get_flat_weights(), self.bias, self.num_layers,
KeyError: 'LSTM'
I think this is a bug that we already fixed on the master branch. Could you try running
pip install --upgrade git+https://github.com/zalandoresearch/flair.git
This installs the current master branch and should fix the bug.
Looks like this still happens even on master
File "./main.py", line 81, in classify
classifier.predict(sentence)
File "/Users/elieh/Projects/fastapi/venv/lib/python3.6/site-packages/flair/models/text_classification_model.py", line 147, in predict
scores = self.forward(batch)
File "/Users/elieh/Projects/fastapi/venv/lib/python3.6/site-packages/flair/models/text_classification_model.py", line 72, in forward
self.document_embeddings.embed(sentences)
File "/Users/elieh/Projects/fastapi/venv/lib/python3.6/site-packages/flair/embeddings.py", line 2238, in embed
rnn_out, hidden = self.rnn(packed)
File "/Users/elieh/Projects/fastapi/venv/lib/python3.6/site-packages/torch/nn/modules/module.py", line 493, in __call__
result = self.forward(*input, **kwargs)
File "/Users/elieh/Projects/fastapi/venv/lib/python3.6/site-packages/torch/nn/modules/rnn.py", line 208, in forward
_impl = _rnn_impls[self.mode]
KeyError: 'LSTM'
Uninstalled and installed the master branch:
pip freeze | grep flair
flair==0.4.2
I am running into the same issue on master as well.
Hm I cannot reproduce. What version of PyTorch do you have installed?
I am running PyTorch 1.1.0.
I am experiencing this also -
flair==0.4.2
pytorch-pretrained-bert==0.6.2
pytorch-transformers==1.0.0
Hi, we've just released Flair 0.4.3 that fixes this bug - could you update your Flair version and see if this is still an issue for you?
This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.
Most helpful comment
I think this is a bug that we already fixed on the master branch. Could you try running
This installs the current master branch and should fix the bug.