class_docstr: This abstract class serves as a base for the 3 `Encoder` abstractions in AllenNLP.
  - [`Seq2SeqEncoders`](./seq2seq_encoders/seq2seq_encoder.md)
  - [`Seq2VecEncoders`](./seq2vec_encoders/seq2vec_encoder.md)
  
  Additionally, this class provides functionality for sorting sequences by length
  so they can be consumed by Pytorch RNN classes, which require their inputs to be
  sorted by length. Finally, it also provides optional statefulness to all of it's
  subclasses by allowing the caching and retrieving of the hidden states of RNNs.
code: def __init__(self, stateful: bool = False) -> None:
      super().__init__()
      self.stateful = stateful
      self._states: Optional[RnnStateStorage] = None
  
file_path: allennlp/allennlp/modules/encoder_base.py
imports: from typing import Tuple, Union, Optional, Callable, Any
  import torch
  from torch.nn.utils.rnn import pack_padded_sequence, PackedSequence
  from allennlp.nn.util import get_lengths_from_binary_sequence_mask, sort_batch_by_length
label_desc: Use image node_id 1 to create a new _EncoderBase object from inherited base classes: torch.nn with example: obj = _EncoderBase(stateful)