The Prosocial Ranking Challenge
Project description
The Prosocial Ranking Challenge
The Prosocial Ranking Challenge is designed to inspire, fund, and test the best algorithms to improve well-being, polarization, and factual knowledge for social media users. We will use our browser extension to re-order the feeds of paid U.S. participants on Facebook, Reddit, and X (Twitter) for four months, and measure changes in attitudes and behavior.
How do we identify pro- and anti-social content? That's where you come in! We are soliciting ranking algorithms to test, with $60,000 in prize money to be split between ten finalists (as selected by our panel of experts).
Grafana Metrics Middleware
The middleware included within this package allows submission applications to easily push custom metrics to Grafana Cloud, remember to set your team ID per the keys shared with you.
Usage
Here's a basic example of how to use the Grafana Metrics Middleware in your FastAPI application:
from fastapi import FastAPI
from ranking_challenge.grafana_metrics_middleware import GrafanaMetricsMiddleware
app = FastAPI()
# Initialize the middleware with your team ID
metrics_middleware = GrafanaMetricsMiddleware(app, team_id="your_team_id")
app.add_middleware(metrics_middleware)
@app.get("/")
async def root():
# Log a custom metric
metrics_middleware.add_custom_metric("requests_count", 1, "Number of requests")
return {"message": "Hello World"}
pydantic models for the PRC API schema
You can use these models in your Python code, both to generate valid data, and to parse incoming data.
Using the models ensures that your data has been at least somewhat validated. If the schema changes and your code needs an update, you're more likely to be able to tell right away.
Parsing a request
With FastAPI
If you're using fastapi, you can use the models right in your server:
from ranking_challenge.request import RankingRequest
from ranking_challenge.response import RankingResponse
@app.post("/rank")
def rank(ranking_request: RankingRequest) -> RankingResponse:
...
# You can return a RankingResponse here, or a dict with the correct keys and
# pydantic will figure it out.
If you specify RankingResponse
as your reeturn type, you will get validation of your response for free.
For a complete example, check out ../fastapi_nltk/
Otherwise
If you'd like to parse a request directly, here is how:
from ranking_challenge.request import RankingRequest
loaded_request = RankingRequest.model_validate_json(json_data)
Generating fake data
There is a fake data generator, rcfaker
. If you run it directly it'll print some.
You can also import it like so:
from ranking_challenge.fake import fake_request, fake_response
# 5 fake reddit posts with 2 comments each
request = fake_request(n_posts=5, n_comments=2, platform='reddit')
# corresponding ranker response with 2 added items
request_ids = [r.id for r in request]
response = fake_response(request_ids, n_new_items=2)
For more in-depth examples, check out the tests.
More
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for ranking_challenge-3.2.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | a951346fd22a750d50780d6784ec95d96d78cbcd5caeaf2ea0b5788b0d0a8304 |
|
MD5 | 7e58173ec49be2c90b88b49fc1276c4c |
|
BLAKE2b-256 | b539c30240bac69e5534ad5eee325fff4bb00341e3e3860d31f0bbdc207ce397 |