Skip to content
DeepForgeby svx
All problems
EasyNLPnlp-150

In-Batch Negatives Count

Problem

Return the total number of in-batch negatives for a batch of size batch_size: every query is contrasted against the other batch_size - 1 passages.

So the count is batch_size * (batch_size - 1), and a non-positive batch size gives 0.

Hint

Each of the n queries sees n - 1 negatives.

Test cases

case 1
in: [4]
expected: 12
case 2
in: [1]
expected: 0
case 3
in: [2]
expected: 2
case 4
in: [0]
expected: 0
Starter codePython
def in_batch_negatives_count(batch_size):
    # Your code here
    pass

4 test cases · run your code against them in the editor