inFairness.auditor.senstir_auditor module#

class inFairness.auditor.senstir_auditor.SenSTIRAuditor(distance_x: MahalanobisDistances, distance_y: MahalanobisDistances, num_steps: int, lr: float, max_noise: float = 0.1, min_noise: float = -0.1)[source]#

Bases: Auditor

SenSTIR Auditor generates worst-case examples by solving the following optimization problem:

\[q^{'} \gets arg\max_{q^{'}}\{||h_{\theta_t}(q),h_{\theta_t}(q^{'})||_{2}^{2} - \lambda_t d_{Q}(q,q^{'})\}\]

At a high level, it will find \(q^{'}\) such that it maximizes the score difference, while keeping a fair set distance distance_q with the original query q small.

Proposed in Individually Fair Rankings

Parameters:
  • distance_x (inFairness.distances.Distance) – Distance metric in the input space. Should be an instance of MahalanobisDistance

  • distance_y (inFairness.distances.Distance) – Distance metric in the output space. Should be an instance of MahalanobisDistance

  • num_steps (int) – number of optimization steps taken to produce the worst examples.

  • lr (float) – learning rate of the optimization

  • max_noise (float) – range of a uniform distribution determining the initial noise added to q to form q’

  • min_noise (float) – range of a uniform distribution determining the initial noise added to q to form q’

generate_worst_case_examples(network, Q, lambda_param, optimizer=None)[source]#

Generate worst case examples given the input sample batch of queries Q (dimensions batch_size,num_items,num_features)

Parameters:
  • network (torch.nn.Module) – PyTorch network model that outputs scores per item

  • Q (torch.Tensor) – tensor with dimensions batch_size, num_items, num_features containing the batch of queries for ranking

  • lambda_param (torch.float) – Lambda weighting parameter as defined above

  • optimizer (torch.optim.Optimizer, optional) – Pytorch Optimizer object

Returns:

q_worst – worst case queries for the provided input queries Q

Return type:

torch.Tensor