Implementation:Pyro ppl Pyro RSA Generics
Appearance
| Property | Value |
|---|---|
| Implementation Type | Pattern Doc |
| Source File | examples/rsa/generics.py
|
| Module | examples.rsa |
| Pyro Features | pyro.sample, pyro.factor, Search, HashingMarginal, memoize, poutine.scale, nested inference
|
| References | forestdb.org/models/generics.html, Tessler & Goodman (2019) |
Overview
This file implements an RSA (Rational Speech Act) model for interpreting generic statements such as "Mosquitoes carry malaria" or "Birds lay eggs". It shows how Pyro can model pragmatic language understanding through nested probabilistic inference.
The model has four levels of reasoning:
- Structured prior: A discretized Beta distribution over prevalence rates, gated by a Bernoulli variable for whether the property is present at all.
- Literal listener (L0): Interprets an utterance literally, conditioning on it being true given a threshold.
- Pragmatic speaker (S1): Chooses utterances to communicate a state to L0, using an optimality parameter.
- Pragmatic listener (L1): Interprets utterances by reasoning about S1, jointly inferring both state and threshold.
- Second-level speaker (S2): Decides whether a generic statement is appropriate for a given prevalence.
The example shows truth judgments (whether a generic like "Mosquitoes carry malaria" is judged true) and listener interpretations (what prevalence is inferred from hearing the generic).
Code Reference
@Marginal
def listener1(utterance, prior):
state = pyro.sample("state", prior)
threshold = threshold_prior()
S1 = speaker1(state, threshold, prior)
pyro.sample("S1_score", S1, obs=utterance)
return state
@Marginal
def speaker2(prevalence, prior):
utterance = utterance_prior()
wL1 = listener1(utterance, prior)
pyro.sample("wL1_score", wL1, obs=prevalence)
return utterance
# Different property priors
hasWingsERP = structured_prior_model(Params(theta=0.5, gamma=0.99, delta=10.0))
carriesMalariaERP = structured_prior_model(Params(theta=0.1, gamma=0.01, delta=2.0))
I/O Contract
| Parameter | Type | Description |
|---|---|---|
Params.theta |
float |
Probability that the property is present at all |
Params.gamma |
float |
Mean of the Beta distribution (when property is present) |
Params.delta |
float |
Concentration of the Beta distribution |
-n / --num-samples |
int |
Number of samples (default: 10) |
Output:
- Listener posterior distributions over prevalence for different properties (wings, malaria, eggs, female)
- Speaker truth judgments (probability of asserting the generic) for different prevalences
Usage Examples
# Run the generics model
# python generics.py -n 10
# Inspect listener interpretation of "Mosquitoes carry malaria"
malariaPosterior = listener1("generic is true", carriesMalariaERP)
for elt in malariaPosterior.enumerate_support():
print(elt, malariaPosterior.log_prob(elt).exp().item())
Related Pages
- Pyro_ppl_Pyro_SearchInference - Search inference utilities used by this model
- Pyro_ppl_Pyro_RSA_Hyperbole - RSA model for hyperbolic language
- Pyro_ppl_Pyro_RSA_Schelling - Schelling coordination game
- Pyro_ppl_Pyro_RSA_SemanticParsing - RSA with compositional semantics
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment