FlagEmbedding icon indicating copy to clipboard operation
FlagEmbedding copied to clipboard

关于微调的问题

Open Powerdiao opened this issue 11 months ago • 2 comments

你好,想问关于以下几个问题

  1. 如果有n个query,n8个passage,即每个query都有一个正例和七个负例。每个query都会与n8计算score吗?最后会得到一个(n, 8n)大小的scores矩阵
  2. target[i]的含义是第i个query对应的正例index吗?
  3. 在计算crossEntropy时,只有正例对loss有贡献,负例相关的loss都为0吗?
 q_reps = self.encode(query)
  p_reps = self.encode(passage)

  if self.training:
      if self.negatives_cross_device:
          q_reps = self._dist_gather_tensor(q_reps)
          p_reps = self._dist_gather_tensor(p_reps)

      scores = self.compute_similarity(q_reps, p_reps)
      scores = scores / self.temperature
      scores = scores.view(q_reps.size(0), -1)

      target = torch.arange(scores.size(0), device=scores.device, dtype=torch.long)
      target = target * (p_reps.size(0) // q_reps.size(0))
      loss = self.compute_loss(scores, target)

Powerdiao avatar Mar 11 '24 06:03 Powerdiao

  1. 对的
  2. 是的
  3. crossEntropy目标是增大正例的概率。正例的概率是通过softmax计算得到的,负例的分数会在softmax中作为分母。因此优化正例的概率会增大正样本分数,减小负样本分数。

staoxiao avatar Mar 11 '24 09:03 staoxiao

  1. 对的
  2. 是的
  3. crossEntropy目标是增大正例的概率。正例的概率是通过softmax计算得到的,负例的分数会在softmax中作为分母。因此优化正例的概率会增大正样本分数,减小负样本分数。 明白了,十分感谢!!

Powerdiao avatar Mar 11 '24 12:03 Powerdiao