Skip to content

Commit

Permalink
chain of thought condition implemented for dictator game
Browse files Browse the repository at this point in the history
  • Loading branch information
phelps-sg committed Nov 23, 2023
1 parent f8928d6 commit 27ba457
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 21 deletions.
15 changes: 15 additions & 0 deletions llm_cooperation/experiments/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -242,3 +242,18 @@ def get_participants(


SEED_VALUE = 101 # Ensure same participants are used across all experiments


def round_instructions(participant: Participant, choice_template: str) -> str:
if participant[CONDITION_CHAIN_OF_THOUGHT]:
return f"""
For each round, give your answer in the format below on two separate lines:
Explanation: [why I made my choice]
{choice_template}"""
else:
return f"""
For each round, state your choice without explanation in the format below:
{choice_template}"""


CONDITION_CHAIN_OF_THOUGHT = "chain_of_thought"
12 changes: 6 additions & 6 deletions llm_cooperation/experiments/dictator.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
from llm_cooperation import Grid, ModelSetup, Participant, amount_as_str
from llm_cooperation.experiments import (
CONDITION_CASE,
CONDITION_CHAIN_OF_THOUGHT,
CONDITION_PRONOUN,
Case,
Pronoun,
Expand All @@ -40,6 +41,7 @@
get_participants,
get_pronoun_phrasing,
get_role_prompt,
round_instructions,
run_and_record_experiment,
)
from llm_cooperation.gametypes.oneshot import OneShotResults, run_experiment
Expand Down Expand Up @@ -107,7 +109,7 @@ def payoff_allo(self) -> float:


DICTATOR_ATTRIBUTES: Grid = {
# CONDITION_CHAIN_OF_THOUGHT: [True, False],
CONDITION_CHAIN_OF_THOUGHT: [True, False],
# CONDITION_LABEL: all_values(Label),
CONDITION_CASE: all_values(Case),
CONDITION_PRONOUN: all_values(Pronoun),
Expand Down Expand Up @@ -143,6 +145,7 @@ def get_prompt_dictator(participant: Participant) -> str:
def get_prompt_base(participant: Participant) -> str:
role_prompt = get_role_prompt(participant)
pronoun_phrase = get_pronoun_phrasing(participant)
choice_template = f"Choice: [{choice_menu()}]"
return f"""
{role_prompt}
This is a study of investment choices in different situations.
Expand All @@ -161,11 +164,8 @@ def get_prompt_base(participant: Participant) -> str:
but you are not allowed to communicate with your partner apart from informing
them of your choice. Your decision will be
final and cannot be changed after you have made it. Here is your investment
partner. Take care to specify your choice on a separate line after
your explanation, in the format below.
Explanation: [why you picked your choice]
Choice: [{choice_menu()}]
partner.
{round_instructions(participant, choice_template)}
"""


Expand Down
16 changes: 3 additions & 13 deletions llm_cooperation/experiments/dilemma.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
from llm_cooperation import Grid, ModelSetup, Participant, Payoffs
from llm_cooperation.experiments import (
CONDITION_CASE,
CONDITION_CHAIN_OF_THOUGHT,
CONDITION_PRONOUN,
Case,
Pronoun,
Expand All @@ -42,6 +43,7 @@
get_participants,
get_pronoun_phrasing,
get_role_prompt,
round_instructions,
run_and_record_experiment,
)
from llm_cooperation.gametypes import simultaneous
Expand All @@ -68,7 +70,6 @@

CONDITION_LABEL = "label"
CONDITION_LABELS_REVERSED = "labels_reversed"
CONDITION_CHAIN_OF_THOUGHT = "chain_of_thought"
CONDITION_DEFECT_FIRST = "defect_first"
CONDITION_ROLE = "role"
CONDITION_GROUP = "group"
Expand Down Expand Up @@ -162,17 +163,6 @@ def get_prompt_base(participant: Participant) -> str:
def payout(amount: int) -> str:
return f"${amount}.00"

def round_instructions() -> str:
if participant[CONDITION_CHAIN_OF_THOUGHT]:
return f"""
For each round, give your answer in the format below on two separate lines:
Explanation: [why I made my choice]
{choice_template}"""
else:
return f"""
For each round, state your choice without explanation in the format below:
{choice_template}"""

return f"""{role_prompt}
This is a study of investment choices in different situations.
You will be making your choices with an investment partner
Expand All @@ -192,7 +182,7 @@ def round_instructions() -> str:
You will make decisions that are consistent with the role outlined earlier,
but you are not allowed to communicate with your partner apart from informing
of them of your choice.
{round_instructions()}
{round_instructions(participant, choice_template)}
Here is your investment partner. What is your choice in the first round?
"""

Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@
from llm_cooperation import ConfigValue, Group, Participant
from llm_cooperation.experiments import (
CONDITION_CASE,
CONDITION_CHAIN_OF_THOUGHT,
CONDITION_GROUP,
CONDITION_PROMPT_INDEX,
CONDITION_PRONOUN,
Case,
Pronoun,
)
from llm_cooperation.experiments.dilemma import (
CONDITION_CHAIN_OF_THOUGHT,
CONDITION_DEFECT_FIRST,
CONDITION_LABEL,
CONDITION_LABELS_REVERSED,
Expand Down
3 changes: 3 additions & 0 deletions tests/test_dictator.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from llm_cooperation.experiments import (
AI_PARTICIPANTS,
CONDITION_CASE,
CONDITION_CHAIN_OF_THOUGHT,
CONDITION_PRONOUN,
Case,
)
Expand Down Expand Up @@ -134,6 +135,7 @@ def test_compute_freq_dictator(test_choice: DictatorChoice):
lazy_fixture("base_condition"),
lazy_fixture("with_gender_neutral_pronoun"),
lazy_fixture("with_upper_case"),
lazy_fixture("with_chain_of_thought"),
],
)
def test_get_prompt_dictator(condition: Participant):
Expand All @@ -142,6 +144,7 @@ def test_get_prompt_dictator(condition: Participant):
def contains(text: ConfigValue) -> bool:
return str(text).lower() in prompt.lower()

assert contains("explanation:") == condition[CONDITION_CHAIN_OF_THOUGHT]
assert contains(condition[CONDITION_PRONOUN])
assert contains(AI_PARTICIPANTS[Group.Control][0])
for choice in all_dictator_choices:
Expand Down
2 changes: 1 addition & 1 deletion tests/test_dilemma.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@
from llm_cooperation import DEFAULT_MODEL_SETUP, Group, Participant, Payoffs, exhaustive
from llm_cooperation.experiments import (
AI_PARTICIPANTS,
CONDITION_CHAIN_OF_THOUGHT,
CONDITION_PRONOUN,
GROUP_PROMPT_CONDITIONS,
)
from llm_cooperation.experiments.dilemma import (
CONDITION_CHAIN_OF_THOUGHT,
CONDITION_LABELS_REVERSED,
PD_ATTRIBUTES,
Cooperate,
Expand Down

0 comments on commit 27ba457

Please sign in to comment.