Closed schmmd closed 6 years ago
I'm trying to get a more focused error case, but the exception doesn't happen if I shrink the input sentences most ways. I get a similar exception when I input an empty string ""
as a tokenized sentence--but that isn't really valid input anyway.
sentences = [""]
ee = ElmoEmbedder()
print("Embedding sentences")
embeddings = []
for sentence, embedding in zip(sentences, ee.embed_sentences(sentences, batch_size=3)):
print(sentence)
embeddings.append(embedding)
Traceback (most recent call last):
File "elmo_failure_case.py", line 17, in <module>
for sentence, embedding in zip(sentences, ee.embed_sentences(sentences, batch_size=3)):
File "/Users/michaels/hack/allenai/allennlp/allennlp/commands/elmo.py", line 246, in embed_sentences
yield from self.embed_batch(batch)
File "/Users/michaels/hack/allenai/allennlp/allennlp/commands/elmo.py", line 214, in embed_batch
embeddings, mask = self.batch_to_embeddings(batch)
File "/Users/michaels/hack/allenai/allennlp/allennlp/commands/elmo.py", line 165, in batch_to_embeddings
character_ids = self.batch_to_ids(batch)
File "/Users/michaels/hack/allenai/allennlp/allennlp/commands/elmo.py", line 151, in batch_to_ids
return dataset.as_tensor_dict()['elmo']['character_ids']
File "/Users/michaels/hack/allenai/allennlp/allennlp/data/dataset.py", line 155, in as_tensor_dict
final_fields[field_name] = field_classes[field_name].batch_tensors(field_tensor_list)
File "/Users/michaels/hack/allenai/allennlp/allennlp/data/fields/text_field.py", line 137, in batch_tensors
return util.batch_tensor_dicts(tensor_list)
File "/Users/michaels/hack/allenai/allennlp/allennlp/nn/util.py", line 41, in batch_tensor_dicts
batched_tensor = torch.stack(tensor_list)
File "/Users/michaels/miniconda3/envs/allennlp/lib/python3.6/site-packages/torch/functional.py", line 62, in stack
inputs = [t.unsqueeze(dim) for t in sequence]
File "/Users/michaels/miniconda3/envs/allennlp/lib/python3.6/site-packages/torch/functional.py", line 62, in <listcomp>
inputs = [t.unsqueeze(dim) for t in sequence]
RuntimeError: dimension specified as 0 but tensor has no dimensions
Do you have an extra newline at the end? It sure looks like there's an input that's empty somewhere.
@matt-gardner yes I do--but that newline doesn't cause an exception all the time. It depends on the number of sentences and the batch size.
I love to sail forbidden seas, and land on barbarous coasts.
Not ignoring what is good, I am quick to perceive a horror, and could still be social with it- would they let me- since it is but well to be on friendly terms with all the inmates of the place one lodges in.
By reason of these things, then, the whaling voyage was welcome; the great flood-gates of the wonder-world swung open, and in the wild conceits that swayed me to my purpose, two and two there floated into my inmost soul, endless processions of the whale, and, mid most of them all, one grand hooded phantom, like a snow hill in the air.
Here's a smaller case that causes an exception.
Maybe this happens when you end up with just that sentence in the batch? In any event, you should probably just strip all blank sentences from the input in the script.
@matt-gardner I think that's it (although I still have some confusing mysteries). I'd like to add an assert so we fail on any blank input with a reasonable exception rather than failing on blank inputs only if they are alone in a batch.
Any particular reason for an assert instead of removing the inputs? It'd be nice to just give a large file that may or may not have blank lines, and have it just work.
@matt-gardner I wanted to both handle the error case and have an assert, so if others hit the same issue they would have a clear exception. But I didn't quite figure that out...
Data (
sentences.txt
):Code:
Exception: