class_docstr: Combines a list / sequence of embeddings into one using a biLSTM
class_docstr_tok: ["Combines","a","list","\/","sequence","of","embeddings","into","one","using","a","biLSTM"]
docstr: Embed the sequence. If the input corresponds to [IN:GL where am I at]:
  - x will contain the embeddings of [at I am where IN:GL] in that order.
  - Forward LSTM will embed the sequence [IN:GL where am I at].
  - Backward LSTM will embed the sequence [IN:GL at I am where].
  The final hidden states are concatenated and then projected.
  
  Args:
      x: Embeddings of the input tokens in *reversed* order
  Shapes:
      x: (1, lstm_dim) each
      return value: (1, lstm_dim)
docstr_tok: ["Embed","the","sequence",".","If","the","input","corresponds","to","[","IN",":","GL","where","am","I","at","]",":","-","x","will","contain","the","embeddings","of","[","at","I","am","where","IN",":","GL","]","in","that","order",".","-","Forward","LSTM","will","embed","the","sequence","[","IN",":","GL","where","am","I","at","]",".","-","Backward","LSTM","will","embed","the","sequence","[","IN",":","GL","at","I","am","where","]",".","The","final","hidden","states","are","concatenated","and","then","projected",".","Args",":","x",":","Embeddings","of","the","input","tokens","in","*","reversed","*","order","Shapes",":","x",":","(","1",",","lstm_dim",")","each","return","value",":","(","1",",","lstm_dim",")"]
code: def forward(
      self, x: List[torch.Tensor], device: str = "cpu"
  ) -> torch.Tensor:
      """
      Embed the sequence. If the input corresponds to [IN:GL where am I at]:
      - x will contain the embeddings of [at I am where IN:GL] in that order.
      - Forward LSTM will embed the sequence [IN:GL where am I at].
      - Backward LSTM will embed the sequence [IN:GL at I am where].
      The final hidden states are concatenated and then projected.
  
      Args:
          x: Embeddings of the input tokens in *reversed* order
      Shapes:
          x: (1, lstm_dim) each
          return value: (1, lstm_dim)
      """
      # reset hidden state every time
      lstm_hidden_fwd = (
          xaviervar([1, 1, self.lstm_dim], device=device),
          xaviervar([1, 1, self.lstm_dim], device=device),
      )
      lstm_hidden_rev = (
          xaviervar([1, 1, self.lstm_dim], device=device),
          xaviervar([1, 1, self.lstm_dim], device=device),
      )
      nonterminal_element = x[-1]
      reversed_rest = x[:-1]
      # Always put nonterminal_element at the front
      fwd_input = [nonterminal_element] + reverse_tensor_list(
          reversed_rest
      )
      rev_input = [nonterminal_element] + reversed_rest
      stacked_fwd = self.lstm_fwd(
          torch.stack(fwd_input), lstm_hidden_fwd
      )[0][0]
      stacked_rev = self.lstm_rev(
          torch.stack(rev_input), lstm_hidden_rev
      )[0][0]
      combined = torch.cat([stacked_fwd, stacked_rev], dim=1)
      subtree_embedding = self.linear_seq(combined)
      return subtree_embedding
  
imports: from typing import Any, List, Sized, Tuple
  import torch
  import torch.nn
  from pytext.torchscript.utils import reverse_tensor_list
  from pytext.utils.cuda import FloatTensor
  from pytext.utils.tensor import xaviervar
label_desc: Use image node_id 2 for calling the CompositionalNN obj's underlying member method code with example usage: obj.forward(x, device) and returns: subtree_embedding