Skip to content
This repository was archived by the owner on Dec 16, 2022. It is now read-only.
This repository was archived by the owner on Dec 16, 2022. It is now read-only.

deepcopy(instance) fails when using mismatched indexer. #4270

@dheerajrajagopal

Description

@dheerajrajagopal

Describe the bug
deepcopy(instance) fails when using mismatched indexer.

Stack Trace


20 to the input and returns those gradients normalized and sanitized.
21 """
---> 22 labeled_instances = self.predictor.json_to_labeled_instances(inputs)
23
24 # List of embedding inputs, used for multiplying gradient by the input for normalization
/usr1/home/dheeraj/anaconda3/envs/interpret-baseline/lib/python3.7/site-packages/allennlp/predictors/predictor.py in json_to_labeled_instances(self, inputs)
62 instance = self._json_to_instance(inputs)
63 outputs = self._model.forward_on_instance(instance)
---> 64 new_instances = self.predictions_to_labeled_instances(instance, outputs)
65 return new_instances
66
/usr1/home/dheeraj/anaconda3/envs/interpret-baseline/lib/python3.7/site-packages/allennlp/predictors/text_classifier.py in predictions_to_labeled_instances(self, instance, outputs)
43 self, instance: Instance, outputs: Dict[str, numpy.ndarray]
44 ) -> List[Instance]:
---> 45 new_instance = deepcopy(instance)
46 label = numpy.argmax(outputs["probs"])
47 new_instance.add_field("label", LabelField(int(label), skip_indexing=True))
/usr1/home/dheeraj/anaconda3/envs/interpret-baseline/lib/python3.7/copy.py in deepcopy(x, memo, _nil)
178 y = x
179 else:
--> 180 y = _reconstruct(x, memo, *rv)

To Reproduce

from allennlp.predictors.predictor import Predictor
from allennlp.data.tokenizers import SpacyTokenizer
import allennlp_models.sentiment
from allennlp.interpret.saliency_interpreters import SimpleGradient

predictor = Predictor.from_path("https://storage.googleapis.com/allennlp-public-models/sst-roberta-large-2020.05.05.tar.gz")
predictor.predict(
   sentence="a very well-made, funny and entertaining picture."
 )
tokenizer = SpacyTokenizer()
tokenized_sentence = tokenizer.tokenize("a very well-made, funny and entertaining picture.")
simple_grad_viz =  SimpleGradient(predictor).saliency_interpret_from_json({'sentence':"a very well-made, funny and entertaining picture."}) 

Expected behavior
Should not give an error

System (please complete the following information):

  • OS: Linux (Ubuntu 18.04)
  • Python version: 3.7.4
  • AllenNLP version: v1.0.0.rc4
  • PyTorch version: 1.5.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions