Describe the bug
Predicting on examples which generate empty instances should raise an error.
This type of instances make explore
and predict
to fail (at least when using char features)
To Reproduce
pipeline = Pipeline.from_pretrained('runs/v1.text.classifier/model.tar.gz')
pipeline.predict('')
---------------------------------------------------------------------------
RuntimeError Traceback (most recent call last)
<ipython-input-9-002150b8da6a> in <module>
----> 1 pipeline.predict('')
~/recognai/biome/text/src/biome/text/helpers.py in wrapper(*args, **kwargs)
59
60 def wrapper(*args, **kwargs):
---> 61 return to_method(*args, **kwargs)
62
63 wrapper.__signature__ = signature
~/recognai/biome/text/src/biome/text/pipeline.py in predict(self, *args, **kwargs)
284 A dictionary containing the predictions and additional information
285 """
--> 286 return self._model.predict(*args, **kwargs)
287
288 def explain(self, *args, **kwargs) -> Dict[str, Any]:
~/recognai/biome/text/src/biome/text/_model.py in predict(self, *args, **kwargs)
277 inputs = self._model_inputs_from_args(*args, **kwargs)
278 instance = self.text_to_instance(**inputs)
--> 279 prediction = self.forward_on_instance(instance)
280 self.log_prediction(inputs, prediction)
281
/anaconda3/lib/python3.7/site-packages/allennlp/models/model.py in forward_on_instance(self, instance)
144 `torch.Tensors` into numpy arrays and remove the batch dimension.
145 """
--> 146 return self.forward_on_instances([instance])[0]
147
148 def forward_on_instances(self, instances: List[Instance]) -> List[Dict[str, numpy.ndarray]]:
/anaconda3/lib/python3.7/site-packages/allennlp/models/model.py in forward_on_instances(self, instances)
170 dataset.index_instances(self.vocab)
171 model_input = util.move_to_device(dataset.as_tensor_dict(), cuda_device)
--> 172 outputs = self.make_output_human_readable(self(**model_input))
173
174 instance_separated_output: List[Dict[str, numpy.ndarray]] = [
/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
548 result = self._slow_forward(*input, **kwargs)
549 else:
--> 550 result = self.forward(*input, **kwargs)
551 for hook in self._forward_hooks.values():
552 hook_result = hook(self, input, result)
~/recognai/biome/text/src/biome/text/_model.py in forward(self, *args, **kwargs)
134 def forward(self, *args, **kwargs) -> Dict[str, torch.Tensor]:
135 """The main forward method. Wraps the head forward method and converts the head output into a dictionary"""
--> 136 head_output: TaskOutput = self._head.forward(*args, **kwargs)
137 # we don't want to break AllenNLP API: TaskOutput -> as_dict()
138 return head_output.as_dict()
~/recognai/biome/text/src/biome/text/modules/heads/classification/text_classification.py in forward(self, text, label)
66
67 mask = get_text_field_mask(text)
---> 68 embedded_text = self.backbone.forward(text, mask)
69 embedded_text = self.pooler(embedded_text, mask=mask)
70
~/recognai/biome/text/src/biome/text/backbone.py in forward(self, text, mask, num_wrapping_dims)
51 ) -> torch.Tensor:
52 """Applies embedding + encoder layers"""
---> 53 embeddings = self.embedder(text, num_wrapping_dims=num_wrapping_dims)
54 return self.encoder(embeddings, mask=mask)
55
/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
548 result = self._slow_forward(*input, **kwargs)
549 else:
--> 550 result = self.forward(*input, **kwargs)
551 for hook in self._forward_hooks.values():
552 hook_result = hook(self, input, result)
/anaconda3/lib/python3.7/site-packages/allennlp/modules/text_field_embedders/basic_text_field_embedder.py in forward(self, text_field_input, num_wrapping_dims, **kwargs)
82 # If there's only one tensor argument to the embedder, and we just have one tensor to
83 # embed, we can just pass in that tensor, without requiring a name match.
---> 84 token_vectors = embedder(list(tensors.values())[0], **forward_params_values)
85 else:
86 # If there are multiple tensor arguments, we have to require matching names from the
/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
548 result = self._slow_forward(*input, **kwargs)
549 else:
--> 550 result = self.forward(*input, **kwargs)
551 for hook in self._forward_hooks.values():
552 hook_result = hook(self, input, result)
/anaconda3/lib/python3.7/site-packages/allennlp/modules/token_embedders/token_characters_encoder.py in forward(self, token_characters)
35 def forward(self, token_characters: torch.Tensor) -> torch.Tensor:
36 mask = (token_characters != 0).long()
---> 37 return self._dropout(self._encoder(self._embedding(token_characters), mask))
/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py in __call__(self, *input, **kwargs)
548 result = self._slow_forward(*input, **kwargs)
549 else:
--> 550 result = self.forward(*input, **kwargs)
551 for hook in self._forward_hooks.values():
552 hook_result = hook(self, input, result)
/anaconda3/lib/python3.7/site-packages/allennlp/modules/time_distributed.py in forward(self, pass_through, *inputs, **kwargs)
33 pass_through = pass_through or []
34
---> 35 reshaped_inputs = [self._reshape_tensor(input_tensor) for input_tensor in inputs]
36
37 # Need some input to then get the batch_size and time_steps.
/anaconda3/lib/python3.7/site-packages/allennlp/modules/time_distributed.py in <listcomp>(.0)
33 pass_through = pass_through or []
34
---> 35 reshaped_inputs = [self._reshape_tensor(input_tensor) for input_tensor in inputs]
36
37 # Need some input to then get the batch_size and time_steps.
/anaconda3/lib/python3.7/site-packages/allennlp/modules/time_distributed.py in _reshape_tensor(input_tensor)
66 input_size = input_tensor.size()
67 if len(input_size) <= 2:
---> 68 raise RuntimeError(f"No dimension to distribute: {input_size}")
69 # Squash batch_size and time_steps into a single axis; result has shape
70 # (batch_size * time_steps, **input_size).
RuntimeError: No dimension to distribute: torch.Size([1, 0])
Expected behavior
A clear and concise description of what you expected to happen.
Screenshots
If applicable, add screenshots to help explain your problem.
OS environment
- OS: macOS
- biome.text Version 1.0.0rc
Additional context
Add any other context about the problem here.
bug