def precision_recall_f1(labels, predictions, label_types, neg_label):
    """
    Compute the precision, recall and F1 score for a set of predictions.

    Parameters
    ----------
    labels : np.array
        The true labels.
    predictions : np.array
        The predicted labels.
    label_types : list[str]
        The list of valid label types.
    neg_label : str
        The label indicating that two entities are not related.

    Returns
    -------
    precision : float
    recall : float
    f1 : float
    """

    tp = 0
    fp = 0
    fn = 0

    for i in range(len(labels)):
        if labels[i] == predictions[i] and labels[i] != label_types.index(neg_label):
            tp += 1
        elif predictions[i] != label_types.index(neg_label) and labels[i] != predictions[i]:
            fp += 1
        elif predictions[i] == label_types.index(neg_label) and labels[i] != predictions[i]:
            fn += 1

    precision = 0 if tp + fp == 0 else tp / (tp + fp)
    recall = 0 if tp + fn == 0 else tp / (tp + fn)
    f1 = 0 if precision + recall == 0 else (2 * precision * recall) / (precision + recall)

    return precision, recall, f1