Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 23 additions & 18 deletions openseek/competition/LongContext-ICL-Annotation/src/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@

# from method import build_prompt, select_examples, annotate

from method import build_prompt, select_examples
from method import build_prompt, select_examples, select_examples_M05, select_examples_M19, select_examples_M20, select_examples_M09, select_examples_M10, select_examples_M11, build_prompt_cot, build_prompt_by_task_type

from method import annotate_nvidia as annotate # For Nvidia GPU
# from method import annotate_ascend as annotate # For Huawei Ascend
# from method import annotate_nvidia as annotate # For Nvidia GPU
from method import annotate_ascend as annotate # For Huawei Ascend

TASK_FILES = {
1: './data/openseek-1_closest_integers.json',
2: './data/openseek-2_count_nouns_verbs.json',
3: './data/openseek-3_collatz_conjecture.json',
4: './data/openseek-4_conala_concat_strings.json',
5: './data/openseek-5_semeval_2018_task1_tweet_sadness_detection.json',
6: './data/openseek-6_mnli_same_genre_classification.json',
7: './data/openseek-7_jeopardy_answer_generation_all.json',
8: '../data/openseek-8_kernel_generation.json',
1: '/root/OpenSeek/openseek/competition/LongContext-ICL-Annotation/data/openseek-1_closest_integers.json',
2: '/root/OpenSeek/openseek/competition/LongContext-ICL-Annotation/data/openseek-2_count_nouns_verbs.json',
3: '/root/OpenSeek/openseek/competition/LongContext-ICL-Annotation/data/openseek-3_collatz_conjecture.json',
4: '/root/OpenSeek/openseek/competition/LongContext-ICL-Annotation/data/openseek-4_conala_concat_strings.json',
5: '/root/OpenSeek/openseek/competition/LongContext-ICL-Annotation/data/openseek-5_semeval_2018_task1_tweet_sadness_detection.json',
6: '/root/OpenSeek/openseek/competition/LongContext-ICL-Annotation/data/openseek-6_mnli_same_genre_classification.json',
7: '/root/OpenSeek/openseek/competition/LongContext-ICL-Annotation/data/openseek-7_jeopardy_answer_generation_all.json',
8: '/root/OpenSeek/openseek/competition/LongContext-ICL-Annotation/data/openseek-8_kernel_generation.json',
}

def parser_args():
Expand All @@ -30,7 +30,7 @@ def parser_args():
default='../outputs/',
help='Prefix path to save the evaluation logs.')
parser.add_argument('--tokenizer_path', type=str,
default='/share/project/wuhaiming/spaces/data_agent/OpenSeek-main/openseek/competition/LongContext-ICL-Annotation/src/Qwen3-4B')
default='/root/Qwen3-4B')
args = parser.parse_args()
return args

Expand All @@ -48,7 +48,7 @@ def evaluate(task_id:int,

task_name = task_dict['task_name']
task_description = task_dict['Definition'][0]
icl_examples = task_dict['examples'][:100]
icl_examples = task_dict['examples'][:50]
test_samples = task_dict['test_samples']

version = 1
Expand All @@ -62,26 +62,31 @@ def evaluate(task_id:int,
pass

examples_str = None
for test_sample in tqdm(test_samples, desc=f'Evaluation on Task {task_id}: {task_name}'):
for sample_idx, test_sample in enumerate(tqdm(test_samples, desc=f'Evaluation on Task {task_id}: {task_name}')):
test_record = dict()

test_sample_id = test_sample['id']
test_record['test_sample_id'] = test_sample_id


text2annotate = test_sample['input']
prompt = build_prompt(task_description, text2annotate)

# M03优化:使用任务分型Prompt路由系统
# 根据任务类型自动选择最合适的prompt策略
prompt = build_prompt_by_task_type(task_id, task_description, text2annotate)

if examples_str is None:
examples_str = select_examples(icl_examples, task_description, text2annotate)
# M11优化:使用Task 7 Jeopardy线索拆解策略
examples_str = select_examples_M11(icl_examples, task_description, text2annotate, task_id, sample_idx)
Comment on lines 78 to +80

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

high

🚨 Logic Error: Caching examples_str defeats dynamic example selection

In the current implementation, examples_str is initialized to None outside the loop and cached after the first iteration:

if examples_str is None:
    examples_str = select_examples_M11(...)

Because of this, select_examples_M11 (or any other dynamic selection method) is only called once for the very first sample (sample_idx = 0). For all subsequent samples, the exact same examples are reused.

This completely breaks:

  1. Dynamic Retrieval: Examples are not selected based on the current sample's text2annotate similarity or keywords.
  2. Mixed Context Length Strategy: The sample_index < 50 check in select_examples_M11 will always evaluate to True (since it only runs for sample_idx = 0), meaning a 30k context is used for all samples, which is highly inefficient and defeats the 8k fallback optimization.
  3. Specialized Routing: The other specialized strategies (select_examples_M09 for Task 5, select_examples_M10 for Task 6, select_examples_M20 for other tasks) are imported but never used.

Recommendation: Remove the if examples_str is None: check and route the example selection dynamically based on task_id.

Suggested change
if examples_str is None:
examples_str = select_examples(icl_examples, task_description, text2annotate)
# M11优化:使用Task 7 Jeopardy线索拆解策略
examples_str = select_examples_M11(icl_examples, task_description, text2annotate, task_id, sample_idx)
# Dynamic example selection based on task type (M09, M10, M11, M20)
if task_id == 5:
examples_str = select_examples_M09(icl_examples, task_description, text2annotate, task_id, sample_idx)
elif task_id == 6:
examples_str = select_examples_M10(icl_examples, task_description, text2annotate, task_id, sample_idx)
elif task_id == 7:
examples_str = select_examples_M11(icl_examples, task_description, text2annotate, task_id, sample_idx)
else:
examples_str = select_examples_M20(icl_examples, task_description, text2annotate, task_id, sample_idx)

input_prompt = prompt.replace("[[EXAMPLES]]\n\n", examples_str+'\n\n')

# tokenized_input = qwen_tokenizer(input_prompt, return_tensors="pt")
# if tokenized_input['input_ids'].shape[1] > max_input_length:
# test_record['prediction'] = None
# else:
# prediction = annotate(input_prompt)
# prediction = annotate(input_prompt, task_id)
# test_record['prediction'] = prediction
prediction = annotate(input_prompt)
prediction = annotate(input_prompt, task_id)
test_record['prediction'] = prediction
with open(output_file, 'a') as f:
f.write(json.dumps(test_record)+'\n')
Expand Down
Loading