class_docstr: Runs the input reduction method from [Pathologies of Neural Models Make Interpretations
  Difficult](https://arxiv.org/abs/1804.07781), which removes as many words as possible from
  the input without changing the model's prediction.
  
  The functions on this class handle a special case for NER by looking for a field called "tags"
  This check is brittle, i.e., the code could break if the name of this field has changed, or if
  a non-NER model has a field called "tags".
  
  Registered as an `Attacker` with name "input-reduction".
class_docstr_tok: ["Runs","the","input","reduction","method","from","[","Pathologies","of","Neural","Models","Make","Interpretations","Difficult","]","(","https",":","\/\/arxiv.org\/abs\/1804.07781",")",",","which","removes","as","many","words","as","possible","from","the","input","without","changing","the","model","'s","prediction",".","The","functions","on","this","class","handle","a","special","case","for","NER","by","looking","for","a","field","called","``","tags","''","This","check","is","brittle",",","i.e.",",","the","code","could","break","if","the","name","of","this","field","has","changed",",","or","if","a","non-NER","model","has","a","field","called","``","tags","''",".","Registered","as","an","`","Attacker","`","with","name","``","input-reduction","''","."]
code: def attack_from_json(
      self,
      inputs: JsonDict,
      input_field_to_attack: str = "tokens",
      grad_input_field: str = "grad_input_1",
      ignore_tokens: List[str] = None,
      target: JsonDict = None,
  ):
      if target is not None:
          raise ValueError(
              "Input reduction does not implement targeted attacks"
          )
      ignore_tokens = (
          ["@@NULL@@"] if ignore_tokens is None else ignore_tokens
      )
      original_instances = self.predictor.json_to_labeled_instances(
          inputs
      )
      original_text_field: TextField = original_instances[0][  # type: ignore
          input_field_to_attack
      ]
      original_tokens = deepcopy(original_text_field.tokens)
      final_tokens = []
      for instance in original_instances:
          final_tokens.append(
              self._attack_instance(
                  inputs,
                  instance,
                  input_field_to_attack,
                  grad_input_field,
                  ignore_tokens,
              )
          )
      return sanitize(
          {"final": final_tokens, "original": original_tokens}
      )
  
file_path: allennlp/allennlp/interpret/attackers/input_reduction.py
imports: from copy import deepcopy
  from typing import List, Tuple
  import heapq
  import numpy
  import torch
  from allennlp.common.util import JsonDict, sanitize
  from allennlp.data import Instance
  from allennlp.data.fields import TextField, SequenceLabelField
  from allennlp.interpret.attackers import utils
  from allennlp.interpret.attackers.attacker import Attacker
  from allennlp.predictors import Predictor
label_desc: Use image node_id 2 for calling the InputReduction obj's underlying member method code with example usage: obj.attack_from_json(inputs, input_field_to_attack, grad_input_field, ignore_tokens, target) and returns: sanitize