Skip to content

Commit

Permalink
update multimodal games
Browse files Browse the repository at this point in the history
  • Loading branch information
kushal-10 committed May 5, 2024
1 parent 34a201f commit 2419425
Show file tree
Hide file tree
Showing 20 changed files with 12,019 additions and 373 deletions.
2 changes: 1 addition & 1 deletion games/matchit/in/instances.json

Large diffs are not rendered by default.

97 changes: 57 additions & 40 deletions games/matchit/instancegenerator.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,24 @@
import sys
import pandas as pd
from clemgame.clemgame import GameInstanceGenerator

GAME_NAME = "matchit"
GAME_NAME: str = "matchit"
# n instances to be generated
N: int = 10 # max = len(similar_images.csv) = 161, if not using other image pairs
# paths to image pair tables
PATH_DIFF: str = "games/matchit/resources/image_pairs/different_images.csv"
PATH_SIM: str = "games/matchit/resources/image_pairs/similar_images.csv"

#how many questions can each player ask?
DEC_TURN: int = 3
# should the players be informed about the number of questions they can ask?
INFO_NUM_QUESTIONS: bool = False

SEED: int = 42

# Flags that have to be at the beginning of each response; are also specified in the prompts
FLAGS: dict[str, str] = {"description": "DESCRIPTION:", "question": "QUESTION:", "answer": "ANSWER:", "decision": "DECISION:"}
SOL_SAME: str = "same image"
SOL_DIFF: str = "different images"

class MatchItInstanceGenerator(GameInstanceGenerator):
def __init__(self, game_name):
Expand All @@ -11,27 +27,55 @@ def __init__(self, game_name):

def on_generate(self):

prompt_a = self.load_template('resources/initial_prompts/player_a_prompt.template')
prompt_b = self.load_template('resources/initial_prompts/player_b_prompt.template')
differents = pd.read_csv(PATH_DIFF)
diffs = differents.sample(n = N, random_state = SEED)

similars = pd.read_csv(PATH_SIM)
#similars = similars[similars.clipscore >= THRESHOLD_SIM ]
sims = similars.sample(n = N, random_state= SEED)[["url1", "url2"]]

# same images get sampled from the same df as different image, just doubling url1
sames = differents[~differents.url1.isin(diffs.url1)]
sams = sames.sample(n = N, random_state= SEED)[["url1"]]
sams["url2"] = sams[["url1"]]

initial_prompt = self.load_template('resources/initial_prompts/initial_prompt.template').replace("$FLAG$", FLAGS["description"])

desc_intro = self.load_template('resources/initial_prompts/description_introduction.template')

experiments = {"same_image": (self.load_csv("resources/image_pairs/same_image_10_test.csv"), "same image"), "similar_image": (self.load_csv("resources/image_pairs/similar_image_10_test.csv"), "different image"), "different_image": (self.load_csv("resources/image_pairs/different_image_10_test.csv"), "different image")}
sentence_num_questions = self.load_template('resources/initial_prompts/info_num_questions.template').replace("$DEC_TURN$", str(DEC_TURN))

print(experiments)
if INFO_NUM_QUESTIONS:
initial_prompt = initial_prompt.replace("$NUM_QUESTIONS$", sentence_num_questions)
else:
initial_prompt = initial_prompt.replace("$NUM_QUESTIONS$", "")


q_reprompt = self.load_template('resources/initial_prompts/q_reprompt.template').replace("$FLAG$", FLAGS["question"])
d_reprompt = self.load_template('resources/initial_prompts/d_reprompt.template').replace("$SOL_SAME$", SOL_SAME).replace("$SOL_DIFF$", SOL_DIFF).replace("$FLAG$", FLAGS["decision"])
a_request = self.load_template('resources/initial_prompts/a_request.template').replace("$FLAG$", FLAGS["answer"])


experiments = {"same_image": (sams, SOL_SAME),
"similar_image": (sims, SOL_DIFF),
"different_image": (diffs, SOL_DIFF)}

max_turns = 10

for exp_name in experiments.keys():
experiment = self.add_experiment(exp_name)
game_id = 0
experiment["prompt_a"] = prompt_a
experiment["prompt_b"] = prompt_b
experiment["initial_prompt"] = initial_prompt
experiment["q_reprompt"] = q_reprompt
experiment["d_reprompt"] = d_reprompt
experiment["a_request"] = a_request
experiment["desc_intro"] = desc_intro
experiment["flags"] = FLAGS
experiment["solution"] = experiments[exp_name][1]


for inst in experiments[exp_name][0]:
game_id = game_id
for index, row in experiments[exp_name][0].iterrows():
instance = self.add_game_instance(experiment, game_id)
image_a, image_b = inst[0].strip(), inst[1].strip()
image_a, image_b = row["url1"], row["url2"]
if image_a.startswith("http"):
instance["image_a"] = image_a
else:
Expand All @@ -41,37 +85,10 @@ def on_generate(self):
else:
instance["image_b"] = "games/matchit/resources/images/" + image_b

max_turns = max_turns
instance["decision_turn"] = DEC_TURN

game_id += 1




#{game_id: , image_a, image_b, solution}, max_turns, prompt_a, prompt_b



# wir haben idealerweise 3 oder 4 Listen, in denen schon die Bildpaare pro Schwierigkeit festgelegt sind (mit Dateinamen). Später kann man da vielleicht auch noch draus machen, dass diese Listen hier generiert und die Bilder heruntergeladen werden, falls sie noch nicht existieren

#Ziel:
# json file with key "experiments":[] followed by list of ... experiments:
# each experiment has: name, list of instances:
# instances: id, pic1, pic2,



# Schwierigkeit: leicht
# game instances:
# game id: int
# image_player_A: str (.jpg)
# image_player_B: str (.jpg)
# solution: str oder int oder so (same image/1, diff image/0)
# Schwierigkeit: mittel
# game_id: int
# ... etc.
# hart:


if __name__ == "__main__":
MatchItInstanceGenerator(GAME_NAME).generate()
Loading

0 comments on commit 2419425

Please sign in to comment.