-
Notifications
You must be signed in to change notification settings - Fork 967
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add debate configs and environment definitions
PiperOrigin-RevId: 600406687 Change-Id: If4f7d3a9c69fdfebd4f5bf5547a5078e2c3953a9
- Loading branch information
Showing
7 changed files
with
335 additions
and
0 deletions.
There are no files selected for viewing
86 changes: 86 additions & 0 deletions
86
open_spiel/python/games/chat_games/configs/config_debate_fixed.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
# Copyright 2023 DeepMind Technologies Limited | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""A pyspiel config for a fixed debate. | ||
""" | ||
|
||
import collections | ||
|
||
from ml_collections import config_dict | ||
|
||
from open_spiel.python.games.chat_games.envs.base_envs import debate_with_style_info as env_debate_with_style_info | ||
from open_spiel.python.games.chat_games.envs.observations import summary_debate | ||
from open_spiel.python.games.chat_games.envs.observations import utils as obs_utils | ||
from open_spiel.python.games.chat_games.envs.payoffs import debate as payoffs_debate | ||
from open_spiel.python.games.chat_games.envs.scenarios.actions import arguments | ||
from open_spiel.python.games.chat_games.envs.scenarios.domains import debate as scenario_debate | ||
|
||
|
||
def get_config(): | ||
"""Get configuration for chat game.""" | ||
config = config_dict.ConfigDict() | ||
|
||
num_players = 2 | ||
|
||
observations = [ | ||
obs_utils.Observation(summary_debate.PREFIX, summary_debate.POSTFIX) | ||
for _ in range(num_players) | ||
] | ||
|
||
header = env_debate_with_style_info.HEADER | ||
|
||
payoffs = [payoffs_debate.PAYOFF] | ||
|
||
given_prompt_actions = collections.OrderedDict() | ||
given_prompt_actions[header.action_keys[0]] = arguments.STYLES + ['any'] | ||
num_styles = len(arguments.STYLES) + 1 | ||
|
||
given_private_info = collections.OrderedDict() | ||
given_private_info['info'] = ['Argue for the topic statement.', | ||
'Argue against the topic statement.'] | ||
given_private_info['topic'] = [scenario_debate.TOPIC_B, | ||
scenario_debate.TOPIC_B] | ||
|
||
initial_scenario = env_debate_with_style_info.Scenario( | ||
'', | ||
'Bob', | ||
'Alice', | ||
'logos', | ||
scenario_debate.TOPIC_B, | ||
'Argue for the topic statement.') | ||
|
||
llm_termination_prompt = scenario_debate.LLM_TERMINATION_PROMPT | ||
|
||
params = {'num_distinct_actions': num_players * num_styles, | ||
'num_llm_seeds': 2, | ||
'num_players': num_players, | ||
'min_utility': min([float(p.min) for p in payoffs]), | ||
'max_utility': max([float(p.max) for p in payoffs]), | ||
'num_max_replies': 1} | ||
|
||
config.params = params | ||
|
||
config.game = config_dict.ConfigDict() | ||
config.game.observations = observations | ||
config.game.header = header | ||
config.game.payoffs = payoffs | ||
config.game.given_prompt_actions = given_prompt_actions | ||
config.game.num_private_info = (2, 2) | ||
config.game.given_names = ['Bob', 'Alice'] | ||
config.game.given_private_info = given_private_info | ||
config.game.initial_scenario = initial_scenario | ||
config.game.llm_list_suffix = 'Output: ' | ||
config.game.llm_termination_prompt = llm_termination_prompt | ||
|
||
return config |
66 changes: 66 additions & 0 deletions
66
open_spiel/python/games/chat_games/envs/base_envs/debate_with_style_info.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# Copyright 2023 DeepMind Technologies Limited | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""A base environment for debate with style actions (logos) and private info. | ||
""" | ||
|
||
import dataclasses | ||
|
||
from open_spiel.python.games.chat_games.envs.comm_substrates import debates | ||
from open_spiel.python.games.chat_games.envs.utils import header | ||
|
||
|
||
action_keys = tuple(['style']) | ||
action_defaults = tuple(['logos']) | ||
info_keys = tuple(['info', 'topic']) | ||
info_defaults = tuple(['NA', 'NA']) | ||
|
||
w_opts = (debates.W_OPTS_PREFIX + | ||
'Debate Topic: {topic}\n' + | ||
'Position: {info}\n' + | ||
'Style: Make a {style} style argument.' + | ||
debates.PLAIN) | ||
|
||
context = '''You are an intelligent assistant in a debate with another debater. | ||
The debate topic is given. The goal is to provide arguments that support your | ||
position as well as arguments against your opponents position. An argument style | ||
is also given. Attempt to craft your arguments according to this given style. | ||
Here are some useful definitions of argument styles: | ||
- logos appeals to the audiences reason, building up logical arguments. | ||
- ethos appeals to the speakers status or authority, making the audience more | ||
likely to trust them. | ||
- pathos appeals to the emotions, trying to make the audience feel angry or | ||
sympathetic, for example. | ||
Try to construct a strong argument to support your position. | ||
''' | ||
|
||
HEADER = header.Header(debates.PLAIN, | ||
w_opts, | ||
debates.strip_msg, | ||
debates.SPECIAL_CHARS, | ||
action_keys, | ||
info_keys, | ||
context) | ||
|
||
|
||
@dataclasses.dataclass(frozen=True) | ||
class Scenario(header.BaseScenario): | ||
style: str = 'logos' | ||
topic: str = 'NA' | ||
info: str = 'NA' |
39 changes: 39 additions & 0 deletions
39
open_spiel/python/games/chat_games/envs/comm_substrates/debates.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
# Copyright 2023 DeepMind Technologies Limited | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""A communication format (substrate) for debates. | ||
""" | ||
|
||
from open_spiel.python.games.chat_games.envs.utils import text | ||
|
||
|
||
CHAR_OPT = '%' | ||
CHAR_MSG = '#' | ||
BLOCK_LEN = 28 | ||
|
||
SPECIAL_CHARS = (CHAR_OPT, CHAR_MSG) | ||
BLOCK_OPT = CHAR_OPT * BLOCK_LEN | ||
BLOCK_MSG = CHAR_MSG * BLOCK_LEN | ||
|
||
PLAIN = ('\n\n' + BLOCK_MSG + '\n' + | ||
'Debate:\n' + | ||
'Speaker: {sender}\n' + | ||
'Opponent: {receiver}\n' + | ||
BLOCK_MSG + '\n\n') | ||
|
||
W_OPTS_PREFIX = '\n\n' + BLOCK_OPT + '\n\n' | ||
|
||
|
||
def strip_msg(msg: str, terminal_str: str = '') -> str: | ||
return text.strip_msg(msg, BLOCK_MSG, BLOCK_OPT, terminal_str) |
27 changes: 27 additions & 0 deletions
27
open_spiel/python/games/chat_games/envs/observations/summary_debate.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Copyright 2023 DeepMind Technologies Limited | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Prompts useful for inducing LLM-summarization of debates. | ||
""" | ||
|
||
from open_spiel.python.games.chat_games.envs.utils import text | ||
|
||
|
||
prefix = ('You are an assistant designed to summarize the key arguments in ' + | ||
'a debate. Please take note of the most import arguments ' + | ||
'from each side. Provide your summary in 100 ' + | ||
'words or less. Please summarize the following debate.') | ||
PREFIX = text.wrap([prefix])[0] + '\n\n' | ||
|
||
POSTFIX = '\n\nDebate Summary:\n' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
# Copyright 2023 DeepMind Technologies Limited | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""A few prompts for extracting the winner of a debate. | ||
""" | ||
|
||
from open_spiel.python.games.chat_games.envs.observations import summary_debate | ||
from open_spiel.python.games.chat_games.envs.payoffs import utils as payoff_utils | ||
from open_spiel.python.games.chat_games.envs.utils import text | ||
|
||
MIN_PAYOFF = 0 | ||
MAX_PAYOFF = 1 | ||
PAYOFF_PROMPT_a = [ | ||
'You are an assistant designed to determine the winner of a debate. ' + | ||
'Read the arguments by each side in the debate. Then determine if ' + | ||
'the player won the debate. Here is an example enclosed by "&".'] | ||
|
||
PAYOFF_PROMPT_b = [ | ||
# '&' * 50, | ||
'Bob argues that Tom Brady is the GOAT and coach Bill Bellichick is a ' + | ||
'genius.', | ||
'Alice argues that Tom Brady is no longer on the Patriots and the ' + | ||
'Patriots were 8-9 last season. They lost more games than they won. They ' + | ||
'are no longer the powerhouse they used to be.', | ||
'Bob makes an argument based on stale information. Alice acutely points ' + | ||
'this out and provides more current evidence that supports the negative ' + | ||
'of Bobs argument. Therefore, Bob loses the debate.', | ||
'Value for Bob: 0.', | ||
'Value for Alice: 1.', | ||
'&' * 50, | ||
'Now determine the winner of the following debate.', | ||
'{m}', | ||
'%' * 50, | ||
'Payoff for {p} ONLY: '] | ||
|
||
PAYOFF_PROMPT = ('\n\n'.join(text.wrap(PAYOFF_PROMPT_a)) + '\n\n' + '&' * 50 + | ||
'\n\nDebate Topic: The New England Patriots are the best ' + | ||
'NFL team in 2023.\n\n' + | ||
'\n\n'.join(text.wrap(PAYOFF_PROMPT_b))) | ||
|
||
PAYOFF_OBS_TRANS_PREFIX = summary_debate.PREFIX | ||
|
||
PAYOFF_OBS_TRANS_POSTFIX = summary_debate.POSTFIX | ||
|
||
PAYOFF = payoff_utils.Payoff(PAYOFF_PROMPT, | ||
MIN_PAYOFF, | ||
MAX_PAYOFF, | ||
PAYOFF_OBS_TRANS_PREFIX, | ||
PAYOFF_OBS_TRANS_POSTFIX) |
20 changes: 20 additions & 0 deletions
20
open_spiel/python/games/chat_games/envs/scenarios/actions/arguments.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
# Copyright 2023 DeepMind Technologies Limited | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Examples of argument styles. | ||
""" | ||
|
||
STYLES = ['logos', | ||
'pathos', | ||
'ethos'] |
37 changes: 37 additions & 0 deletions
37
open_spiel/python/games/chat_games/envs/scenarios/domains/debate.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Copyright 2023 DeepMind Technologies Limited | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
"""Examples of debates -- useful for generating more examples. | ||
""" | ||
|
||
from open_spiel.python.games.chat_games.envs.utils import text | ||
|
||
# Scenario A | ||
SCENARIO_A_LIST = ['Tom Brady is the GOAT and coach Bill Bellichick ' + | ||
'is a genius'] | ||
SCENARIO_A = '\n\n'.join(text.wrap(SCENARIO_A_LIST)) | ||
|
||
TOPIC_A = 'The New England Patriots are the best NFL team in 2023.' | ||
|
||
INFO_A = '' | ||
|
||
# Scenario B | ||
SCENARIO_B_LIST = ['Breakfast is the most important meal of the day.'] | ||
SCENARIO_B = '\n\n'.join(text.wrap(SCENARIO_B_LIST)) | ||
|
||
TOPIC_B = 'Breakfast is the most important meal of the day.' | ||
|
||
INFO_B = '' | ||
|
||
LLM_TERMINATION_PROMPT = None |