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 compute_scores_and_loss(self, inputs):
      (
          q_input_ids,
          q_input_mask,
          q_input_type_ids,
          p_input_ids,
          p_input_mask,
          p_input_type_ids,
      ) = inputs
      batch_size, num_passages, p_seq_length = p_input_ids.size()
      q_seq_length = q_input_ids.size()[-1]
  
      scores = self(
          q_input_ids=q_input_ids.view(-1, q_seq_length),
          q_token_type_ids=q_input_type_ids.view(-1, q_seq_length),
          q_attention_mask=q_input_mask.view(-1, q_seq_length),
          p_input_ids=p_input_ids.view(-1, p_seq_length),
          p_token_type_ids=p_input_type_ids.view(-1, p_seq_length),
          p_attention_mask=p_input_mask.view(-1, p_seq_length),
      ).view(batch_size, 1, batch_size + num_passages - 1)
      normalized_scores = torch.log_softmax(scores, dim=-1)
  
      labels = (
          torch.arange(batch_size)[:, None]
          .long()
          .to(normalized_scores.device)
      )
      loss = self.loss(
          log_probs=normalized_scores,
          labels=labels,
          output_mask=torch.ones_like(labels),
      )
  
      scores = scores[:, 0]
      scores = torch.cat(
          (torch.diag(scores)[:, None], scores[:, batch_size:]),
          dim=1,
      )
  
      return scores, loss
  
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 5 for calling the BertDPRModel obj's underlying member method code with example usage: obj.compute_scores_and_loss(inputs) and returns: scores,  loss