class_docstr: A `SaliencyInterpreter` interprets an AllenNLP Predictor's outputs by assigning a saliency
  score to each input token.
class_docstr_tok: ["A","`","SaliencyInterpreter","`","interprets","an","AllenNLP","Predictor","'s","outputs","by","assigning","a","saliency","score","to","each","input","token","."]
code: def _aggregate_token_embeddings(
      embeddings_list: List[torch.Tensor],
      token_offsets: List[torch.Tensor],
  ) -> List[numpy.ndarray]:
      if len(token_offsets) == 0:
          return [
              embeddings.detach().cpu().numpy()
              for embeddings in embeddings_list
          ]
      aggregated_embeddings = []
      # NOTE: This is assuming that embeddings and offsets come in the same order, which may not
      # be true.  But, the intersection of using multiple TextFields with mismatched indexers is
      # currently zero, so we'll delay handling this corner case until it actually causes a
      # problem.  In practice, both of these lists will always be of size one at the moment.
      for embeddings, offsets in zip(embeddings_list, token_offsets):
          span_embeddings, span_mask = util.batched_span_select(
              embeddings.contiguous(), offsets
          )
          span_mask = span_mask.unsqueeze(-1)
          span_embeddings *= span_mask  # zero out paddings
  
          span_embeddings_sum = span_embeddings.sum(2)
          span_embeddings_len = span_mask.sum(2)
          # Shape: (batch_size, num_orig_tokens, embedding_size)
          embeddings = span_embeddings_sum / torch.clamp_min(
              span_embeddings_len, 1
          )
  
          # All the places where the span length is zero, write in zeros.
          embeddings[
              (span_embeddings_len == 0).expand(embeddings.shape)
          ] = 0
          aggregated_embeddings.append(
              embeddings.detach().cpu().numpy()
          )
      return aggregated_embeddings
  
file_path: allennlp/allennlp/interpret/saliency_interpreters/saliency_interpreter.py
imports: from typing import List
  import numpy
  import torch
  from allennlp.common import Registrable
  from allennlp.common.util import JsonDict
  from allennlp.nn import util
  from allennlp.predictors import Predictor
label_desc: Use image node_id 3 for calling the SaliencyInterpreter obj's underlying member method code with example usage: obj._aggregate_token_embeddings(embeddings_list, token_offsets) and returns: aggregated_embeddings, unknown