class_docstr: Bi-Encoder model component. Encapsulates query/question and context/passage encoders.
      
code: def forward(self, batch, output_all_encoded_layers=False):
      # batch keys
      #   imgs
      #   txts
      #   caps
      batch = defaultdict(lambda: None, batch)
  
      if "txts" in batch:
          sb = batch["txts"]
          txt_seq, txt_pooled, _ = self.get_representation(
              self.txt_model,
              sb["input_ids"],
              sb["attention_mask"],
              sb["position_ids"],
              sb["img_feat"],
              sb["img_pos_feat"],
              sb["img_masks"],
              sb["gather_index"],
              self.fix_txt_encoder,
          )
      else:
          txt_seq, txt_pooled = None, None
  
      if "imgs" in batch:
          sb = batch["imgs"]
          img_seq, img_pooled, _ = self.get_representation(
              self.img_model,
              sb["input_ids"],
              sb["attention_mask"],
              sb["position_ids"],
              sb["img_feat"],
              sb["img_pos_feat"],
              sb["img_masks"],
              sb["gather_index"],
              self.fix_txt_encoder,
          )
      else:
          img_seq, img_pooled = None, None
  
      if "caps" in batch and batch["caps"]["input_ids"] is not None:
          sb = batch["caps"]
          cap_seq, cap_pooled, _ = self.get_representation(
              self.txt_model,
              sb["input_ids"],
              sb["attention_mask"],
              sb["position_ids"],
              sb["img_feat"],
              sb["img_pos_feat"],
              sb["img_masks"],
              sb["gather_index"],
              self.fix_txt_encoder,
          )
      else:
          cap_seq, cap_pooled = None, None
  
      if output_all_encoded_layers:
          return txt_seq, img_seq, cap_seq
      else:
          return txt_pooled, img_pooled, cap_pooled
  
file_path: towhee/towhee/models/lightning_dot/bi_encoder.py
imports: from typing import Any
  import torch
  from collections import defaultdict
  from torch import nn
label_desc: Use image node_id 3 for calling the BiEncoder obj's underlying member method code with example usage: obj.forward(batch, output_all_encoded_layers) and returns: txt_seq,  img_seq,  cap_seq, txt_pooled,  img_pooled,  cap_pooled