Skip to content

Conversation

@pangyyyyy
Copy link
Contributor

Comment on lines +50 to +76
def build_query(sample):
"""
Construct a multiple-choice query. Inserts <image> placeholder if missing.
Appends either chain-of-thought (CoT) or direct instruction from config.
"""
question = sample["question"]
images = sample.get("images", [])
answer = sample["answer"].strip().upper()
strategy = config["metadata"]["strategy"]

# Ensure <image> placeholder if images are provided
if "<image>" not in question and images:
question += "\n<image>"

# Fill the template with the question
prompt_template = stare_config["multi_choice_format"]
filled_prompt = prompt_template.format(question=question)

# Append the selected strategy instruction
if strategy == "CoT":
query = f"{filled_prompt}\n{stare_config['Strategy_Instruction']['CoT']}"
else:
query = f"{filled_prompt}\n{stare_config['Strategy_Instruction']['Directly']}"

# Build the result dictionary
res_dict = {"query": query, "gt_content": answer, **sample}
return res_dict
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would recommend to use doc_to_messages so that no need to put the placeholder for chat model and the images can be correctly interleaved

Copy link
Collaborator

@kcz358 kcz358 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi, thank you for the contribution. I think most of the code looks nice. The build query should be fine to work for simple model as it is hard to come up with a unified solution with it. I would recommend you to use doc_to_messages api also so that the chat model can build the interleave format better. Feel free to refer to mmmu for more info. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants