Vowpal Wabbit
Functions
topk.h File Reference
#include "reductions_fwd.h"

Go to the source code of this file.

Functions

LEARNER::base_learnertopk_setup (VW::config::options_i &options, vw &all)
 

Function Documentation

◆ topk_setup()

LEARNER::base_learner* topk_setup ( VW::config::options_i options,
vw all 
)

Definition at line 132 of file topk.cc.

References VW::config::option_group_definition::add(), VW::config::options_i::add_and_parse(), LEARNER::as_singleline(), VW::finish_example(), LEARNER::init_learner(), LEARNER::make_base(), VW::config::make_option(), setup_base(), and VW::config::options_i::was_supplied().

Referenced by parse_reductions().

133 {
134  uint32_t K;
135  option_group_definition new_options("Top K");
136  new_options.add(make_option("top", K).keep().help("top k recommendation"));
137  options.add_and_parse(new_options);
138 
139  if (!options.was_supplied("top"))
140  return nullptr;
141 
142  auto data = scoped_calloc_or_throw<VW::topk>(K);
143 
145  init_learner(data, as_singleline(setup_base(options, all)), predict_or_learn<true>, predict_or_learn<false>);
146  l.set_finish_example(finish_example);
147 
148  return make_base(l);
149 }
base_learner * make_base(learner< T, E > &base)
Definition: learner.h:462
virtual void add_and_parse(const option_group_definition &group)=0
single_learner * as_singleline(learner< T, E > *l)
Definition: learner.h:476
learner< T, E > & init_learner(free_ptr< T > &dat, L *base, void(*learn)(T &, L &, E &), void(*predict)(T &, L &, E &), size_t ws, prediction_type::prediction_type_t pred_type)
Definition: learner.h:369
virtual bool was_supplied(const std::string &key)=0
typed_option< T > make_option(std::string name, T &location)
Definition: options.h:80
void finish_example(vw &all, VW::topk &d, multi_ex &ec_seq)
Definition: topk.cc:124
LEARNER::base_learner * setup_base(options_i &options, vw &all)
Definition: parse_args.cc:1222