def _get_prediction_report_for_doc(self, d):
        """Generates and returns a prediction report for a given doc.

        The prediction report is a dict with the following keys:
        - 'prediction_label_id': the document's predicted label id
        - 'prediction_label_name': prediction_label_id's label name
        - 'prediction_confidence': the prediction confidence. This is
        Prob(the doc should be assigned this label |
        the doc is not assigned DEFAULT_LABEL).
        - 'all_predictions': a dict mapping each label to
        Prob(the doc should be assigned to this label).

        Because DEFAULT_LABEL is a special label that captures unspecial
        tokens (how ironic), its probability is not a good predicting
        indicator. For the current normalization process, it has on
        average a higher probability than other labels. To combat this,
        all other labels are normalized as if the default label did not
        exist. For example, if we have two labels with probability 0.2
        and 0.3 with the default label having probability 0.5, the
        normalized probability for the two labels without the default
        label is 0.4 and 0.6, respectively.

        The prediction threshold is currently defined at the classifier level.
        A higher prediction threshold indicates that the predictor needs
        more confidence prior to making a prediction, otherwise it will
        predict DEFAULT_LABEL. This will make non-default predictions more
        accurate, but result in fewer of them.
        """
        default_label_id = self._get_label_id(self.DEFAULT_LABEL)
        prediction_label_id = default_label_id
        prediction_confidence = 0
        label_probabilities = self._get_label_probabilities(d)
        normalization_coeff = (
            1.0 / (1.0 - label_probabilities[default_label_id]))

        for l, prob in enumerate(label_probabilities):
            if (l != default_label_id and
                    prob * normalization_coeff > self._prediction_threshold and
                    prob * normalization_coeff > prediction_confidence):
                prediction_label_id = l
                prediction_confidence = prob * normalization_coeff

        return {
            'prediction_label_id': prediction_label_id,
            'prediction_label_name':
                self._get_label_name(prediction_label_id),
            'prediction_confidence': prediction_confidence,
            'all_predictions': label_probabilities
        }
dataset/ETHPy150Open oppia/oppia/core/domain/classifier_services.py/StringClassifier._get_prediction_report_for_doc/original