def _construct_s_and_psx(records: List[TextClassificationRecord]) -> Tuple[np.ndarray, np.ndarray]:
    """Helper function to construct the s array and psx matrix.

    Args:
        records: List of records.

    Returns:
        A tuple containing the s array and the psx matrix.

    Raises:
        MissingPredictionError: If predictions are missing for certain labels.
    """
    predictions = []
    labels = set()  # use a dict to preserve the order
    for rec in records:
        predictions.append({pred[0]: pred[1] for pred in rec.prediction})
        labels.update(predictions[-1].keys())
    labels_mapping = {label: i for i, label in enumerate(sorted(labels))}

    s = np.empty(len(records), dtype=object) if records[0].multi_label else np.zeros(len(records), dtype=np.short)
    psx = np.zeros((len(records), len(labels)), dtype=float)

    for i, rec, pred in zip(range(len(records)), records, predictions):
        try:
            psx[i] = [pred[label] for label in labels_mapping]
        except KeyError as error:
            raise MissingPredictionError(f"It seems a prediction for {error} is missing in the following record: {rec}")

        try:
            s[i] = (
                [labels_mapping[label] for label in rec.annotation]
                if rec.multi_label
                else labels_mapping[rec.annotation]
            )
        except KeyError as error:
            raise MissingPredictionError(f"It seems predictions are missing for the label {error}!")

    return s, psx
Helper function to construct the s array and psx matrix.

    Args:
        records: List of records.

    Returns:
        A tuple containing the s array and the psx matrix.

    Raises:
        MissingPredictionError: If predictions are missing for certain labels.
    
argilla-v1/src/argilla_v1/labeling/text_classification/label_errors.py