Skip to content
项目

pymc-labs/semantic-similarity-rating

在 GitHub 查看

关于

Implementation of the SSR algorithm of the paper "LLMs Reproduce Human Purchase Intent via Semantic Similarity Elicitation of Likert Ratings"

人工智能与机器学习

这些数字如何统计

实测星标增长

24小时
+2
7天
正在收集历史
15天
正在收集历史
1个月
正在收集历史

各周期内的星标净变化,周期相互重叠,并非每日新增。缺失的测量保持空白。星标代表关注度,不代表软件质量。

README.md

原文

Semantic-Similarity Rating (SSR)

A Python package implementing the Semantic-Similarity Rating methodology for converting LLM textual responses to Likert scale probability distributions using semantic similarity against reference statements.

Overview

The SSR methodology addresses the challenge of mapping rich textual responses from Large Language Models (LLMs) to structured Likert scale ratings. Instead of forcing a single numerical rating, SSR preserves the inherent uncertainty and nuance in textual responses by generating probability distributions over all possible Likert scale points.

This package provides a distilled, reusable implementation of the SSR methodology described in the paper "Measuring Synthetic Consumer Purchase Intent Using Semantic-Similarity Ratings" (2025).

Installation

Local Development

To install this package locally for development, run:

pip install -e .

From GitHub Repository

To install this package into your own project from GitHub, run:

pip install git+https://github.com/pymc-labs/semantic-similarity-rating.git

Quick Start

import polars as po
import numpy as np
from semantic_similarity_rating import ResponseRater

# Create example reference sentences dataframe
reference_set_1 = [
    "Strongly disagree",
    "Disagree",
    "Neutral",
    "Agree",
    "Strongly agree",
]
reference_set_2 = [
    "Disagree a lot",
    "Kinda disagree",
    "Don't know",
    "Kinda agree",
    "Agree a lot",
]
df = po.DataFrame(
    {
        "id": ["set1"] * 5 + ["set2"] * 5,
        "int_response": [1, 2, 3, 4, 5] * 2,
        "sentence": reference_set_1 + reference_set_2,
    }
)

# Initialize rater
rater = ResponseRater(df)

# Create some example synthetic consumer responses
llm_responses = ["I totally agree", "Not sure about this", "Completely disagree"]

# Get PMFs for synthetic consumer responses
pmfs = rater.get_response_pmfs(
    reference_set_id="set1",      # Reference set to score against, or "mean"
    llm_responses=llm_responses,  # List of LLM responses to score
    temperature=1.0,              # Temperature for scaling the PMF
    epsilon=0.0,                  # Small regularization parameter to prevent division by zero and add smoothing
)

# Get survey response PMF
survey_pmf = rater.get_survey_response_pmf(pmfs)

print(survey_pmf)

Methodology

The ESR methodology works by:

  1. Defining reference statements for each Likert scale point
  2. Computing cosine similarities between LLM response embeddings and reference statement embeddings
  3. Converting similarities to probability distributions using minimum similarity subtraction and normalization
  4. Optionally applying temperature scaling for distribution control

Core Components

  • ResponseRater: Main class implementing the SSR methodology
  • get_response_pmfs(): Convert LLM response embeddings to PMFs using specified reference set

Citation

Maier, B. F., Aslak, U., Fiaschi, L., Pappas, K., Wiecki, T. (2025). Measuring Synthetic Consumer Purchase Intent Using Embeddings-Similarity Ratings.

License

MIT License

探索相关项目

加载中…