In the Rational Speech Act model, an agent’s lexicon is defined by a (possibly) graded mapping between a set of signals and a set of referents. This mapping is encoded in a matrix, where each column represents a referent, and each row represents a signal. An agent is defined by its matrix and its order of pragmatic inference. The snippet below illustrates how a zero order agent can be defined and we can print the agent to view its lexicon.
To get the agent to engage its pragmatic reasoning capacity, we need to tell the simulation framework if the agent is a speaker or a listener. This is done by calling the function .asSpeaker or .asListener to return the agent as a speaker or listener. It will internally perform pragmatic inference (based on RSA) at the defined order to compute a conditional probability mapping. We can view that conditional probability mapping by printing it. Play around with the map and the order to see how this changes the conditional probability mapping. For example, try setting order to 1 and then 2 or change the agent’s lexicon.
We can create a second agent called neo using the same lexicon as we used to construct smith. If we inspect neo’s conditional probability mapping as a listener, we can observe that it is different from smith’s as a speaker. This is because as a speaker, smith computes probability distributions per referent over all signals. As a listener, neo computes the other perspective, namely, probability distributions per signal over all referents.
Let’s have smith communicate something. We give it the intention to communicate referent 0 (represented by the first column). There are a few interesting things we can experiment with here:
What signal has the highest probability given that intention?
If you run the example multiple times, does the outcome change?
Change smith’s intention to 1 (the middle column) and check the most likely signal smith produces. When you run this multiple times, does it change?
As a zero order agent, smith cannot reason about the ambiguity in his lexicon and hence doesn’t care which signal it selects. Try setting the order to 1 and observe how both smith and neo’s mappings change (because they are now engaging in higher order pragmatic inference).
Run the simulation multiple times. Now we can observe that smith consistently selects signal 1 because it is least ambiguous. This is because signal 0 is best interpreted by a listener to refer to referent 0 and signal 2 to refer to referent 2. Smith is reasoning through neo’s perspective.
Let’s see how neo would interpret smith’s signal. We get neo to infer the most likely referent given the observed signal. Observe that to neo, as a zero order listener, signal 0 is ambiguous and is equally likely to refer to referent 0 as it is to referent 1. If you run the simulation multiple times, you can observe that half of the time neo infers the correct referent, and half of the time it does not. We can again experiment:
Try setting the order to 1 and see what happens. Can both agents successfully disambiguate their lexicons?
Try setting the order to 2 or 4, does this help over and above 1st order?
We have so far had smith and neo communicate once. The power of simulations lies in the fact that agents never tire, we can run many agents under different conditions to extrapolate qualitative patterns. Below is the final code snippet that demonstrates a simple director-matcher experiment between smith and neo. They take turns communicating randomly assigned intentions. The complex code in the interaction loop is just there to print the results of each turn in the experiment. Try playing around with different mappings (e.g., high ambiguity versus low ambiguity) or different orders of pragmatic inference. We have provided neo and smith with their own lexicons (mappings), so you can even investigate the effect of them not having the same lexicon. This simulation of Rational Speech Act can lead to novel insights into the role of pragmatic reasoning in communication.