Class: DSPy::Teleprompt::MIPROv2
- Inherits:
-
Teleprompter
- Object
- Teleprompter
- DSPy::Teleprompt::MIPROv2
- Extended by:
- T::Sig
- Defined in:
- lib/dspy/teleprompt/mipro_v2.rb
Overview
MIPROv2: Multi-prompt Instruction Proposal with Retrieval Optimization State-of-the-art prompt optimization combining bootstrap sampling, instruction generation, and Bayesian optimization
Defined Under Namespace
Modules: AutoMode Classes: CandidateConfig, MIPROv2Config, MIPROv2Result
Instance Attribute Summary collapse
-
#mipro_config ⇒ Object
readonly
Returns the value of attribute mipro_config.
-
#proposer ⇒ Object
readonly
Returns the value of attribute proposer.
Attributes inherited from Teleprompter
Instance Method Summary collapse
- #compile(program, trainset:, valset: nil) ⇒ Object
-
#initialize(metric: nil, config: nil) ⇒ MIPROv2
constructor
A new instance of MIPROv2.
Methods inherited from Teleprompter
#create_evaluator, #ensure_typed_examples, #evaluate_program, #save_results, #validate_inputs
Constructor Details
#initialize(metric: nil, config: nil) ⇒ MIPROv2
Returns a new instance of MIPROv2.
264 265 266 267 268 269 270 271 |
# File 'lib/dspy/teleprompt/mipro_v2.rb', line 264 def initialize(metric: nil, config: nil) @mipro_config = config || MIPROv2Config.new super(metric: metric, config: @mipro_config) @proposer = DSPy::Propose::GroundedProposer.new(config: @mipro_config.proposer_config) @optimization_trace = [] @evaluated_candidates = [] end |
Instance Attribute Details
#mipro_config ⇒ Object (readonly)
Returns the value of attribute mipro_config.
253 254 255 |
# File 'lib/dspy/teleprompt/mipro_v2.rb', line 253 def mipro_config @mipro_config end |
#proposer ⇒ Object (readonly)
Returns the value of attribute proposer.
256 257 258 |
# File 'lib/dspy/teleprompt/mipro_v2.rb', line 256 def proposer @proposer end |
Instance Method Details
#compile(program, trainset:, valset: nil) ⇒ Object
281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/dspy/teleprompt/mipro_v2.rb', line 281 def compile(program, trainset:, valset: nil) validate_inputs(program, trainset, valset) instrument_step('miprov2_compile', { trainset_size: trainset.size, valset_size: valset&.size || 0, num_trials: @mipro_config.num_trials, optimization_strategy: @mipro_config.optimization_strategy, mode: infer_auto_mode }) do # Convert examples to typed format typed_trainset = ensure_typed_examples(trainset) typed_valset = valset ? ensure_typed_examples(valset) : nil # Use validation set if available, otherwise use part of training set evaluation_set = typed_valset || typed_trainset.take([typed_trainset.size / 3, 10].max) # Phase 1: Bootstrap few-shot examples emit_event('phase_start', { phase: 1, name: 'bootstrap' }) bootstrap_result = phase_1_bootstrap(program, typed_trainset) emit_event('phase_complete', { phase: 1, success_rate: bootstrap_result.statistics[:success_rate], candidate_sets: bootstrap_result.candidate_sets.size }) # Phase 2: Generate instruction candidates emit_event('phase_start', { phase: 2, name: 'instruction_proposal' }) proposal_result = phase_2_propose_instructions(program, typed_trainset, bootstrap_result) emit_event('phase_complete', { phase: 2, num_candidates: proposal_result.num_candidates, best_instruction_preview: proposal_result.best_instruction[0, 50] }) # Phase 3: Bayesian optimization emit_event('phase_start', { phase: 3, name: 'optimization' }) optimization_result = phase_3_optimize( program, evaluation_set, proposal_result, bootstrap_result ) emit_event('phase_complete', { phase: 3, best_score: optimization_result[:best_score], trials_completed: optimization_result[:trials_completed] }) # Build final result final_result = build_miprov2_result( optimization_result, bootstrap_result, proposal_result ) save_results(final_result) final_result end end |