-
Notifications
You must be signed in to change notification settings - Fork 84
Expand file tree
/
Copy pathrun_negative.py
More file actions
169 lines (151 loc) · 4.86 KB
/
run_negative.py
File metadata and controls
169 lines (151 loc) · 4.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
# Copyright 2025 CHATS-Lab. All Rights Reserved.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
from pathlib import Path
from typing import Any, Dict, List
from verbalized_sampling.methods import Method
from verbalized_sampling.pipeline import (
EvaluationConfig,
ExperimentConfig,
Pipeline,
PipelineConfig,
)
from verbalized_sampling.tasks import Task
def create_method_experiments(
task: Task,
model_name: str,
temperature: float,
top_p: float,
methods: List[Dict[str, Any]],
) -> List[ExperimentConfig]:
"""Create experiments for testing specific method variations."""
# Base configuration
base = {
"task": task,
"model_name": model_name,
"num_responses": 10,
"num_prompts": 50, # maximum 100
"target_words": 0,
"temperature": temperature,
"top_p": top_p,
"random_seed": 42,
"use_vllm": False,
}
experiments = []
for method_config in methods:
# Create name
name = f"{method_config['method'].value}"
if method_config.get("strict_json"):
name += " [strict]"
if method_config.get("num_samples"):
name += f" (samples={method_config['num_samples']})"
experiments.append(ExperimentConfig(name=name, **base, **method_config))
return experiments
def run_method_tests(
task: Task,
model_name: str,
methods: List[Dict[str, Any]],
metrics: List[str], # "ngram"
temperature: float,
top_p: float,
output_dir: str,
num_workers: int = 16,
) -> None:
"""Run tests for specific method variations."""
print("🔬 Running Method Tests")
experiments = create_method_experiments(task, model_name, temperature, top_p, methods)
print(f"📊 {len(experiments)} methods to test")
for i, exp in enumerate(experiments, 1):
print(f" {i}. {exp.name}")
model_basename = model_name.replace("/", "_")
config = PipelineConfig(
experiments=experiments,
evaluation=EvaluationConfig(metrics=metrics),
output_base_dir=Path(f"{output_dir}/{model_basename}_{task.value}"),
skip_existing=True,
)
pipeline = Pipeline(config)
pipeline.run_complete_pipeline()
print(f"✅ Done! Check {output_dir}/{model_basename}_{task.value}/pipeline_report.html")
if __name__ == "__main__":
# Example usage for testing different method variations
# Test multi-turn and JSON mode variations
num_samples = 5
methods = [
# {
# 'method': Method.DIRECT,
# 'strict_json': False,
# 'num_samples': 1,
# },
# {
# 'method': Method.DIRECT_COT,
# 'strict_json': True,
# 'num_samples': 1,
# },
{
"method": Method.MULTI_TURN,
"strict_json": False,
"num_samples": num_samples,
},
# {
# 'method': Method.SEQUENCE,
# 'strict_json': True,
# 'num_samples': num_samples,
# },
# {
# 'method': Method.VS_STANDARD,
# 'strict_json': True,
# 'num_samples': num_samples,
# },
{
"method": Method.SEQUENCE,
"strict_json": True,
"num_samples": num_samples,
},
# {
# 'method': Method.VS_STANDARD,
# 'strict_json': True,
# 'num_samples': num_samples,
# },
# {
# 'method': Method.VS_MULTI,
# 'strict_json': True,
# 'num_samples': num_samples,
# 'num_samples_per_prompt': 2,
# }
]
models = [
# "gpt-4.1-mini",
"gpt-4.1",
# "gemini-2.5-flash",
# "gemini-2.5-pro",
# "llama-3.1-70b-instruct",
# "claude-4-sonnet",
# "meta-llama/Llama-3.1-70B-Instruct",
# "meta-llama/Llama-3.1-70B",
# "anthropic/claude-4-sonnet",
# "deepseek-r1",
# "o3",
]
for model in models:
model_basename = model.replace("/", "_")
run_method_tests(
task=Task.SYNTHETIC_NEGATIVE,
model_name=model,
methods=methods,
metrics=["diversity"],
temperature=0.7,
top_p=1.0,
output_dir="method_synthetic_negative_test",
num_workers=16 if any(x in model_basename for x in ["claude", "gemini"]) else 32,
)