squad¶
-
compute_prediction
(examples, features, predictions, version_2_with_negative: bool = False, n_best_size: int = 20, max_answer_length: int = 30, null_score_diff_threshold: float = 0.0)[source]¶ Post-processes the predictions of a question-answering model to convert them to answers that are substrings of the original contexts. This is the base postprocessing functions for models that only return start and end logits.
- Parameters
examples – The non-preprocessed dataset (see the main script for more information).
features – The processed dataset (see the main script for more information).
predictions (
Tuple[np.ndarray, np.ndarray]
) – The predictions of the model: two arrays containing the start logits and the end logits respectively. Its first dimension must match the number of elements offeatures
.version_2_with_negative (
bool
,optional
, defaults toFalse
) – Whether or not the underlying dataset contains examples with no answers.n_best_size (
int
,optional
, defaults to 20) – The total number of n-best predictions to generate when looking for an answer.max_answer_length (
int
,optional
, defaults to 30) – The maximum length of an answer that can be generated. This is needed because the start and end predictions are not conditioned on one another.null_score_diff_threshold (
float
,optional
, defaults to 0) –The threshold used to select the null answer: if the best answer has a score that is less than the score of the null answer minus this threshold, the null answer is selected for this example (note that the score of the null answer for an example giving several features is the minimum of the scores for the null answer on each feature: all features must be aligned on the fact they
want
to predict a null answer).Only useful when
version_2_with_negative
isTrue
.