class_docstr: Information retrieval model which encodes query and passage separately
  with two different BERT encoders and computes their similarity score
  as a dot-product between corresponding [CLS] token representations.
class_docstr_tok: ["Information","retrieval","model","which","encodes","query","and","passage","separately","with","two","different","BERT","encoders","and","computes","their","similarity","score","as","a","dot-product","between","corresponding","[","CLS","]","token","representations","."]
code: def forward(
      self,
      q_input_ids,
      q_token_type_ids,
      q_attention_mask,
      p_input_ids,
      p_token_type_ids,
      p_attention_mask,
  ):
      q_vectors = self.q_encoder(
          input_ids=q_input_ids,
          token_type_ids=q_token_type_ids,
          attention_mask=q_attention_mask,
      )
      q_vectors = q_vectors[:, 0]
      batch_size, hidden_size = q_vectors.size()
  
      p_vectors = self.p_encoder(
          input_ids=p_input_ids,
          token_type_ids=p_token_type_ids,
          attention_mask=p_attention_mask,
      )
      num_passages = p_vectors.shape[0] // batch_size
      p_vectors = p_vectors[:, 0].view(-1, num_passages, hidden_size)
      p_positives, p_negatives = p_vectors[:, 0], p_vectors[:, 1:]
      scores = torch.cat(
          (
              torch.matmul(q_vectors, p_positives.T),
              torch.einsum("ij,ipj->ip", q_vectors, p_negatives),
          ),
          dim=1,
      )
  
      return scores
  
file_path: NeMo/nemo/collections/nlp/models/information_retrieval/bert_dpr_model.py
imports: from typing import Dict, Optional
  import torch
  from omegaconf import DictConfig
  from pytorch_lightning import Trainer
  from nemo.collections.common.losses import SmoothedCrossEntropyLoss
  from nemo.collections.nlp.data import BertInformationRetrievalDataset
  from nemo.collections.nlp.models.information_retrieval.base_ir_model import BaseIRModel
  from nemo.collections.nlp.modules.common.tokenizer_utils import get_tokenizer
  from nemo.core.classes.common import typecheck
  from nemo.core.neural_types import ChannelType, LogitsType, MaskType, NeuralType
label_desc: Use image node_id 4 for calling the BertDPRModel obj's underlying member method code with example usage: obj.forward(q_input_ids, q_token_type_ids, q_attention_mask, p_input_ids, p_token_type_ids, p_attention_mask) and returns: scores