forked from EvolvingLMMs-Lab/lmms-eval
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adapt qwen to sqa, gqa, ai2d, docvqa (EvolvingLMMs-Lab#36)
* adapt qwen to sqa, gqa, ai2d, docvqa * black
- Loading branch information
Showing
15 changed files
with
90 additions
and
52 deletions.
There are no files selected for viewing
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
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
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
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
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 |
---|---|---|
@@ -1,32 +1,27 @@ | ||
def ai2d_doc_to_text(doc, model_specific_prompt_kwargs=None): | ||
question, choices = doc["question"], doc["options"] | ||
len_choices = len(choices) | ||
options = [chr(ord("A") + i) for i in range(len_choices)] | ||
choices_str = "\n".join([f"{option}. {choice}" for option, choice in zip(options, choices)]) | ||
|
||
post_prompt = model_specific_prompt_kwargs["post_prompt"] | ||
pre_prompt = model_specific_prompt_kwargs["pre_prompt"] | ||
return f"{pre_prompt}{question}\n{choices_str}{post_prompt}" | ||
if model_specific_prompt_kwargs["prompt_format"] == "mcq": | ||
options = [chr(ord("A") + i) for i in range(len_choices)] | ||
choices_str = "\n".join([f"{option}. {choice}" for option, choice in zip(options, choices)]) | ||
return f"{pre_prompt}{question}\n{choices_str}{post_prompt}" | ||
elif model_specific_prompt_kwargs["prompt_format"] == "qa": | ||
options = "\n".join(choices) | ||
return f"{pre_prompt}{question}{options}{post_prompt}" | ||
else: | ||
raise ValueError(f"Unknown prompt format: {model_specific_prompt_kwargs['prompt_format']}") | ||
|
||
|
||
def ai2d_doc_to_visual(doc): | ||
return [doc["image"].convert("RGB")] | ||
|
||
|
||
def ai2d_doc_to_target(doc): | ||
len_choices = len(doc["options"]) | ||
options = [chr(ord("A") + i) for i in range(len_choices)] | ||
return options[int(doc["answer"])] | ||
|
||
|
||
def ai2d_process_results(doc, results): | ||
# I know this is weird, but it's how llava parse it. | ||
target = ai2d_doc_to_target(doc) | ||
pred = results[0] | ||
if pred == target: | ||
return {"exact_match": 1.0} | ||
# pattern: ^[A-Z]\. .* | ||
if len(pred) >= 2 and pred[0].isupper() and pred[1] == ".": | ||
result = 1.0 if pred[0] == target else 0.0 | ||
return {"exact_match": result} | ||
return {"exact_match": 0.0} | ||
def ai2d_doc_to_target(doc, model_specific_target_kwargs): | ||
if model_specific_target_kwargs == "mcq": | ||
len_choices = len(doc["options"]) | ||
options = [chr(ord("A") + i) for i in range(len_choices)] | ||
return options[int(doc["answer"])] | ||
elif model_specific_target_kwargs == "qa": | ||
return doc["options"][int(doc["answer"])] |
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
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
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
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
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
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
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
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
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
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