code: def _last_dimension_applicator(function_to_apply, tensor, mask=None):
      """
      Takes a tensor with 3 or more dimensions and applies a function over the last dimension.  We
      assume the tensor has shape ``(batch_size, ..., sequence_length)`` and that the mask (if given)
      has shape ``(batch_size, sequence_length)``.  We first unsqueeze and expand the mask so that it
      has the same shape as the tensor, then flatten them both to be 2D, pass them through
      the function and put the tensor back in its original shape.
      """
      tensor_shape = tensor.size()
      reshaped_tensor = tensor.view(-1, tensor.size()[-1])
      if mask is not None:
          while mask.dim() < tensor.dim():
              mask = mask.unsqueeze(1)
          mask = mask.expand_as(tensor).contiguous().float()
          mask = mask.view(-1, mask.size()[-1])
      reshaped_result = function_to_apply(reshaped_tensor, mask)
      return reshaped_result.view(*tensor_shape)
  
imports: from __future__ import division
  from __future__ import absolute_import
  from collections import defaultdict
  import logging
  import math
  import torch
  from allennlp.common.checks import ConfigurationError
label_desc: Use image node_id 13 for calling a global function with example usage: _last_dimension_applicator(function_to_apply, tensor, mask) and returns: reshaped_result