Jump to content

Connect SuperML | Leeroopedia MCP: Equip your AI agents with best practices, code verification, and debugging knowledge. Powered by Leeroo — building Organizational Superintelligence. Contact us at founders@leeroo.com.

Implementation:Pyro ppl Pyro RSA Hyperbole

From Leeroopedia


Property Value
Implementation Type Pattern Doc
Source File examples/rsa/hyperbole.py
Module examples.rsa
Pyro Features pyro.sample, pyro.factor, Search, HashingMarginal, memoize, poutine.scale, nested inference, QUD (Question Under Discussion) reasoning
Reference Adapted from https://gscontras.github.io/probLang/chapters/03-nonliteral.html

Overview

This file implements an RSA model for interpreting hyperbole, explaining how listeners can understand non-literal numerical utterances like "It cost $10,000" (when it actually cost much less). The model captures the pragmatic reasoning that allows hyperbolic interpretation through Question Under Discussion (QUD) uncertainty.

The key innovation is that the pragmatic listener reasons about:

  • The actual price (from a log-linear prior over price ranges)
  • The valence (positive or negative feeling, correlated with price)
  • The QUD being addressed (price, valence, both, approximate price, etc.)

Five QUD functions determine what information is relevant: exact price, valence, price+valence, approximate price, and approximate price+valence. The speaker chooses utterances with costs (precise numbers are costlier than round numbers), explaining why round numbers are used for approximate communication.

Code Reference

State = collections.namedtuple("State", ["price", "valence"])

qud_fns = {
    "price": lambda state: State(price=state.price, valence=None),
    "valence": lambda state: State(price=None, valence=state.valence),
    "priceValence": lambda state: State(price=state.price, valence=state.valence),
    "approxPrice": lambda state: State(price=approx(state.price), valence=None),
    "approxPriceValence": lambda state: State(price=approx(state.price), valence=state.valence),
}

@Marginal
def pragmatic_listener(utterance):
    price = price_prior()
    valence = valence_prior(price)
    qud = qud_prior()
    state = State(price=price, valence=valence)
    qudValue = qud_fns[qud](state)
    speaker_marginal = speaker(qudValue, qud)
    pyro.sample("speaker", speaker_marginal, obs=utterance)
    return state

I/O Contract

Parameter Type Description
--price int Utterance price value (default: 10000)
-n / --num-samples int Number of samples (default: 10)

Output:

  • Joint distribution over (price, valence) states given the utterance
  • Probabilities for each possible interpretation

State space:

  • Prices: [50, 51, 500, 501, 1000, 1001, 5000, 5001, 10000, 10001]
  • Valence: True (negative feeling) or False

Usage Examples

# Interpret "It cost $10,000"
# python hyperbole.py --price 10000

# The pragmatic listener will assign high probability to
# states where the actual price is much lower than $10,000
# but the valence is negative (expensive feeling)
pragmatic_marginal = pragmatic_listener(10000)
for s in pragmatic_marginal.enumerate_support():
    print(s, pragmatic_marginal.log_prob(s).exp().item())

Related Pages

Page Connections

Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment