Skip to main content

Local acceptance-manifold scoring for implicit RLHF preference pair generation

Project description

manifold-scorer

Local acceptance-manifold scoring for implicit RLHF/DPO preference pair generation.

Implementation of the local density scorer from Gerard & Volkova (2026), "Density-Guided Response Optimization."

The idea: responses a community accepts cluster in coherent, high-density regions of embedding space. Local density — conditioned on nearby conversation histories — reliably recovers human preference ordering, and can substitute for explicit preference annotations when building DPO training pairs.


Install

pip install manifold-scorer

# if you want the built-in Embedder helper too:
pip install "manifold-scorer[embed]"

Usage

1. Fit on accepted community responses

from manifold import ManifoldScorer

# hist_embs: embeddings of conversation histories (N, d)
# resp_embs: embeddings of accepted responses (N, d)
# — these are your unlabeled community posts/replies

scorer = ManifoldScorer(k=150)
scorer.fit(hist_embs, resp_embs)

2. Generate DPO pairs from candidates

# For each query you have multiple candidate responses
# cand_embs: shape (N_queries, n_candidates, d)

pairs = scorer.make_pairs(query_hist_embs, cand_embs)

# pairs["chosen_emb"]   — shape (N, d), highest-density candidate
# pairs["rejected_emb"] — shape (N, d), lowest-density candidate
# pairs["margin"]       — score gap; filter on this for data quality

# Feed directly to your DPO trainer:
high_quality = pairs["margin"] > threshold
dpo_chosen   = pairs["chosen_emb"][high_quality]
dpo_rejected = pairs["rejected_emb"][high_quality]

3. Score a single candidate

score = scorer.score(history_emb, candidate_emb)
# log-density; higher = more aligned with community norms

4. Rank candidates for a query

ranked_indices = scorer.rank_candidates(history_emb, candidates_emb)
best = candidates_emb[ranked_indices[0]]

5. Save / load

scorer.save("my_community_scorer.npz")
scorer2 = ManifoldScorer.load("my_community_scorer.npz")

Embedding your text

The scorer is embedding-agnostic — pass any float32 arrays. For a quick start with sentence-transformers:

from sentence_transformers import SentenceTransformer

model = SentenceTransformer("sentence-transformers/all-mpnet-base-v2")
hist_embs = model.encode(histories, normalize_embeddings=True)
resp_embs = model.encode(responses, normalize_embeddings=True)

Citation

@article{gerard2026dgro,
  title   = {Density-Guided Response Optimization: Community-Grounded Alignment via Implicit Acceptance Signals},
  author  = {Gerard, Patrick and Volkova, Svitlana},
  journal = {ACM FAccT},
  year    = {2026},
}

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

manifold_scorer-0.1.1.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

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

manifold_scorer-0.1.1-py3-none-any.whl (7.3 kB view details)

Uploaded Python 3

File details

Details for the file manifold_scorer-0.1.1.tar.gz.

File metadata

  • Download URL: manifold_scorer-0.1.1.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.13

File hashes

Hashes for manifold_scorer-0.1.1.tar.gz
Algorithm Hash digest
SHA256 0ec8a39544b686b1934c1eed034f9adbe913790f0d3a905c6961dff10eb75e9f
MD5 7bb51d1378fb7c195739992f2f10d40f
BLAKE2b-256 755d349843dab8cd59d0f379536af05800ae376eb745f95fa2eba820354e4915

See more details on using hashes here.

File details

Details for the file manifold_scorer-0.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for manifold_scorer-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a8fac023dff047e527cab8ff64c012b358c54f862353ebf5b279ea12c14d46dd
MD5 b085378fa6ab7006a23d72f2e9a2846c
BLAKE2b-256 ee0c06917e56fe4c76f7d194526aa3eae8a6d8fc7399498203f4cfe53d8e3a2f

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