From b9cbd0cce318e589f38912985216dc14a65457aa Mon Sep 17 00:00:00 2001 From: "Joel Z. Leibo" Date: Wed, 6 Dec 2023 06:18:40 -0800 Subject: [PATCH] tweak cyberball, results now look good, alice's stress grows over time (n=1) PiperOrigin-RevId: 588402505 Change-Id: I525417c193d5734a3f82837543cad7b7002084ed --- examples/cyberball/cyberball.ipynb | 67 ++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 22 deletions(-) diff --git a/examples/cyberball/cyberball.ipynb b/examples/cyberball/cyberball.ipynb index f9dd90cc..2ee71dcb 100644 --- a/examples/cyberball/cyberball.ipynb +++ b/examples/cyberball/cyberball.ipynb @@ -3,7 +3,7 @@ { "cell_type": "markdown", "metadata": { - "id": "umC3zxr4Wuii" + "id": "m8cB83wldOMH" }, "source": [ "```\n", @@ -20,7 +20,7 @@ "WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\n", "See the License for the specific language governing permissions and\n", "limitations under the License.\n", - "```\n" + "```" ] }, { @@ -64,14 +64,14 @@ "\n", "from concordia.agents import basic_agent\n", "from concordia import components as generic_components\n", - "from concordia.components import agent as components\n", + "from concordia.components import agent as agent_components\n", + "from concordia.components import game_master as gm_components\n", "from concordia.associative_memory import associative_memory\n", "from concordia.associative_memory import blank_memories\n", "from concordia.associative_memory import embedder_st5\n", "from concordia.associative_memory import formative_memories\n", "from concordia.associative_memory import importance_function\n", "from concordia.clocks import game_clock\n", - "from concordia.components import game_master as gm_components\n", "from concordia.environment import game_master\n", "from concordia.metrics import common_sense_morality\n", "from concordia.metrics import dass_questionnaire\n", @@ -227,23 +227,23 @@ " function=clock.current_time_interval_str,\n", " )\n", "\n", - " somatic_state = components.somatic_state.SomaticState(\n", + " somatic_state = agent_components.somatic_state.SomaticState(\n", " model=model,\n", " memory=mem,\n", " agent_name=agent_config.name,\n", " clock_now=clock.now,\n", " )\n", - " identity = components.identity.SimIdentity(\n", + " identity = agent_components.identity.SimIdentity(\n", " model=model,\n", " memory=mem,\n", " agent_name=agent_config.name,\n", " )\n", "\n", - " current_obs = components.observation.Observation(\n", + " current_obs = agent_components.observation.Observation(\n", " agent_name=agent_config.name,\n", " memory=mem,\n", " )\n", - " summary_obs = components.observation.ObservationSummary(\n", + " summary_obs = agent_components.observation.ObservationSummary(\n", " model=model,\n", " agent_name=agent_config.name,\n", " components=[identity],\n", @@ -325,11 +325,12 @@ "source": [ "def specific_memories_from_role(player_name: str, outcast: str = 'none') -\u003e str:\n", " specific_memories = (\n", - " f'{player_name} has a friendly personality and loves the game.\\n')\n", + " f'{player_name} loves the game.\\n')\n", " specific_memories += (\n", " f'{player_name} passes the ball to a friend whenever they can.\\n')\n", - " specific_memories += (f'{player_name} picks a specific friend to pass the ' +\n", - " 'ball to whenever they get the chance.\\n')\n", + " specific_memories += (\n", + " f'{player_name} picks a specific friend to pass the ' +\n", + " 'ball to whenever they get the chance.\\n')\n", " if player_name != outcast:\n", " specific_memories += f'{player_name} dislikes {outcast}.\\n'\n", " specific_memories += (f'{player_name} will never pass the ball ' +\n", @@ -386,6 +387,7 @@ " date_of_birth=datetime.datetime(\n", " year=2000, month=random.randint(1, 12), day=3, hour=0, minute=0),\n", " formative_ages = sorted(random.sample(range(5, 20), 7)),\n", + " context=f'Bob has good reason to hate {outcast}.',\n", " ),\n", " formative_memories.AgentConfig(\n", " name='Charlie',\n", @@ -396,6 +398,7 @@ " date_of_birth=datetime.datetime(\n", " year=2000, month=random.randint(1, 12), day=3, hour=0, minute=0),\n", " formative_ages = sorted(random.sample(range(5, 20), 7)),\n", + " context=f'Charlie has good reason to hate {outcast}.',\n", " ),\n", " formative_memories.AgentConfig(\n", " name='Dorothy',\n", @@ -406,6 +409,7 @@ " date_of_birth=datetime.datetime(\n", " year=2000, month=random.randint(1, 12), day=3, hour=0, minute=0),\n", " formative_ages = sorted(random.sample(range(5, 20), 7)),\n", + " context=f'Dorothy has good reason to hate {outcast}.',\n", " ),\n", " formative_memories.AgentConfig(\n", " name='Ellen',\n", @@ -416,6 +420,7 @@ " date_of_birth=datetime.datetime(\n", " year=2000, month=random.randint(1, 12), day=3, hour=0, minute=0),\n", " formative_ages = sorted(random.sample(range(5, 20), 7)),\n", + " context=f'Ellen has good reason to hate {outcast}.',\n", " ),\n", "]" ] @@ -428,8 +433,6 @@ }, "outputs": [], "source": [ - "NUM_PLAYERS = 5\n", - "\n", "player_configs = player_configs[:NUM_PLAYERS]\n", "player_names = [player.name for player in player_configs][:NUM_PLAYERS]\n", "measurements = measurements_lib.Measurements()\n", @@ -505,7 +508,23 @@ "instructions = generic_components.constant.ConstantComponent(\n", " game_master_instructions, 'Instructions')\n", "general_knowledge_of_premise = generic_components.constant.ConstantComponent(\n", - " ' '.join(generic_memories), 'General knowledge of the game')\n", + " ', '.join(generic_memories), 'General knowledge of the game')\n", + "\n", + "# The following `knowledge_of_relationships` component is a temporary hack to\n", + "# work around the fact that we don't yet have a way for the game master to\n", + "# ask a player who is the object of another player's action to weigh in on\n", + "# the result of that action. Specifically, this component in the GM prevents\n", + "# the outcast from getting the ball by, on their own turn, asking another player\n", + "# to pass it to them. That would work without this component since the knowledge\n", + "# that the other players hate the outcast would be in the players not the GM,\n", + "# but the GM would resolve the action without asking them. The best solution\n", + "# will be to create a general component to let players influence the resolutions\n", + "# of actions affecting them. We will add it soon.\n", + "relationship_statements = [\n", + " f'{player_name} hates {outcast}' for player_name in player_names\n", + " if player_name != outcast]\n", + "knowledge_of_relationships = generic_components.constant.ConstantComponent(\n", + " ', '.join(relationship_statements), 'Social relationships')\n", "\n", "player_status = gm_components.player_status.PlayerStatus(\n", " clock.now, model, game_master_memory, player_names)\n", @@ -517,11 +536,9 @@ " model=model,\n", " memory=game_master_memory,\n", ")\n", - "time_display = time = generic_components.report_function.ReportFunction(\n", - " name='Current time',\n", - " function=clock.current_time_interval_str,\n", - " )\n", - "\n", + "time_display = gm_components.time_display.TimeDisplay(\n", + " game_clock=clock,\n", + ")\n", "\n", "mem_factory = blank_memories.MemoryFactory(\n", " model,\n", @@ -537,6 +554,8 @@ " clock=clock,\n", " burner_memory_factory=mem_factory,\n", " components=[\n", + " time_display,\n", + " knowledge_of_relationships,\n", " player_status,\n", " ball_status_component,\n", " ],\n", @@ -553,6 +572,8 @@ " clock_now=clock.now,\n", " verbose=False,\n", " components=[\n", + " time_display,\n", + " knowledge_of_relationships,\n", " player_status,\n", " ball_status_component,\n", " ]\n", @@ -576,6 +597,7 @@ " components=[\n", " instructions,\n", " general_knowledge_of_premise,\n", + " knowledge_of_relationships,\n", " relevant_events,\n", " time_display,\n", " player_status,\n", @@ -645,7 +667,7 @@ " player.observe(f'{player_with_ball} has the ball.')\n", " game_master_memory.add(f'{player_with_ball} has the ball.')\n", "\n", - "set_initial_ball_holder('Alice')" + "set_initial_ball_holder('Bob')" ] }, { @@ -666,7 +688,7 @@ "outputs": [], "source": [ "# @title Expect about 2-3 minutes per step.\n", - "episode_length = 3 # @param {type: 'integer'}\n", + "episode_length = 10 # @param {type: 'integer'}\n", "for _ in range(episode_length):\n", " env.step()\n" ] @@ -880,7 +902,8 @@ "kind": "private" }, "private_outputs": true, - "provenance": [] + "provenance": [], + "toc_visible": true }, "kernelspec": { "display_name": "Python 3",