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.
docstr: Resets the internal states of a stateful encoder.
  
  # Parameters
  
  mask : `torch.BoolTensor`, optional.
      A tensor of shape `(batch_size,)` indicating which states should
      be reset. If not provided, all states will be reset.
docstr_tok: ["Resets","the","internal","states","of","a","stateful","encoder",".","#","Parameters","mask",":","`","torch.BoolTensor","`",",","optional",".","A","tensor","of","shape","`","(","batch_size",",",")","`","indicating","which","states","should","be","reset",".","If","not","provided",",","all","states","will","be","reset","."]
code: def reset_states(self, mask: torch.BoolTensor = None) -> None:
      """
      Resets the internal states of a stateful encoder.
  
      # Parameters
  
      mask : `torch.BoolTensor`, optional.
          A tensor of shape `(batch_size,)` indicating which states should
          be reset. If not provided, all states will be reset.
      """
      if mask is None:
          self._states = None
      else:
          # state has shape (num_layers, batch_size, hidden_size). We reshape
          # mask to have shape (1, batch_size, 1) so that operations
          # broadcast properly.
          mask_batch_size = mask.size(0)
          mask = mask.view(1, mask_batch_size, 1)
          new_states = []
          assert self._states is not None
          for old_state in self._states:
              old_state_batch_size = old_state.size(1)
              if old_state_batch_size != mask_batch_size:
                  raise ValueError(
                      f"Trying to reset states using mask with incorrect batch size. "
                      f"Expected batch size: {old_state_batch_size}. "
                      f"Provided batch size: {mask_batch_size}."
                  )
              new_state = ~mask * old_state
              new_states.append(new_state.detach())
          self._states = tuple(new_states)
  
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 5 for calling the _EncoderBase obj's underlying member method code with example usage: obj.reset_states(mask) without return types