How Author Diversity Affects Post Scoring in X-Algorithm: Technical Implementation Guide
Author diversity reduces "author dominance" in the home timeline by applying an exponential decay multiplier to posts from the same author, ensuring the first post retains nearly full score while subsequent posts receive progressively lower rankings based on configurable decay and floor parameters.
The X-Algorithm (xai-org/x-algorithm) employs a dedicated author-diversity stage within its home-timeline ranking pipeline to prevent any single author from overwhelming a user's feed. This mechanism adjusts raw post scores based on how many times an author has already appeared in the current slate, directly influencing which content surfaces in the home mixer.
Enabling the Author Diversity Feature
Whether the diversity adjustment runs at all is controlled by the boolean flag EnableAuthorDiversity defined in home-mixer/params/param.rs (lines 29‑33). When this flag is set to true, the RankingScorer::score method invokes the diversity logic during the scoring pipeline.
If disabled, the scorer bypasses all author-counting and multiplier calculations, allowing posts to rank purely on their base engagement signals without frequency-based penalties.
Computing Per-Author Frequency Counts
The diversity logic first orders candidates by their pre-diversity scores (weighted_scores). The function author_pool_counts in home-mixer/scorers/ranking_scorer.rs (lines 29‑44) then walks this ordered list, tracking how many times each author_id has already been encountered.
For each candidate, the function writes the current count for that author into a parallel vector (counts). This count represents k—the number of previous posts from the same author in the slate—and serves as the input for the decay calculation.
The Diversity Multiplier Formula
For each author count k, the function diversity_multiplier (implemented in home-mixer/scorers/ranking_scorer.rs, lines 56‑63 and 625‑632) produces a decay multiplier using the formula:
m = (1 - floor) × decay^k + floor
The variables are sourced from query parameters:
- AuthorDiversityDecay (declared in
home-mixer/params/param.rs, lines 34‑44): Controls the exponential decay rate (e.g.,0.6for faster penalty accumulation). - AuthorDiversityFloor: Sets a hard minimum multiplier to prevent extreme suppression of prolific authors.
A higher decay value applies steeper penalties to subsequent posts, while the floor guarantees that scores never drop below the configured baseline regardless of how many posts the author has in the slate.
Applying the Multiplier to Raw Scores
The function apply_author_diversity in home-mixer/scorers/ranking_scorer.rs (lines 66‑78) multiplies each candidate's raw pre-diversity score by its calculated diversity multiplier. The resulting diversity-adjusted scores replace the original values before any further offsets or Out-Of-Network (OON) weighting is applied.
This placement in the pipeline ensures that author diversity acts as a foundational ranking factor, shaping the slate before network-based adjustments modify the distribution.
Impact on Home Timeline Ranking
Because the multiplier decays exponentially with the author count k, the ranking effects follow a predictable pattern:
- First post: Receives nearly the full base score (multiplier approaches
1.0). - Second post: Receives a reduced score based on
(1 - floor) × decay + floor. - Subsequent posts: Face increasingly severe penalties, asymptotically approaching the floor value.
This design deliberately spreads visibility across multiple authors while still allowing high-quality posts to surface if they earn sufficiently strong base scores to overcome the decay penalty.
Code Example: Configuring Author Diversity
use home_mixer::scorers::ranking_scorer::RankingScorer;
use home_mixer::params::param::{EnableAuthorDiversity, AuthorDiversityDecay, AuthorDiversityFloor};
// Initialize query with author diversity enabled
let mut query = ScoredPostsQuery::default();
query.params.set(EnableAuthorDiversity, true);
query.params.set(AuthorDiversityDecay, 0.6); // Aggressive decay
query.params.set(AuthorDiversityFloor, 0.2); // 20% minimum score retention
// Assume candidates each contain an author_id field
let candidates: Vec<PostCandidate> = fetch_candidates();
// Execute scoring pipeline with diversity adjustment
let scorer = RankingScorer::default();
let results = scorer.score(&query, &candidates).await;
// Results contain diversity-adjusted scores
for post in results {
println!("Author {}: final score = {}", post.author_id, post.score);
}
This implementation mirrors the production path in home-mixer/scorers/ranking_scorer.rs, triggering the author_pool_counts and apply_author_diversity functions when EnableAuthorDiversity is active.
Summary
- EnableAuthorDiversity (in
home-mixer/params/param.rs) controls whether the diversity stage runs at all. - author_pool_counts tracks per-author frequencies in the candidate slate.
- The diversity multiplier applies exponential decay using the formula
(1 - floor) × decay^k + floor. - apply_author_diversity (lines 66‑78) applies these multipliers before OON weighting.
- The floor parameter prevents complete suppression of active authors while the decay parameter controls penalty severity.
Frequently Asked Questions
What is the exact mathematical formula used for author diversity scoring?
The X-Algorithm uses the formula m = (1 - floor) × decay^k + floor, where k is the number of previous posts from the same author in the current slate, decay is the AuthorDiversityDecay parameter, and floor is the AuthorDiversityFloor parameter. This produces an exponential decay curve that approaches but never drops below the floor value.
How do I disable author diversity in the home timeline?
Set the EnableAuthorDiversity parameter to false in your query parameters (defined in home-mixer/params/param.rs, lines 29‑33). When disabled, the RankingScorer skips the author_pool_counts and apply_author_diversity functions entirely, ranking posts solely on their base engagement scores without frequency-based penalties.
Where does author diversity processing occur relative to other ranking stages?
According to the source code in home-mixer/scorers/ranking_scorer.rs, author diversity adjustment happens in apply_author_diversity (lines 66‑78) immediately after pre-diversity scoring but before Out-Of-Network (OON) weighting and other offset applications. This ensures diversity shapes the fundamental content mix before network-based adjustments.
What happens if an author has many posts in a single slate?
Each subsequent post from the same author receives an exponentially smaller multiplier based on AuthorDiversityDecay^position. However, the AuthorDiversityFloor parameter guarantees that no post drops below a configured percentage of its original score (e.g., 20%), preventing extreme suppression of prolific authors while still reducing their timeline dominance.
Have a question about this repo?
These articles cover the highlights, but your codebase questions are specific. Give your agent direct access to the source. Share this with your agent to get started:
curl -s "https://instagit.com/install.md" Maintain an open-source project? Get it listed too →