Fairness metrics for LLM text generation and understanding
Fairness metrics often focus on comparing model performance or outputs across different demographic groups.
Here are some examples:
- Demographic parity difference for text classification: This metric measures the difference in positive prediction rates between the most and least favored groups:
from sklearn.metrics import confusion_matrix import numpy as np def demographic_parity_difference( y_true, y_pred, protected_attribute ): groups = np.unique(protected_attribute) dps = [] for group in groups: mask = protected_attribute == group cm = confusion_matrix(y_true[mask], y_pred[mask]) dp = (cm[1, 0] + cm[1, 1]) / cm.sum() dps.append(dp...