Class: DSPy::Evals::BatchEvaluationResult

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/dspy/evals.rb

Overview

Batch evaluation results with aggregated metrics

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(results:, aggregated_metrics:) ⇒ BatchEvaluationResult

Returns a new instance of BatchEvaluationResult.



91
92
93
94
95
96
97
98
99
# File 'lib/dspy/evals.rb', line 91

def initialize(results:, aggregated_metrics:)
  @results = results.freeze
  @aggregated_metrics = aggregated_metrics.freeze
  @total_examples = results.length
  @passed_examples = results.count(&:passed)
  @pass_rate = @total_examples > 0 ? @passed_examples.to_f / @total_examples : 0.0
  score_avg = aggregated_metrics[:score_avg] || @pass_rate
  @score = (score_avg * 100).round(2)
end

Instance Attribute Details

#aggregated_metricsObject (readonly)

Returns the value of attribute aggregated_metrics.



71
72
73
# File 'lib/dspy/evals.rb', line 71

def aggregated_metrics
  @aggregated_metrics
end

#pass_rateObject (readonly)

Returns the value of attribute pass_rate.



80
81
82
# File 'lib/dspy/evals.rb', line 80

def pass_rate
  @pass_rate
end

#passed_examplesObject (readonly)

Returns the value of attribute passed_examples.



77
78
79
# File 'lib/dspy/evals.rb', line 77

def passed_examples
  @passed_examples
end

#resultsObject (readonly)

Returns the value of attribute results.



68
69
70
# File 'lib/dspy/evals.rb', line 68

def results
  @results
end

#scoreObject (readonly)

Returns the value of attribute score.



83
84
85
# File 'lib/dspy/evals.rb', line 83

def score
  @score
end

#total_examplesObject (readonly)

Returns the value of attribute total_examples.



74
75
76
# File 'lib/dspy/evals.rb', line 74

def total_examples
  @total_examples
end

Instance Method Details

#to_hObject



102
103
104
105
106
107
108
109
110
111
# File 'lib/dspy/evals.rb', line 102

def to_h
  {
    total_examples: @total_examples,
    passed_examples: @passed_examples,
    pass_rate: @pass_rate,
    score: @score,
    aggregated_metrics: @aggregated_metrics,
    results: @results.map(&:to_h)
  }
end

#to_polarsObject



118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/dspy/evals.rb', line 118

def to_polars
  ensure_polars!

  rows = @results.each_with_index.map do |result, index|
    {
      "index" => index,
      "passed" => result.passed,
      "score" => result.metrics[:score],
      "example" => serialize_for_polars(result.example),
      "prediction" => serialize_for_polars(result.prediction),
      "metrics" => serialize_for_polars(result.metrics),
      "trace" => serialize_for_polars(result.trace)
    }
  end

  Polars::DataFrame.new(rows)
end