Pick the ensemble output with the most total weight
Source:R/module-ensemble.R
reduce_weighted_vote.Rdreduce_weighted_vote() makes a reducer for ensemble() that adds up the
weights of the modules behind each value and returns the output with the
largest total. Without weights, every vote counts 1.
Value
A function function(outputs, weights = NULL) for the reduce_fn
argument of ensemble().
Details
Values are compared as strings. Ties go to the value that sorts first alphabetically. The reducer returns the whole output of the first module that gave the winning value.
See also
Other composition:
as_reward_fn(),
best_of_n(),
ensemble(),
module-graph,
pipeline(),
reduce_best_by_metric(),
reduce_first(),
reduce_majority(),
refine(),
step(),
with_assertions()
Examples
vote <- reduce_weighted_vote(field = "sentiment")
outputs <- list(
list(sentiment = "positive"),
list(sentiment = "negative"),
list(sentiment = "positive")
)
vote(outputs)
#> $sentiment
#> [1] "positive"
#>
# The second module is trusted more than the other two together
vote(outputs, weights = c(0.4, 0.9, 0.4))
#> $sentiment
#> [1] "negative"
#>