Skip to content

Commit 244b37e

Browse files
authored
[benchmark][MOAT] Shuffle choices for MOAT (open-compass#852)
* [benchmark][MOAT] Shuffle choices for MOAT * [benchmark] [MOAT] set random seed for choice shuffle
1 parent 8b281c6 commit 244b37e

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

vlmeval/dataset/moat.py

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
from .utils import DEBUG_MESSAGE
77

88
import zipfile
9+
from random import shuffle, seed
910

1011

12+
RANDOM_SEED = 0
13+
1114
VQA_SYSTEM_PROMPT = json.dumps({
1215
'task': 'Answer the question presented to you truthfully.',
1316
'requirements': [
@@ -42,6 +45,10 @@ class MOAT(ImageBaseDataset):
4245
'MOAT': '803b5a176a5b01aa1b8094fae73532a2',
4346
}
4447

48+
def __init__(self, dataset, **kwargs):
49+
super().__init__(dataset, **kwargs)
50+
seed(RANDOM_SEED) # seed the random number generator to ensure reproducibility
51+
4552
def post_build(self, dataset):
4653
assert dataset == "MOAT", f"Wrong dataset name {dataset}"
4754
ROOT = LMUDataRoot()
@@ -70,16 +77,19 @@ def build_prompt(self, line):
7077
question, choices, images, outside_knowledge_text, outside_knowledge_images = line['question'], line['choices'], line['images'], line['outside_knowledge_text'], line['outside_knowledge_images'] # noqa: E501
7178
choices, images, outside_knowledge_images = toliststr(choices), toliststr(images), toliststr(outside_knowledge_images) # noqa: E501
7279

80+
if len(choices):
81+
shuffle(choices) # shuffle the choices to avoid bias
82+
question += f'\nThe choices are: {choices}'
7383
msgs = [
7484
{
7585
'type': 'text',
76-
'value': VQA_SYSTEM_PROMPT + '\n' + question + (f'\nThe choices are: {choices}' if choices else ''),
86+
'value': VQA_SYSTEM_PROMPT + '\n' + question,
7787
},
7888
]
7989
for img in images:
8090
msgs.append({'type': 'image', 'value': osp.join(self.img_root, img)})
8191
if not pd.isna(outside_knowledge_text):
82-
msgs.append({'type': 'text', 'value': outside_knowledge_text})
92+
msgs.append({'type': 'text', 'value': 'Hint:\n' + outside_knowledge_text})
8393
for img in outside_knowledge_images:
8494
msgs.append({'type': 'image', 'value': osp.join(self.img_root, img)})
8595
return msgs

0 commit comments

Comments
 (0)