Abstract_Ranker¶
- class fairdiverse.recommendation.rank_model.Abstract_Ranker.Abstract_Regularizer(config)[source]¶
Bases:
object
- fairness_loss(**kwargs)[source]¶
Computes the fairness loss as the variance of the input scores.
This function calculates the fairness loss by computing the variance of the provided scores. The loss aims to capture the variation in the scores, which can be used as a measure of fairness in the model’s predictions.
- Param:
any.
- Returns:
The fairness loss.
- class fairdiverse.recommendation.rank_model.Abstract_Ranker.Abstract_Reweigher(config)[source]¶
Bases:
object
- reweight(**kwargs)[source]¶
Recalculates the batch weights based on the loss and the group adjacency matrix.
This function computes new weights for each group in the batch based on the loss associated with each item and the group adjacency matrix. The batch weights are recalculated by considering the loss for each group and adjusting them based on predefined parameters in the configuration (e.g., beta, alpha, eta).
- Parameters:
Any
- Returns:
A normalized vector of batch weights for each group in the batch.
- class fairdiverse.recommendation.rank_model.Abstract_Ranker.Abstract_Sampler(config, user2pos)[source]¶
Bases:
object
- sample(**kwargs)[source]¶
Samples negative items for each user in the interaction, based on group fairness and model predictions.
This function selects negative items for users in the interaction based on two factors: group fairness (weighted by group_fair) and the model’s predicted scores (scaled by a temperature parameter). The negative item selection combines these factors and returns the selected items.
- Parameters:
interaction – A dictionary containing interaction data. It should include: - ‘user_ids’: A tensor of user IDs. - ‘item_ids’: A tensor of item IDs.
Model – The model object that provides the method full_scores to get predicted scores for negative items.
- Returns:
A tensor of sampled negative item IDs for each user, and the positive item embeddings.