class_docstr: This class can be used to compose several encoders in sequence.
  
  Among other things, this can be used to add a "pre-contextualizer" before a Seq2SeqEncoder.
  
  Registered as a `Seq2SeqEncoder` with name "compose".
  
  # Parameters
  
  encoders : `List[Seq2SeqEncoder]`, required.
      A non-empty list of encoders to compose. The encoders must match in bidirectionality.
code: def __init__(self, encoders: List[Seq2SeqEncoder]):
      super().__init__()
      self.encoders = encoders
      for idx, encoder in enumerate(encoders):
          self.add_module("encoder%d" % idx, encoder)
  
      # Compute bidirectionality.
      all_bidirectional = all(
          encoder.is_bidirectional() for encoder in encoders
      )
      any_bidirectional = any(
          encoder.is_bidirectional() for encoder in encoders
      )
      self.bidirectional = all_bidirectional
  
      if all_bidirectional != any_bidirectional:
          raise ValueError(
              "All encoders need to match in bidirectionality."
          )
  
      if len(self.encoders) < 1:
          raise ValueError("Need at least one encoder.")
  
      last_enc = None
      for enc in encoders:
          if (
              last_enc is not None
              and last_enc.get_output_dim() != enc.get_input_dim()
          ):
              raise ValueError(
                  "Encoder input and output dimensions don't match."
              )
          last_enc = enc
  
file_path: allennlp/allennlp/modules/seq2seq_encoders/compose_encoder.py
imports: import torch
  from typing import List
  from allennlp.modules.seq2seq_encoders.seq2seq_encoder import Seq2SeqEncoder
label_desc: Use image node_id 1 to create a new ComposeEncoder object from inherited base classes: Seq2SeqEncoder with example: obj = ComposeEncoder(encoders)