Skip to main content

No project description provided

Project description

reranking: fairness/personalization for recommendation and search

Python PyTest pre-commit PyPI GitHub

reranking provides algorithms to re-rank the ranked items to any specified item attribute distribution.

This package can be used as a post-processing modular of recommendation systems or search engines.

Inspired by paper Fairness-Aware Ranking in Search & Recommendation Systems with Application to LinkedIn Talent Search.

Concept of usage

Fairness: impose the same distribution to all user

Taking "recommend candidates to recruiters" as the example (this is the case of LinkedIn Recruiter service stressed in the paper), the search engine rankings are re-ranked by the distribution of the protected attributes like gender and demographic parity in consideration of the fair display of the candidates to recruiters.

Personalization: impose the personalized distributions to each user

For example, when we recommend products to users, the product preference distribution for each user (which can be obtained by the purchase log or view log) can be used to re-rank the item rankings by recommendation systems to get a more personalized recommendation.

Installation

$ pip install reranking

Examples

Re-rank

import reranking
item_attribute = ["a1", "a1", "a1", "a2", "a1", "a1", "a1", "a2", "a2", "a1"]
desired_distribution = {"a1": 0.5, "a2": 0.5}
rerank_indices = reranking.rerank(
    item_attribute,  # attributes of the ranked items
    desired_distribution,  # desired item distribution
    max_na=None,  # controls the max number of attribute categories applied
    k_max=None,  # length of output, if None, k_max is the length of `item_attribute`
    algorithm="det_greedy",  # "det_greedy", "det_cons", "det_relaxed", "det_const_sort"
    verbose=False,  # if True, the output is with detailed information
)
print(rerank_indices)

The rerank_indices is [0, 3, 1, 7, 2, 8, 4, 5, 6, 9] which is the list of item indices after re-ranking by the desired distribution. The top items of the re-ranked list will have the same distribution as the desired distribution if there are enough desired items. (item_attribute has the same order with the item list so it contains rank/score information.)

Evaluate

# Evaluate the before&after of the re-ranking result above
item_attribute_reranked = [item_attribute[i] for i in rerank_indices]
before = reranking.ndkl(item_attribute, desired_distribution)
after = reranking.ndkl(item_attribute_reranked, desired_distribution)
print(f"{before:.3f}, {after:.3f}")

The before and after are 0.412 and 0.172 respectively which are the normalized discounted cumulative KL-divergence (NDKL) of the ranked item attribute distribution and the desired distribution. (Lower is better.)

More examples can be found here.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

reranking-0.3.6.tar.gz (11.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

reranking-0.3.6-py3-none-any.whl (17.1 kB view details)

Uploaded Python 3

File details

Details for the file reranking-0.3.6.tar.gz.

File metadata

  • Download URL: reranking-0.3.6.tar.gz
  • Upload date:
  • Size: 11.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.7.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.3

File hashes

Hashes for reranking-0.3.6.tar.gz
Algorithm Hash digest
SHA256 69d285472449b370e8ac3a7229643fe3c05548df1bb9c01eaa155d7365f25812
MD5 a89580725de80692bdf9a4b99f9821d3
BLAKE2b-256 e77c5aa546d8c4b06c7910e10ed50396fd2d4b985099d090414eaabc24293222

See more details on using hashes here.

File details

Details for the file reranking-0.3.6-py3-none-any.whl.

File metadata

  • Download URL: reranking-0.3.6-py3-none-any.whl
  • Upload date:
  • Size: 17.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.2 importlib_metadata/4.7.1 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.8.3

File hashes

Hashes for reranking-0.3.6-py3-none-any.whl
Algorithm Hash digest
SHA256 c3f05ef05f8911a58d230f8cac2fa5a57c3c163847bef477b88931a0653632ba
MD5 237f51fcbec66ca968ae4de29d22c2df
BLAKE2b-256 fc26549f2b1ca76069e0d1494b8c3757dab18caf768b2583b12357c63df4608b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page