{"record":{"id":"51185377f4c60ee2","repo":"huggingface/transformers","slug":"no-valid-predictions","errorCode":null,"errorMessage":"No valid predictions","messagePattern":"No valid predictions","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"src/transformers/data/metrics/squad_metrics.py","lineNumber":539,"sourceCode":"\n            nbest.append(_NbestPrediction(text=final_text, start_logit=pred.start_logit, end_logit=pred.end_logit))\n        # if we didn't include the empty option in the n-best, include it\n        if version_2_with_negative:\n            if \"\" not in seen_predictions:\n                nbest.append(_NbestPrediction(text=\"\", start_logit=null_start_logit, end_logit=null_end_logit))\n\n            # In very rare edge cases we could only have single null prediction.\n            # So we just create a nonce prediction in this case to avoid failure.\n            if len(nbest) == 1:\n                nbest.insert(0, _NbestPrediction(text=\"empty\", start_logit=0.0, end_logit=0.0))\n\n        # In very rare edge cases we could have no valid predictions. So we\n        # just create a nonce prediction in this case to avoid failure.\n        if not nbest:\n            nbest.append(_NbestPrediction(text=\"empty\", start_logit=0.0, end_logit=0.0))\n\n        if len(nbest) < 1:\n            raise ValueError(\"No valid predictions\")\n\n        total_scores = []\n        best_non_null_entry = None\n        for entry in nbest:\n            total_scores.append(entry.start_logit + entry.end_logit)\n            if not best_non_null_entry:\n                if entry.text:\n                    best_non_null_entry = entry\n\n        probs = _compute_softmax(total_scores)\n\n        nbest_json = []\n        for i, entry in enumerate(nbest):\n            output = collections.OrderedDict()\n            output[\"text\"] = entry.text\n            output[\"probability\"] = probs[i]\n            output[\"start_logit\"] = entry.start_logit\n            output[\"end_logit\"] = entry.end_logit","sourceCodeStart":521,"sourceCodeEnd":557,"githubUrl":"https://github.com/huggingface/transformers/blob/a597f974857b3d92939971296bc0deb93d33d780/src/transformers/data/metrics/squad_metrics.py#L521-L557","documentation":"Raised by squad_metrics.compute_predictions_logits when the nbest list is empty after the nonce-prediction fallbacks. Normally the code inserts an 'empty' prediction when nbest is empty, making this branch nearly unreachable in practice; hitting it means every candidate start/end pair failed to map back to valid text (e.g. get_final_text produced nothing usable for any candidate) and even the fallbacks did not append.","triggerScenarios":"Calling compute_predictions_logits with all_examples/features/results where, for some example, every predicted span fails text mapping (misaligned offsets between tokenizer features and original context, or features/results indexed by the wrong example).","commonSituations":"Mixing features from one preprocessing run with results from another (different max_seq_length or doc_stride); tokenizers whose offset mapping does not match the original examples; corrupted results files.","solutions":["Regenerate features and predictions with the same tokenizer, max_seq_length, and doc_stride so example/feature/result indices align.","Check that SquadResult objects correspond feature-for-feature to the features passed in (same unique_id ordering).","Inspect the failing qas_id: log its features' token_to_orig_map to confirm offsets are populated (requires a fast tokenizer during preprocessing)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"qas_ids = {ex.qas_id for ex in all_examples}\nresult_ids = {r.unique_id for r in all_results}\nfeature_ids = {f.unique_id for f in all_features}\nassert result_ids <= feature_ids, 'results reference features that were not provided'","typeGuard":null,"tryCatchPattern":"try:\n    predictions = compute_predictions_logits(examples, features, results, ...)\nexcept ValueError as e:\n    if 'No valid predictions' in str(e):\n        logger.error('feature/result misalignment for at least one example; regenerate both with same tokenizer/settings')\n    raise","preventionTips":["Always generate features and run inference with the same tokenizer, max_seq_length, and doc_stride.","Keep unique_id mapping intact: pass the exact features list used for prediction back into the metric function.","Use a fast tokenizer during preprocessing so token_to_orig_map offsets exist for text recovery."],"tags":["squad","metrics","question-answering","evaluation"],"backgroundTag":null,"analyzedSha":"a597f974857b3d92939971296bc0deb93d33d780","analyzedAt":"2026-08-14T18:24:08.354Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}