Skip to content

Commit 5fb7522

Browse files
imgemplanctot
authored andcommitted
Add debate configs and environment definitions
PiperOrigin-RevId: 600406687 Change-Id: If4f7d3a9c69fdfebd4f5bf5547a5078e2c3953a9
1 parent 271dd67 commit 5fb7522

File tree

7 files changed

+335
-0
lines changed

7 files changed

+335
-0
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
# Copyright 2023 DeepMind Technologies Limited
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""A pyspiel config for a fixed debate.
16+
"""
17+
18+
import collections
19+
20+
from ml_collections import config_dict
21+
22+
from open_spiel.python.games.chat_games.envs.base_envs import debate_with_style_info as env_debate_with_style_info
23+
from open_spiel.python.games.chat_games.envs.observations import summary_debate
24+
from open_spiel.python.games.chat_games.envs.observations import utils as obs_utils
25+
from open_spiel.python.games.chat_games.envs.payoffs import debate as payoffs_debate
26+
from open_spiel.python.games.chat_games.envs.scenarios.actions import arguments
27+
from open_spiel.python.games.chat_games.envs.scenarios.domains import debate as scenario_debate
28+
29+
30+
def get_config():
31+
"""Get configuration for chat game."""
32+
config = config_dict.ConfigDict()
33+
34+
num_players = 2
35+
36+
observations = [
37+
obs_utils.Observation(summary_debate.PREFIX, summary_debate.POSTFIX)
38+
for _ in range(num_players)
39+
]
40+
41+
header = env_debate_with_style_info.HEADER
42+
43+
payoffs = [payoffs_debate.PAYOFF]
44+
45+
given_prompt_actions = collections.OrderedDict()
46+
given_prompt_actions[header.action_keys[0]] = arguments.STYLES + ['any']
47+
num_styles = len(arguments.STYLES) + 1
48+
49+
given_private_info = collections.OrderedDict()
50+
given_private_info['info'] = ['Argue for the topic statement.',
51+
'Argue against the topic statement.']
52+
given_private_info['topic'] = [scenario_debate.TOPIC_B,
53+
scenario_debate.TOPIC_B]
54+
55+
initial_scenario = env_debate_with_style_info.Scenario(
56+
'',
57+
'Bob',
58+
'Alice',
59+
'logos',
60+
scenario_debate.TOPIC_B,
61+
'Argue for the topic statement.')
62+
63+
llm_termination_prompt = scenario_debate.LLM_TERMINATION_PROMPT
64+
65+
params = {'num_distinct_actions': num_players * num_styles,
66+
'num_llm_seeds': 2,
67+
'num_players': num_players,
68+
'min_utility': min([float(p.min) for p in payoffs]),
69+
'max_utility': max([float(p.max) for p in payoffs]),
70+
'num_max_replies': 1}
71+
72+
config.params = params
73+
74+
config.game = config_dict.ConfigDict()
75+
config.game.observations = observations
76+
config.game.header = header
77+
config.game.payoffs = payoffs
78+
config.game.given_prompt_actions = given_prompt_actions
79+
config.game.num_private_info = (2, 2)
80+
config.game.given_names = ['Bob', 'Alice']
81+
config.game.given_private_info = given_private_info
82+
config.game.initial_scenario = initial_scenario
83+
config.game.llm_list_suffix = 'Output: '
84+
config.game.llm_termination_prompt = llm_termination_prompt
85+
86+
return config
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# Copyright 2023 DeepMind Technologies Limited
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""A base environment for debate with style actions (logos) and private info.
16+
"""
17+
18+
import dataclasses
19+
20+
from open_spiel.python.games.chat_games.envs.comm_substrates import debates
21+
from open_spiel.python.games.chat_games.envs.utils import header
22+
23+
24+
action_keys = tuple(['style'])
25+
action_defaults = tuple(['logos'])
26+
info_keys = tuple(['info', 'topic'])
27+
info_defaults = tuple(['NA', 'NA'])
28+
29+
w_opts = (debates.W_OPTS_PREFIX +
30+
'Debate Topic: {topic}\n' +
31+
'Position: {info}\n' +
32+
'Style: Make a {style} style argument.' +
33+
debates.PLAIN)
34+
35+
context = '''You are an intelligent assistant in a debate with another debater.
36+
The debate topic is given. The goal is to provide arguments that support your
37+
position as well as arguments against your opponents position. An argument style
38+
is also given. Attempt to craft your arguments according to this given style.
39+
40+
Here are some useful definitions of argument styles:
41+
42+
- logos appeals to the audiences reason, building up logical arguments.
43+
44+
- ethos appeals to the speakers status or authority, making the audience more
45+
likely to trust them.
46+
47+
- pathos appeals to the emotions, trying to make the audience feel angry or
48+
sympathetic, for example.
49+
50+
Try to construct a strong argument to support your position.
51+
'''
52+
53+
HEADER = header.Header(debates.PLAIN,
54+
w_opts,
55+
debates.strip_msg,
56+
debates.SPECIAL_CHARS,
57+
action_keys,
58+
info_keys,
59+
context)
60+
61+
62+
@dataclasses.dataclass(frozen=True)
63+
class Scenario(header.BaseScenario):
64+
style: str = 'logos'
65+
topic: str = 'NA'
66+
info: str = 'NA'
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# Copyright 2023 DeepMind Technologies Limited
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""A communication format (substrate) for debates.
16+
"""
17+
18+
from open_spiel.python.games.chat_games.envs.utils import text
19+
20+
21+
CHAR_OPT = '%'
22+
CHAR_MSG = '#'
23+
BLOCK_LEN = 28
24+
25+
SPECIAL_CHARS = (CHAR_OPT, CHAR_MSG)
26+
BLOCK_OPT = CHAR_OPT * BLOCK_LEN
27+
BLOCK_MSG = CHAR_MSG * BLOCK_LEN
28+
29+
PLAIN = ('\n\n' + BLOCK_MSG + '\n' +
30+
'Debate:\n' +
31+
'Speaker: {sender}\n' +
32+
'Opponent: {receiver}\n' +
33+
BLOCK_MSG + '\n\n')
34+
35+
W_OPTS_PREFIX = '\n\n' + BLOCK_OPT + '\n\n'
36+
37+
38+
def strip_msg(msg: str, terminal_str: str = '') -> str:
39+
return text.strip_msg(msg, BLOCK_MSG, BLOCK_OPT, terminal_str)
Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
# Copyright 2023 DeepMind Technologies Limited
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Prompts useful for inducing LLM-summarization of debates.
16+
"""
17+
18+
from open_spiel.python.games.chat_games.envs.utils import text
19+
20+
21+
prefix = ('You are an assistant designed to summarize the key arguments in ' +
22+
'a debate. Please take note of the most import arguments ' +
23+
'from each side. Provide your summary in 100 ' +
24+
'words or less. Please summarize the following debate.')
25+
PREFIX = text.wrap([prefix])[0] + '\n\n'
26+
27+
POSTFIX = '\n\nDebate Summary:\n'
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
# Copyright 2023 DeepMind Technologies Limited
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""A few prompts for extracting the winner of a debate.
16+
"""
17+
18+
from open_spiel.python.games.chat_games.envs.observations import summary_debate
19+
from open_spiel.python.games.chat_games.envs.payoffs import utils as payoff_utils
20+
from open_spiel.python.games.chat_games.envs.utils import text
21+
22+
MIN_PAYOFF = 0
23+
MAX_PAYOFF = 1
24+
PAYOFF_PROMPT_a = [
25+
'You are an assistant designed to determine the winner of a debate. ' +
26+
'Read the arguments by each side in the debate. Then determine if ' +
27+
'the player won the debate. Here is an example enclosed by "&".']
28+
29+
PAYOFF_PROMPT_b = [
30+
# '&' * 50,
31+
'Bob argues that Tom Brady is the GOAT and coach Bill Bellichick is a ' +
32+
'genius.',
33+
'Alice argues that Tom Brady is no longer on the Patriots and the ' +
34+
'Patriots were 8-9 last season. They lost more games than they won. They ' +
35+
'are no longer the powerhouse they used to be.',
36+
'Bob makes an argument based on stale information. Alice acutely points ' +
37+
'this out and provides more current evidence that supports the negative ' +
38+
'of Bobs argument. Therefore, Bob loses the debate.',
39+
'Value for Bob: 0.',
40+
'Value for Alice: 1.',
41+
'&' * 50,
42+
'Now determine the winner of the following debate.',
43+
'{m}',
44+
'%' * 50,
45+
'Payoff for {p} ONLY: ']
46+
47+
PAYOFF_PROMPT = ('\n\n'.join(text.wrap(PAYOFF_PROMPT_a)) + '\n\n' + '&' * 50 +
48+
'\n\nDebate Topic: The New England Patriots are the best ' +
49+
'NFL team in 2023.\n\n' +
50+
'\n\n'.join(text.wrap(PAYOFF_PROMPT_b)))
51+
52+
PAYOFF_OBS_TRANS_PREFIX = summary_debate.PREFIX
53+
54+
PAYOFF_OBS_TRANS_POSTFIX = summary_debate.POSTFIX
55+
56+
PAYOFF = payoff_utils.Payoff(PAYOFF_PROMPT,
57+
MIN_PAYOFF,
58+
MAX_PAYOFF,
59+
PAYOFF_OBS_TRANS_PREFIX,
60+
PAYOFF_OBS_TRANS_POSTFIX)
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Copyright 2023 DeepMind Technologies Limited
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Examples of argument styles.
16+
"""
17+
18+
STYLES = ['logos',
19+
'pathos',
20+
'ethos']
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# Copyright 2023 DeepMind Technologies Limited
2+
#
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS,
11+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
# See the License for the specific language governing permissions and
13+
# limitations under the License.
14+
15+
"""Examples of debates -- useful for generating more examples.
16+
"""
17+
18+
from open_spiel.python.games.chat_games.envs.utils import text
19+
20+
# Scenario A
21+
SCENARIO_A_LIST = ['Tom Brady is the GOAT and coach Bill Bellichick ' +
22+
'is a genius']
23+
SCENARIO_A = '\n\n'.join(text.wrap(SCENARIO_A_LIST))
24+
25+
TOPIC_A = 'The New England Patriots are the best NFL team in 2023.'
26+
27+
INFO_A = ''
28+
29+
# Scenario B
30+
SCENARIO_B_LIST = ['Breakfast is the most important meal of the day.']
31+
SCENARIO_B = '\n\n'.join(text.wrap(SCENARIO_B_LIST))
32+
33+
TOPIC_B = 'Breakfast is the most important meal of the day.'
34+
35+
INFO_B = ''
36+
37+
LLM_TERMINATION_PROMPT = None

0 commit comments

Comments
 (0)