{"record":{"id":"3767f8918b3cdfea","repo":"tensorflow/models","slug":"num-positives-was-provided-but-it-was-a-negative","errorCode":null,"errorMessage":"'num_positives' was provided but it was a negative number.","messagePattern":"'num_positives' was provided but it was a negative number\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"official/projects/yt8m/eval_utils/average_precision_calculator.py","lineNumber":118,"sourceCode":"    Args:\n      predictions: a list storing the prediction scores.\n      actuals: a list storing the ground truth labels. Any value larger than 0\n        will be treated as positives, otherwise as negatives. num_positives = If\n        the 'predictions' and 'actuals' inputs aren't complete, then it's\n        possible some true positives were missed in them. In that case, you can\n        provide 'num_positives' in order to accurately track recall.\n      num_positives: number of positive examples.\n\n    Raises:\n      ValueError: An error occurred when the format of the input is not the\n      numpy 1-D array or the shape of predictions and actuals does not match.\n    \"\"\"\n    if len(predictions) != len(actuals):\n      raise ValueError(\"the shape of predictions and actuals does not match.\")\n\n    if num_positives is not None:\n      if not isinstance(num_positives, numbers.Number) or num_positives < 0:  # pyrefly: ignore[unsupported-operation]\n        raise ValueError(\n            \"'num_positives' was provided but it was a negative number.\")\n\n    if num_positives is not None:\n      self._total_positives += num_positives\n    else:\n      self._total_positives += numpy.size(\n          numpy.where(numpy.array(actuals) > 1e-5))\n    topk = self._top_n\n    heap = self._heap\n\n    for i in range(numpy.size(predictions)):\n      if topk is None or len(heap) < topk:\n        heapq.heappush(heap, (predictions[i], actuals[i]))\n      else:\n        if predictions[i] > heap[0][0]:  # heap[0] is the smallest\n          heapq.heappop(heap)\n          heapq.heappush(heap, (predictions[i], actuals[i]))\n","sourceCodeStart":100,"sourceCodeEnd":136,"githubUrl":"https://github.com/tensorflow/models/blob/e006f5f0d534913e49c1f1dae87364039fa607e2/official/projects/yt8m/eval_utils/average_precision_calculator.py#L100-L136","documentation":"Error \"'num_positives' was provided but it was a negative number.\" thrown in tensorflow/models.","triggerScenarios":"Thrown at official/projects/yt8m/eval_utils/average_precision_calculator.py:118 when the library encounters an invalid state.","commonSituations":"See trigger scenarios.","solutions":[],"exampleFix":null,"handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"e006f5f0d534913e49c1f1dae87364039fa607e2","analyzedAt":"2026-08-24T14:09:15.576Z","schemaVersion":2},"datasetVersion":"2026-08-24T17:17:21.512Z"}