class_docstr: Represents spans from a bidirectional encoder as a concatenation of two different
  representations of the span endpoints, one for the forward direction of the encoder
  and one from the backward direction. This type of representation encodes some subtelty,
  because when you consider the forward and backward directions separately, the end index
  of the span for the backward direction's representation is actually the start index.
  
  By default, this ``SpanExtractor`` represents spans as
  ``sequence_tensor[inclusive_span_end] - sequence_tensor[exclusive_span_start]``
  meaning that the representation is the difference between the the last word in the span
  and the word `before` the span started. Note that the start and end indices are with
  respect to the direction that the RNN is going in, so for the backward direction, the
  start/end indices are reversed.
  
  Additionally, the width of the spans can be embedded and concatenated on to the
  final combination.
  
  The following other types of representation are supported for both the forward and backward
  directions, assuming that ``x = span_start_embeddings`` and ``y = span_end_embeddings``.
  
  ``x``, ``y``, ``x*y``, ``x+y``, ``x-y``, ``x/y``, where each of those binary operations
  is performed elementwise.  You can list as many combinations as you want, comma separated.
  For example, you might give ``x,y,x*y`` as the ``combination`` parameter to this class.
  The computed similarity function would then be ``[x; y; x*y]``, which can then be optionally
  concatenated with an embedded representation of the width of the span.
  
  Parameters
  ----------
  input_dim : ``int``, required.
      The final dimension of the ``sequence_tensor``.
  forward_combination : str, optional (default = "y-x").
      The method used to combine the ``forward_start_embeddings`` and ``forward_end_embeddings``
      for the forward direction of the bidirectional representation.
      See above for a full description.
  backward_combination : str, optional (default = "x-y").
      The method used to combine the ``backward_start_embeddings`` and ``backward_end_embeddings``
      for the backward direction of the bidirectional representation.
      See above for a full description.
  num_width_embeddings : ``int``, optional (default = None).
      Specifies the number of buckets to use when representing
      span width features.
  span_width_embedding_dim : ``int``, optional (default = None).
      The embedding size for the span_width features.
  bucket_widths : ``bool``, optional (default = False).
      Whether to bucket the span widths into log-space buckets. If ``False``,
      the raw span widths are used.
  use_sentinels : ``bool``, optional (default = ``True``).
      If ``True``, sentinels are used to represent exclusive span indices for the elements
      in the first and last positions in the sequence (as the exclusive indices for these
      elements are outside of the the sequence boundary). This is not strictly necessary,
      as you may know that your exclusive start and end indices are always within your sequence
      representation, such as if you have appended/prepended <START> and <END> tokens to your
      sequence.
code: def __init__(
      self,
      input_dim,
      forward_combination="y-x",
      backward_combination="x-y",
      num_width_embeddings=None,
      span_width_embedding_dim=None,
      bucket_widths=False,
      use_sentinels=True,
  ):
      super(BidirectionalEndpointSpanExtractor, self).__init__()
      self._input_dim = input_dim
      self._forward_combination = forward_combination
      self._backward_combination = backward_combination
      self._num_width_embeddings = num_width_embeddings
      self._bucket_widths = bucket_widths
  
      if self._input_dim % 2 != 0:
          raise ConfigurationError(
              "The input dimension is not divisible by 2, but the "
              "BidirectionalEndpointSpanExtractor assumes the embedded representation "
              "is bidirectional (and hence divisible by 2)."
          )
      if (
          num_width_embeddings is not None
          and span_width_embedding_dim is not None
      ):
          self._span_width_embedding = Embedding(
              num_width_embeddings, span_width_embedding_dim
          )
      elif not all(
          [
              num_width_embeddings is None,
              span_width_embedding_dim is None,
          ]
      ):
          raise ConfigurationError(
              "To use a span width embedding representation, you must"
              "specify both num_width_buckets and span_width_embedding_dim."
          )
      else:
          self._span_width_embedding = None
  
      self._use_sentinels = use_sentinels
      if use_sentinels:
          self._start_sentinel = Parameter(
              torch.randn([1, 1, int(input_dim / 2)])
          )
          self._end_sentinel = Parameter(
              torch.randn([1, 1, int(input_dim / 2)])
          )
  
file_path: magnitude/pymagnitude/third_party/allennlp/modules/span_extractors/bidirectional_endpoint_span_extractor.py
imports: from __future__ import division
  from __future__ import absolute_import
  import torch
  from torch.nn.parameter import Parameter
  from allennlp.modules.span_extractors.span_extractor import SpanExtractor
  from allennlp.modules.token_embedders.embedding import Embedding
  from allennlp.nn import util
  from allennlp.common.checks import ConfigurationError
label_desc: Use image node_id 1 to create a new BidirectionalEndpointSpanExtractor object from inherited base classes: SpanExtractor with example: obj = BidirectionalEndpointSpanExtractor(input_dim, forward_combination, backward_combination, num_width_embeddings, span_width_embedding_dim, bucket_widths, use_sentinels)