From b5fe70d0914197715cc358b032354786e23d90fe Mon Sep 17 00:00:00 2001 From: Jack Gerrits Date: Thu, 5 Jan 2023 10:53:01 -0500 Subject: [PATCH] refactor: cleanup cb.h header (#4427) * refactor: cleanup cb.h header * fix inline * deprecated usage * csharp fix * format --- cs/cli/vw_example.cpp | 5 +- cs/cli/vw_label.h | 12 +-- cs/vw.net.native/vw.net.cbutil.cc | 2 +- cs/vw.net.native/vw.net.labels.cc | 16 +-- cs/vw.net.native/vw.net.labels.h | 4 +- java/src/main/c++/jni_spark_vw.cc | 14 +-- python/pylibvw.cc | 8 +- .../core/include/vw/core/automl_impl.h | 4 +- vowpalwabbit/core/include/vw/core/cb.h | 70 ++++++++---- vowpalwabbit/core/include/vw/core/example.h | 4 +- .../core/include/vw/core/gen_cs_example.h | 19 ++-- .../include/vw/core/reductions/cats_tree.h | 2 +- .../include/vw/core/reductions/cb/cb_adf.h | 8 +- .../include/vw/core/reductions/cb/cb_algs.h | 11 +- .../reductions/cb/cb_explore_adf_common.h | 14 +-- .../include/vw/core/reductions/pmf_to_pdf.h | 2 +- vowpalwabbit/core/src/cb.cc | 102 +++++++++--------- vowpalwabbit/core/src/gen_cs_example.cc | 10 +- vowpalwabbit/core/src/label_parser.cc | 4 +- vowpalwabbit/core/src/learner.cc | 2 +- vowpalwabbit/core/src/reductions/automl.cc | 2 +- .../src/reductions/baseline_challenger_cb.cc | 2 +- vowpalwabbit/core/src/reductions/cats_tree.cc | 6 +- vowpalwabbit/core/src/reductions/cb/cb_adf.cc | 13 ++- .../core/src/reductions/cb/cb_algs.cc | 17 ++- vowpalwabbit/core/src/reductions/cb/cb_dro.cc | 2 +- .../core/src/reductions/cb/cb_explore.cc | 8 +- .../src/reductions/cb/cb_explore_adf_bag.cc | 2 +- .../src/reductions/cb/cb_explore_adf_cover.cc | 4 +- .../src/reductions/cb/cb_explore_adf_first.cc | 2 +- .../reductions/cb/cb_explore_adf_greedy.cc | 2 +- .../cb/cb_explore_adf_large_action_space.cc | 4 +- .../src/reductions/cb/cb_explore_adf_regcb.cc | 6 +- .../src/reductions/cb/cb_explore_adf_rnd.cc | 4 +- .../reductions/cb/cb_explore_adf_softmax.cc | 2 +- .../reductions/cb/cb_explore_adf_squarecb.cc | 6 +- .../cb/cb_explore_adf_synthcover.cc | 4 +- .../core/src/reductions/cb/cb_to_cb_adf.cc | 4 +- vowpalwabbit/core/src/reductions/cb/cbify.cc | 12 +-- .../details/large_action/two_pass_svd_impl.cc | 4 +- .../core/src/reductions/cb/warm_cb.cc | 8 +- .../conditional_contextual_bandit.cc | 10 +- .../reductions/details/automl/automl_impl.cc | 4 +- .../core/src/reductions/epsilon_decay.cc | 2 +- .../core/src/reductions/explore_eval.cc | 10 +- .../core/src/reductions/interaction_ground.cc | 2 +- vowpalwabbit/core/src/reductions/mwt.cc | 4 +- .../core/src/reductions/offset_tree.cc | 2 +- .../core/src/reductions/pmf_to_pdf.cc | 4 +- .../core/src/reductions/search/search.cc | 4 +- vowpalwabbit/core/tests/cats_tree_test.cc | 56 +++++----- .../core/tests/cb_large_actions_test.cc | 4 +- .../core/tests/example_header_test.cc | 10 +- vowpalwabbit/core/tests/offset_tree_test.cc | 2 +- vowpalwabbit/fb_parser/src/parse_label.cc | 4 +- .../json_parser/src/parse_example_json.cc | 12 +-- 56 files changed, 288 insertions(+), 269 deletions(-) diff --git a/cs/cli/vw_example.cpp b/cs/cli/vw_example.cpp index 6718f1acca6..6eb6ea929c3 100644 --- a/cs/cli/vw_example.cpp +++ b/cs/cli/vw_example.cpp @@ -2,6 +2,7 @@ // individual contributors. All rights reserved. Released under a BSD (revised) // license as described in the file LICENSE. +#include "vw/core/cb.h" #define NOMINMAX #include "vowpalwabbit.h" @@ -75,9 +76,9 @@ ILabel^ VowpalWabbitExample::Label::get() auto lp = m_owner->Native->m_vw->example_parser->lbl_parser; if (!memcmp(&lp, &VW::simple_label_parser_global, sizeof(lp))) label = gcnew SimpleLabel(); - else if (!memcmp(&lp, &CB::cb_label, sizeof(lp))) + else if (!memcmp(&lp, &VW::cb_label_parser_global, sizeof(lp))) label = gcnew ContextualBanditLabel(); - else if (!memcmp(&lp, &CB_EVAL::cb_eval, sizeof(lp))) + else if (!memcmp(&lp, &VW::cb_eval_label_parser_global, sizeof(lp))) label = gcnew SimpleLabel(); else if (!memcmp(&lp, &VW::cs_label_parser_global, sizeof(lp))) label = gcnew SimpleLabel(); diff --git a/cs/cli/vw_label.h b/cs/cli/vw_label.h index bb3068cf90e..9eadb78c67d 100644 --- a/cs/cli/vw_label.h +++ b/cs/cli/vw_label.h @@ -100,10 +100,10 @@ public ref class ContextualBanditLabel sealed : ILabel virtual void ReadFromExample(example* ex) { - CB::label* ld = &ex->l.cb; + VW::cb_label* ld = &ex->l.cb; if (ld->costs.size() > 0) { - CB::cb_class& f = ld->costs[0]; + VW::cb_class& f = ld->costs[0]; m_action = f.action; m_cost = f.cost; @@ -113,8 +113,8 @@ public ref class ContextualBanditLabel sealed : ILabel virtual void UpdateExample(VW::workspace* vw, example* ex) { - CB::label* ld = &ex->l.cb; - CB::cb_class f; + VW::cb_label* ld = &ex->l.cb; + VW::cb_class f; f.partial_prediction = 0.; f.action = m_action; @@ -153,8 +153,8 @@ public ref class SharedLabel sealed : ILabel virtual void UpdateExample(VW::workspace* vw, example* ex) { - CB::label* ld = &ex->l.cb; - CB::cb_class f; + VW::cb_label* ld = &ex->l.cb; + VW::cb_class f; f.partial_prediction = 0.; f.action = m_action; diff --git a/cs/vw.net.native/vw.net.cbutil.cc b/cs/vw.net.native/vw.net.cbutil.cc index 6d7e3205f03..fe041a80b6a 100644 --- a/cs/vw.net.native/vw.net.cbutil.cc +++ b/cs/vw.net.native/vw.net.cbutil.cc @@ -2,6 +2,6 @@ API float GetCbUnbiasedCost(uint32_t actionObservered, uint32_t actionTaken, float cost, float probability) { - CB::cb_class observation(cost, actionObservered, probability); + VW::cb_class observation(cost, actionObservered, probability); return CB_ALGS::get_cost_estimate(observation, actionTaken); } \ No newline at end of file diff --git a/cs/vw.net.native/vw.net.labels.cc b/cs/vw.net.native/vw.net.labels.cc index c87dfbb1b31..c25054b34ef 100644 --- a/cs/vw.net.native/vw.net.labels.cc +++ b/cs/vw.net.native/vw.net.labels.cc @@ -31,16 +31,16 @@ API void SimpleLabelUpdateExample(vw_net_native::workspace_context* workspace, V VW::count_label(*workspace->vw->sd, ld->label); } -API CB::cb_class* CbLabelReadFromExampleDangerous(VW::example* ex) +API VW::cb_class* CbLabelReadFromExampleDangerous(VW::example* ex) { - CB::label* ld = &ex->l.cb; + VW::cb_label* ld = &ex->l.cb; return (ld->costs.size() > 0) ? &ld->costs[0] : nullptr; } -API void CbLabelUpdateExample(VW::example* ex, const CB::cb_class* f) +API void CbLabelUpdateExample(VW::example* ex, const VW::cb_class* f) { - CB::label* ld = &ex->l.cb; + VW::cb_label* ld = &ex->l.cb; // TODO: Should we be clearing the costs here? // ld->costs.clear(); @@ -86,8 +86,8 @@ API char* ComputeDiffDescriptionSimpleLabels(VW::example* ex1, VW::example* ex2) API char* ComputeDiffDescriptionCbLabels(VW::example* ex1, VW::example* ex2) { - CB::label ld1 = ex1->l.cb; - CB::label ld2 = ex2->l.cb; + VW::cb_label ld1 = ex1->l.cb; + VW::cb_label ld2 = ex2->l.cb; std::stringstream sstream; if (ld1.costs.size() != ld2.costs.size()) @@ -99,8 +99,8 @@ API char* ComputeDiffDescriptionCbLabels(VW::example* ex1, VW::example* ex2) { for (size_t i = 0; i < ld1.costs.size(); i++) { - CB::cb_class c1 = ld1.costs[i]; - CB::cb_class c2 = ld2.costs[i]; + VW::cb_class c1 = ld1.costs[i]; + VW::cb_class c2 = ld2.costs[i]; if (c1.action != c2.action) { diff --git a/cs/vw.net.native/vw.net.labels.h b/cs/vw.net.native/vw.net.labels.h index e5b0339eb8c..17300471565 100644 --- a/cs/vw.net.native/vw.net.labels.h +++ b/cs/vw.net.native/vw.net.labels.h @@ -14,8 +14,8 @@ extern "C" API void SimpleLabelUpdateExample(vw_net_native::workspace_context* workspace, VW::example* ex, float label, float* maybe_weight, float* maybe_initial); - API CB::cb_class* CbLabelReadFromExampleDangerous(VW::example* ex); - API void CbLabelUpdateExample(VW::example* ex, const CB::cb_class* f); + API VW::cb_class* CbLabelReadFromExampleDangerous(VW::example* ex); + API void CbLabelUpdateExample(VW::example* ex, const VW::cb_class* f); API vw_net_native::ERROR_CODE StringLabelParseAndUpdateExample(vw_net_native::workspace_context* workspace, VW::example* ex, const char* label, size_t label_len, VW::experimental::api_status* status = nullptr); diff --git a/java/src/main/c++/jni_spark_vw.cc b/java/src/main/c++/jni_spark_vw.cc index 9f92b53a104..1d8fa64021b 100644 --- a/java/src/main/c++/jni_spark_vw.cc +++ b/java/src/main/c++/jni_spark_vw.cc @@ -710,8 +710,8 @@ JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitExample_setContex try { - CB::label* ld = &ex->l.cb; - CB::cb_class f; + VW::cb_label* ld = &ex->l.cb; + VW::cb_class f; f.action = (uint32_t)action; f.cost = (float)cost; @@ -732,8 +732,8 @@ JNIEXPORT void JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitExample_setShared try { // https://github.com/VowpalWabbit/vowpal_wabbit/blob/master/vowpalwabbit/parse_example_json.h#L437 - CB::label* ld = &ex->l.cb; - CB::cb_class f; + VW::cb_label* ld = &ex->l.cb; + VW::cb_class f; f.partial_prediction = 0.; f.action = (uint32_t)VW::uniform_hash("shared", 6 /*length of string*/, 0); @@ -889,16 +889,16 @@ JNIEXPORT jstring JNICALL Java_org_vowpalwabbit_spark_VowpalWabbitExample_toStri const auto& red_fts = ex->ex_reduction_features.template get(); ostr << "simple " << ld->label << ":" << red_fts.weight << ":" << red_fts.initial; } - else if (!memcmp(&lp, &CB::cb_label, sizeof(lp))) + else if (!memcmp(&lp, &VW::cb_label_parser_global, sizeof(lp))) { - CB::label* ld = &ex->l.cb; + VW::cb_label* ld = &ex->l.cb; ostr << "CB " << ld->costs.size(); if (ld->costs.size() > 0) { ostr << " "; - CB::cb_class& f = ld->costs[0]; + VW::cb_class& f = ld->costs[0]; // Ignore checking if f.action == VW::uniform_hash("shared") if (f.partial_prediction == 0 && f.cost == FLT_MAX && f.probability == -1.f) diff --git a/python/pylibvw.cc b/python/pylibvw.cc index 759d487943c..c2dba2c4063 100644 --- a/python/pylibvw.cc +++ b/python/pylibvw.cc @@ -402,7 +402,7 @@ VW::label_parser* get_label_parser(VW::workspace* all, size_t labelType) case lCOST_SENSITIVE: return &VW::cs_label_parser_global; case lCONTEXTUAL_BANDIT: - return &CB::cb_label; + return &VW::cb_label_parser_global; case lCONDITIONAL_CONTEXTUAL_BANDIT: return &VW::ccb_label_parser_global; case lSLATES: @@ -410,7 +410,7 @@ VW::label_parser* get_label_parser(VW::workspace* all, size_t labelType) case lCONTINUOUS: return &VW::cb_continuous::the_label_parser; case lCONTEXTUAL_BANDIT_EVAL: - return &CB_EVAL::cb_eval; + return &VW::cb_eval_label_parser_global; case lMULTILABEL: return &MULTILABEL::multilabel; default: @@ -424,8 +424,8 @@ size_t my_get_label_type(VW::workspace* all) if (lp->parse_label == VW::simple_label_parser_global.parse_label) { return lSIMPLE; } else if (lp->parse_label == VW::multiclass_label_parser_global.parse_label) { return lMULTICLASS; } else if (lp->parse_label == VW::cs_label_parser_global.parse_label) { return lCOST_SENSITIVE; } - else if (lp->parse_label == CB::cb_label.parse_label) { return lCONTEXTUAL_BANDIT; } - else if (lp->parse_label == CB_EVAL::cb_eval.parse_label) { return lCONTEXTUAL_BANDIT_EVAL; } + else if (lp->parse_label == VW::cb_label_parser_global.parse_label) { return lCONTEXTUAL_BANDIT; } + else if (lp->parse_label == VW::cb_eval_label_parser_global.parse_label) { return lCONTEXTUAL_BANDIT_EVAL; } else if (lp->parse_label == VW::ccb_label_parser_global.parse_label) { return lCONDITIONAL_CONTEXTUAL_BANDIT; } else if (lp->parse_label == VW::slates::slates_label_parser.parse_label) { return lSLATES; } else if (lp->parse_label == VW::cb_continuous::the_label_parser.parse_label) { return lCONTINUOUS; } diff --git a/vowpalwabbit/core/include/vw/core/automl_impl.h b/vowpalwabbit/core/include/vw/core/automl_impl.h index 98fb9dc9aff..6bcbba0cb65 100644 --- a/vowpalwabbit/core/include/vw/core/automl_impl.h +++ b/vowpalwabbit/core/include/vw/core/automl_impl.h @@ -296,8 +296,8 @@ class automl } } // This fn gets called before learning any example - void one_step(VW::LEARNER::multi_learner& base, multi_ex& ec, CB::cb_class& logged, uint64_t labelled_action); - void offset_learn(VW::LEARNER::multi_learner& base, multi_ex& ec, CB::cb_class& logged, uint64_t labelled_action); + void one_step(VW::LEARNER::multi_learner& base, multi_ex& ec, VW::cb_class& logged, uint64_t labelled_action); + void offset_learn(VW::LEARNER::multi_learner& base, multi_ex& ec, VW::cb_class& logged, uint64_t labelled_action); }; } // namespace automl diff --git a/vowpalwabbit/core/include/vw/core/cb.h b/vowpalwabbit/core/include/vw/core/cb.h index f763317928d..3672441b6c1 100644 --- a/vowpalwabbit/core/include/vw/core/cb.h +++ b/vowpalwabbit/core/include/vw/core/cb.h @@ -5,6 +5,7 @@ #include "vw/core/io_buf.h" #include "vw/core/label_parser.h" +#include "vw/core/multi_ex.h" #include "vw/core/v_array.h" #include "vw/core/vw_fwd.h" @@ -15,11 +16,6 @@ namespace VW { -class example; -using multi_ex = std::vector; -} // namespace VW -namespace CB -{ // By default a cb class does not contain an observed cost. class cb_class { @@ -41,7 +37,7 @@ class cb_class constexpr bool has_observed_cost() const { return (cost != FLT_MAX && probability > .0); } }; -class label +class cb_label { public: std::vector costs; @@ -52,36 +48,64 @@ class label void reset_to_default(); }; -extern VW::label_parser cb_label; // for learning -bool ec_is_example_header(VW::example const& ec); // example headers look like "shared" +extern VW::label_parser cb_label_parser_global; -std::pair get_observed_cost_cb(const label& ld); +// example headers look like "shared" +bool ec_is_example_header_cb(VW::example const& ec); -void print_update(VW::workspace& all, bool is_test, const VW::example& ec, const VW::multi_ex* ec_seq, - bool action_scores, const CB::cb_class* known_cost); -} // namespace CB +std::pair get_observed_cost_cb(const cb_label& ld); -namespace CB_EVAL +} // namespace VW +namespace VW +{ +namespace details +{ +void print_update_cb(VW::workspace& all, bool is_test, const VW::example& ec, const VW::multi_ex* ec_seq, + bool action_scores, const VW::cb_class* known_cost); +} +} // namespace VW + +namespace VW { -class label +class cb_eval_label { public: uint32_t action = 0; - CB::label event; + cb_label event; }; -extern VW::label_parser cb_eval; // for evaluation of an arbitrary policy. -} // namespace CB_EVAL +extern VW::label_parser cb_eval_label_parser_global; // for evaluation of an arbitrary policy. +} // namespace VW namespace VW { namespace model_utils { -size_t read_model_field(io_buf&, CB::cb_class&); -size_t write_model_field(io_buf&, const CB::cb_class&, const std::string&, bool); -size_t read_model_field(io_buf&, CB::label&); -size_t write_model_field(io_buf&, const CB::label&, const std::string&, bool); -size_t read_model_field(io_buf&, CB_EVAL::label&); -size_t write_model_field(io_buf&, const CB_EVAL::label&, const std::string&, bool); +size_t read_model_field(io_buf&, VW::cb_class&); +size_t write_model_field(io_buf&, const VW::cb_class&, const std::string&, bool); +size_t read_model_field(io_buf&, VW::cb_label&); +size_t write_model_field(io_buf&, const VW::cb_label&, const std::string&, bool); +size_t read_model_field(io_buf&, VW::cb_eval_label&); +size_t write_model_field(io_buf&, const VW::cb_eval_label&, const std::string&, bool); } // namespace model_utils } // namespace VW + +namespace CB +{ +using cb_class VW_DEPRECATED("Renamed to VW::cb_class") = VW::cb_class; +using label VW_DEPRECATED("Renamed to VW::cb_label") = VW::cb_label; + +VW_DEPRECATED("Renamed to VW::ec_is_example_header_cb") +inline bool ec_is_example_header(VW::example const& ec) { return VW::ec_is_example_header_cb(ec); } + +VW_DEPRECATED("Renamed to VW::get_observed_cost_cb") +inline std::pair get_observed_cost_cb(const VW::cb_label& ld) +{ + return VW::get_observed_cost_cb(ld); +} +} // namespace CB + +namespace CB_EVAL +{ +using label VW_DEPRECATED("Renamed to VW::cb_eval_label") = VW::cb_eval_label; +} \ No newline at end of file diff --git a/vowpalwabbit/core/include/vw/core/example.h b/vowpalwabbit/core/include/vw/core/example.h index 7fed8174110..69c8c2e9840 100644 --- a/vowpalwabbit/core/include/vw/core/example.h +++ b/vowpalwabbit/core/include/vw/core/example.h @@ -41,11 +41,11 @@ class polylabel VW::simple_label simple; VW::multiclass_label multi; VW::cs_label cs; - CB::label cb; + VW::cb_label cb; VW::cb_continuous::continuous_label cb_cont; VW::ccb_label conditional_contextual_bandit; VW::slates::label slates; - CB_EVAL::label cb_eval; + VW::cb_eval_label cb_eval; MULTILABEL::labels multilabels; }; diff --git a/vowpalwabbit/core/include/vw/core/gen_cs_example.h b/vowpalwabbit/core/include/vw/core/gen_cs_example.h index 5a2656db4f1..bd91a9fc09e 100644 --- a/vowpalwabbit/core/include/vw/core/gen_cs_example.h +++ b/vowpalwabbit/core/include/vw/core/gen_cs_example.h @@ -22,7 +22,7 @@ class cb_to_cs float last_pred_reg = 0.f; float last_correct_cost = 0.f; - CB::cb_class known_cost; + VW::cb_class known_cost; }; class cb_to_cs_adf @@ -38,17 +38,17 @@ class cb_to_cs_adf // for DR VW::cs_label pred_scores; - CB::cb_class known_cost; + VW::cb_class known_cost; VW::LEARNER::single_learner* scorer = nullptr; }; float safe_probability(float prob, VW::io::logger& logger); void gen_cs_example_ips( - cb_to_cs& c, const CB::label& ld, VW::cs_label& cs_ld, VW::io::logger& logger, float clip_p = 0.f); + cb_to_cs& c, const VW::cb_label& ld, VW::cs_label& cs_ld, VW::io::logger& logger, float clip_p = 0.f); template -void gen_cs_example_dm(cb_to_cs& c, VW::example& ec, const CB::label& ld, VW::cs_label& cs_ld) +void gen_cs_example_dm(cb_to_cs& c, VW::example& ec, const VW::cb_label& ld, VW::cs_label& cs_ld) { // this implements the direct estimation method, where costs are directly specified by the learned regressor. float min = FLT_MAX; @@ -141,7 +141,8 @@ void gen_cs_label(cb_to_cs& c, VW::example& ec, VW::cs_label& cs_ld, uint32_t ac } template -void gen_cs_example_dr(cb_to_cs& c, VW::example& ec, const CB::label& ld, VW::cs_label& cs_ld, float /*clip_p*/ = 0.f) +void gen_cs_example_dr( + cb_to_cs& c, VW::example& ec, const VW::cb_label& ld, VW::cs_label& cs_ld, float /*clip_p*/ = 0.f) { // this implements the doubly robust method VW_DBG(ec) << "gen_cs_example_dr:" << is_learn << std::endl; @@ -169,7 +170,7 @@ void gen_cs_example_dr(cb_to_cs& c, VW::example& ec, const CB::label& ld, VW::cs } template -void gen_cs_example(cb_to_cs& c, VW::example& ec, const CB::label& ld, VW::cs_label& cs_ld, VW::io::logger& logger) +void gen_cs_example(cb_to_cs& c, VW::example& ec, const VW::cb_label& ld, VW::cs_label& cs_ld, VW::io::logger& logger) { switch (c.cb_type) { @@ -222,7 +223,7 @@ void gen_cs_example_dr(cb_to_cs_adf& c, VW::multi_ex& examples, VW::cs_label& cs wc.x = CB_ALGS::get_cost_pred(c.scorer, c.known_cost, *(examples[i]), 0, 2); c.known_cost.action = known_index; } - else { wc.x = CB_ALGS::get_cost_pred(c.scorer, CB::cb_class{}, *(examples[i]), 0, 2); } + else { wc.x = CB_ALGS::get_cost_pred(c.scorer, VW::cb_class{}, *(examples[i]), 0, 2); } c.pred_scores.costs.push_back(wc); // done @@ -255,12 +256,12 @@ void gen_cs_example(cb_to_cs_adf& c, VW::multi_ex& ec_seq, VW::cs_label& cs_labe } } -void cs_prep_labels(VW::multi_ex& examples, std::vector& cb_labels, VW::cs_label& cs_labels, +void cs_prep_labels(VW::multi_ex& examples, std::vector& cb_labels, VW::cs_label& cs_labels, std::vector& prepped_cs_labels, uint64_t offset); template void cs_ldf_learn_or_predict(VW::LEARNER::multi_learner& base, VW::multi_ex& examples, - std::vector& cb_labels, VW::cs_label& cs_labels, std::vector& prepped_cs_labels, + std::vector& cb_labels, VW::cs_label& cs_labels, std::vector& prepped_cs_labels, bool predict_first, uint64_t offset, size_t id = 0) { VW_DBG(*examples[0]) << "cs_ldf_" << (is_learn ? "" : "") << ": ex=" << examples[0]->example_counter diff --git a/vowpalwabbit/core/include/vw/core/reductions/cats_tree.h b/vowpalwabbit/core/include/vw/core/reductions/cats_tree.h index 02b32646de2..ac9cb13c232 100644 --- a/vowpalwabbit/core/include/vw/core/reductions/cats_tree.h +++ b/vowpalwabbit/core/include/vw/core/reductions/cats_tree.h @@ -73,7 +73,7 @@ class cats_tree void init(uint32_t num_actions, uint32_t bandwidth); int32_t learner_count() const; uint32_t predict(LEARNER::single_learner& base, example& ec); - void init_node_costs(std::vector& ac); + void init_node_costs(std::vector& ac); const tree_node& get_sibling(const tree_node& tree_node); float return_cost(const tree_node& w); void learn(LEARNER::single_learner& base, example& ec); diff --git a/vowpalwabbit/core/include/vw/core/reductions/cb/cb_adf.h b/vowpalwabbit/core/include/vw/core/reductions/cb/cb_adf.h index 64c498f238d..c9135600996 100644 --- a/vowpalwabbit/core/include/vw/core/reductions/cb/cb_adf.h +++ b/vowpalwabbit/core/include/vw/core/reductions/cb/cb_adf.h @@ -22,7 +22,7 @@ VW::LEARNER::base_learner* cb_adf_setup(VW::setup_base_i& stack_builder); namespace CB_ADF // NOLINT { VW::example* test_adf_sequence(const VW::multi_ex& ec_seq); -CB::cb_class get_observed_cost_or_default_cb_adf(const VW::multi_ex& examples); +VW::cb_class get_observed_cost_or_default_cb_adf(const VW::multi_ex& examples); class cb_adf { public: @@ -54,8 +54,8 @@ class cb_adf gen_cs.cb_type == VW::cb_type_t::SM; } - CB::cb_class* known_cost() { return &gen_cs.known_cost; } - const CB::cb_class* known_cost() const { return &gen_cs.known_cost; } + VW::cb_class* known_cost() { return &gen_cs.known_cost; } + const VW::cb_class* known_cost() const { return &gen_cs.known_cost; } private: void learn_ips(VW::LEARNER::multi_learner& base, VW::multi_ex& examples); @@ -66,7 +66,7 @@ class cb_adf void learn_mtr(VW::LEARNER::multi_learner& base, VW::multi_ex& examples); private: - std::vector _cb_labels; + std::vector _cb_labels; VW::cs_label _cs_labels; std::vector _prepped_cs_labels; diff --git a/vowpalwabbit/core/include/vw/core/reductions/cb/cb_algs.h b/vowpalwabbit/core/include/vw/core/reductions/cb/cb_algs.h index 8dbbbe4535d..ccc9b470453 100644 --- a/vowpalwabbit/core/include/vw/core/reductions/cb/cb_algs.h +++ b/vowpalwabbit/core/include/vw/core/reductions/cb/cb_algs.h @@ -28,7 +28,7 @@ namespace CB_ALGS { template float get_cost_pred( - VW::LEARNER::single_learner* scorer, const CB::cb_class& known_cost, VW::example& ec, uint32_t index, uint32_t base) + VW::LEARNER::single_learner* scorer, const VW::cb_class& known_cost, VW::example& ec, uint32_t index, uint32_t base) { VW_DBG(ec) << "get_cost_pred:" << is_learn << std::endl; @@ -56,14 +56,14 @@ float get_cost_pred( } // IPS estimate -inline float get_cost_estimate(const CB::cb_class& observation, uint32_t action, float offset = 0.) +inline float get_cost_estimate(const VW::cb_class& observation, uint32_t action, float offset = 0.) { if (action == observation.action) { return (observation.cost - offset) / observation.probability; } return 0.; } // doubly robust estimate -inline float get_cost_estimate(const CB::cb_class& observation, const VW::cs_label& scores, uint32_t action) +inline float get_cost_estimate(const VW::cb_class& observation, const VW::cs_label& scores, uint32_t action) { for (auto& cl : scores.costs) { @@ -74,7 +74,7 @@ inline float get_cost_estimate(const CB::cb_class& observation, const VW::cs_lab } // IPS -inline float get_cost_estimate(const CB::label& ld, uint32_t action) +inline float get_cost_estimate(const VW::cb_label& ld, uint32_t action) { for (auto& cl : ld.costs) { @@ -92,7 +92,6 @@ inline float get_cost_estimate(const VW::action_score& a_s, float cost, uint32_t inline bool example_is_newline_not_header(VW::example const& ec) { - return (VW::example_is_newline(ec) && !CB::ec_is_example_header(ec)); + return (VW::example_is_newline(ec) && !VW::ec_is_example_header_cb(ec)); } - } // namespace CB_ALGS diff --git a/vowpalwabbit/core/include/vw/core/reductions/cb/cb_explore_adf_common.h b/vowpalwabbit/core/include/vw/core/reductions/cb/cb_explore_adf_common.h index e6051fc094e..a95dec04b78 100644 --- a/vowpalwabbit/core/include/vw/core/reductions/cb/cb_explore_adf_common.h +++ b/vowpalwabbit/core/include/vw/core/reductions/cb/cb_explore_adf_common.h @@ -13,7 +13,7 @@ // defined in the cc file (con: can't inline those functions) // - templatize all input parameters (con: no type safety) #include "vw/core/action_score.h" // used in sort_action_probs -#include "vw/core/cb.h" // required for CB::label +#include "vw/core/cb.h" // required for VW::cb_label #include "vw/core/example.h" // used in predict #include "vw/core/gen_cs_example.h" // required for GEN_CS::cb_to_cs_adf #include "vw/core/global_data.h" @@ -105,10 +105,10 @@ class cb_explore_adf_base ExploreType explore; private: - CB::cb_class _known_cost; + VW::cb_class _known_cost; // used in output_example - CB::label _action_label; - CB::label _empty_label; + VW::cb_label _action_label; + VW::cb_label _empty_label; VW::action_scores _saved_pred; std::unique_ptr _metrics; @@ -214,7 +214,7 @@ void cb_explore_adf_base::_update_stats( for (const auto& example : ec_seq) { - if (CB::ec_is_example_header(*example)) + if (VW::ec_is_example_header_cb(*example)) { num_features += (ec_seq.size() - 1) * (example->get_num_features() - example->feature_space[VW::details::CONSTANT_NAMESPACE].size()); @@ -287,8 +287,8 @@ void cb_explore_adf_base::_print_update( if (ec_seq.size() <= 0) { return; } bool labeled_example = (_known_cost.probability > 0); auto& ec = *ec_seq[0]; - if (labeled_example) { CB::print_update(all, !labeled_example, ec, &ec_seq, true, &_known_cost); } - else { CB::print_update(all, !labeled_example, ec, &ec_seq, true, nullptr); } + if (labeled_example) { VW::details::print_update_cb(all, !labeled_example, ec, &ec_seq, true, &_known_cost); } + else { VW::details::print_update_cb(all, !labeled_example, ec, &ec_seq, true, nullptr); } } template diff --git a/vowpalwabbit/core/include/vw/core/reductions/pmf_to_pdf.h b/vowpalwabbit/core/include/vw/core/reductions/pmf_to_pdf.h index 601c75f8d92..5b62bd5c9df 100644 --- a/vowpalwabbit/core/include/vw/core/reductions/pmf_to_pdf.h +++ b/vowpalwabbit/core/include/vw/core/reductions/pmf_to_pdf.h @@ -32,7 +32,7 @@ class pmf_to_pdf_reduction private: void transform_prediction(example& ec); - CB::label temp_lbl_cb; + VW::cb_label temp_lbl_cb; VW::action_scores temp_pred_a_s; }; } // namespace reductions diff --git a/vowpalwabbit/core/src/cb.cc b/vowpalwabbit/core/src/cb.cc index 3f3f48b5e14..8684bc88c8e 100644 --- a/vowpalwabbit/core/src/cb.cc +++ b/vowpalwabbit/core/src/cb.cc @@ -18,12 +18,8 @@ #include #include -using namespace VW::LEARNER; - -namespace CB -{ // This return value should be treated like an optional. If first is false then the second value should not be read. -std::pair get_observed_cost_cb(const label& ld) +std::pair VW::get_observed_cost_cb(const VW::cb_label& ld) { for (const auto& cl : ld.costs) { @@ -31,11 +27,11 @@ std::pair get_observed_cost_cb(const label& ld) } // Default value for cb_class does not have an observed cost. - return std::make_pair(false, CB::cb_class{}); + return std::make_pair(false, VW::cb_class{}); } -void parse_label(CB::label& ld, VW::label_parser_reuse_mem& reuse_mem, const std::vector& words, - VW::io::logger& logger) +static void parse_label_cb(VW::cb_label& ld, VW::label_parser_reuse_mem& reuse_mem, + const std::vector& words, VW::io::logger& logger) { ld.weight = 1.0; @@ -45,7 +41,7 @@ void parse_label(CB::label& ld, VW::label_parser_reuse_mem& reuse_mem, const std // :: | shared // for example "1:2:0.5" // action = 1, cost = 2, probability = 0.5 - cb_class f; + VW::cb_class f; VW::tokenize(':', word, reuse_mem.tokens); if (reuse_mem.tokens.empty() || reuse_mem.tokens.size() > 3) { THROW("malformed cost specification: " << word); } @@ -84,13 +80,13 @@ void parse_label(CB::label& ld, VW::label_parser_reuse_mem& reuse_mem, const std } } -VW::label_parser cb_label = { +VW::label_parser VW::cb_label_parser_global = { // default_label [](VW::polylabel& label) { label.cb.reset_to_default(); }, // parse_label [](VW::polylabel& label, VW::reduction_features& /*red_features*/, VW::label_parser_reuse_mem& reuse_mem, const VW::named_labels* /*ldict*/, const std::vector& words, VW::io::logger& logger) - { CB::parse_label(label.cb, reuse_mem, words, logger); }, + { ::parse_label_cb(label.cb, reuse_mem, words, logger); }, // cache_label [](const VW::polylabel& label, const VW::reduction_features& /*red_features*/, VW::io_buf& cache, const std::string& upstream_name, bool text) @@ -105,7 +101,7 @@ VW::label_parser cb_label = { // Label type VW::label_type_t::CB}; -bool ec_is_example_header(VW::example const& ec) // example headers just have "shared" +bool VW::ec_is_example_header_cb(VW::example const& ec) // example headers just have "shared" { const auto& costs = ec.l.cb.costs; if (costs.size() != 1) { return false; } @@ -113,7 +109,7 @@ bool ec_is_example_header(VW::example const& ec) // example headers just have " return false; } -std::string known_cost_to_str(const CB::cb_class* known_cost) +static std::string known_cost_to_str(const VW::cb_class* known_cost) { if (known_cost == nullptr) { return " known"; } @@ -123,8 +119,25 @@ std::string known_cost_to_str(const CB::cb_class* known_cost) return label_string.str(); } -void print_update(VW::workspace& all, bool is_test, const VW::example& ec, const VW::multi_ex* ec_seq, - bool action_scores, const CB::cb_class* known_cost) +bool VW::cb_label::is_test_label() const +{ + if (costs.empty()) { return true; } + for (const auto& cost : costs) + { + const auto probability = cost.probability; + if (FLT_MAX != cost.cost && probability > 0.) { return false; } + } + return true; +} +bool VW::cb_label::is_labeled() const { return !is_test_label(); } +void VW::cb_label::reset_to_default() +{ + costs.clear(); + weight = 1.f; +} + +void ::VW::details::print_update_cb(VW::workspace& all, bool is_test, const VW::example& ec, const VW::multi_ex* ec_seq, + bool action_scores, const VW::cb_class* known_cost) { if (all.sd->weighted_examples() >= all.sd->dump_interval && !all.quiet && !all.bfgs) { @@ -137,7 +150,7 @@ void print_update(VW::workspace& all, bool is_test, const VW::example& ec, const // TODO: code duplication csoaa.cc LabelDict::ec_is_example_header for (size_t i = 0; i < (*ec_seq).size(); i++) { - if (CB::ec_is_example_header(*(*ec_seq)[i])) + if (VW::ec_is_example_header_cb(*(*ec_seq)[i])) { num_features += (ec_seq->size() - 1) * ((*ec_seq)[i]->get_num_features() - (*ec_seq)[i]->feature_space[VW::details::CONSTANT_NAMESPACE].size()); @@ -168,38 +181,21 @@ void print_update(VW::workspace& all, bool is_test, const VW::example& ec, const } } } -bool label::is_test_label() const -{ - if (costs.empty()) { return true; } - for (const auto& cost : costs) - { - const auto probability = cost.probability; - if (FLT_MAX != cost.cost && probability > 0.) { return false; } - } - return true; -} -bool label::is_labeled() const { return !is_test_label(); } -void label::reset_to_default() -{ - costs.clear(); - weight = 1.f; -} -} // namespace CB -namespace CB_EVAL +namespace { -float weight(const CB_EVAL::label& ld) { return ld.event.weight; } +float weight_cb_eval(const VW::cb_eval_label& ld) { return ld.event.weight; } -void default_label(CB_EVAL::label& ld) +void default_label_cb_eval(VW::cb_eval_label& ld) { ld.event.reset_to_default(); ld.action = 0; } -bool test_label(const CB_EVAL::label& ld) { return ld.event.is_test_label(); } +bool test_label_cb_eval(const VW::cb_eval_label& ld) { return ld.event.is_test_label(); } -void parse_label(CB_EVAL::label& ld, VW::label_parser_reuse_mem& reuse_mem, const std::vector& words, - VW::io::logger& logger) +void parse_label_cb_eval(VW::cb_eval_label& ld, VW::label_parser_reuse_mem& reuse_mem, + const std::vector& words, VW::io::logger& logger) { if (words.size() < 2) THROW("Evaluation can not happen without an action and an exploration"); @@ -207,16 +203,17 @@ void parse_label(CB_EVAL::label& ld, VW::label_parser_reuse_mem& reuse_mem, cons // TODO - make this a span and there is no allocation const auto rest_of_tokens = std::vector(words.begin() + 1, words.end()); - CB::parse_label(ld.event, reuse_mem, rest_of_tokens, logger); + ::parse_label_cb(ld.event, reuse_mem, rest_of_tokens, logger); +} } -VW::label_parser cb_eval = { +VW::label_parser VW::cb_eval_label_parser_global = { // default_label - [](VW::polylabel& label) { CB_EVAL::default_label(label.cb_eval); }, + [](VW::polylabel& label) { default_label_cb_eval(label.cb_eval); }, // parse_label [](VW::polylabel& label, VW::reduction_features& /*red_features*/, VW::label_parser_reuse_mem& reuse_mem, const VW::named_labels* /*ldict*/, const std::vector& words, VW::io::logger& logger) - { CB_EVAL::parse_label(label.cb_eval, reuse_mem, words, logger); }, + { parse_label_cb_eval(label.cb_eval, reuse_mem, words, logger); }, // cache_label [](const VW::polylabel& label, const VW::reduction_features& /*red_features*/, VW::io_buf& cache, const std::string& upstream_name, bool text) @@ -225,19 +222,18 @@ VW::label_parser cb_eval = { [](VW::polylabel& label, VW::reduction_features& /*red_features*/, VW::io_buf& cache) { return VW::model_utils::read_model_field(cache, label.cb_eval); }, // get_weight - [](const VW::polylabel& /*label*/, const VW::reduction_features& /*red_features*/) { return 1.f; }, + [](const VW::polylabel& label, const VW::reduction_features& /*red_features*/) + { return weight_cb_eval(label.cb_eval); }, // test_label - [](const VW::polylabel& label) { return CB_EVAL::test_label(label.cb_eval); }, + [](const VW::polylabel& label) { return test_label_cb_eval(label.cb_eval); }, // Label type VW::label_type_t::CB_EVAL}; -} // namespace CB_EVAL - namespace VW { namespace model_utils { -size_t read_model_field(io_buf& io, CB::cb_class& cbc) +size_t read_model_field(io_buf& io, VW::cb_class& cbc) { size_t bytes = 0; bytes += read_model_field(io, cbc.cost); @@ -247,7 +243,7 @@ size_t read_model_field(io_buf& io, CB::cb_class& cbc) return bytes; } -size_t write_model_field(io_buf& io, const CB::cb_class& cbc, const std::string& upstream_name, bool text) +size_t write_model_field(io_buf& io, const VW::cb_class& cbc, const std::string& upstream_name, bool text) { size_t bytes = 0; bytes += write_model_field(io, cbc.cost, upstream_name + "_cost", text); @@ -257,7 +253,7 @@ size_t write_model_field(io_buf& io, const CB::cb_class& cbc, const std::string& return bytes; } -size_t read_model_field(io_buf& io, CB::label& cb) +size_t read_model_field(io_buf& io, VW::cb_label& cb) { size_t bytes = 0; bytes += read_model_field(io, cb.costs); @@ -265,7 +261,7 @@ size_t read_model_field(io_buf& io, CB::label& cb) return bytes; } -size_t write_model_field(io_buf& io, const CB::label& cb, const std::string& upstream_name, bool text) +size_t write_model_field(io_buf& io, const VW::cb_label& cb, const std::string& upstream_name, bool text) { size_t bytes = 0; bytes += write_model_field(io, cb.costs, upstream_name + "_costs", text); @@ -273,7 +269,7 @@ size_t write_model_field(io_buf& io, const CB::label& cb, const std::string& ups return bytes; } -size_t read_model_field(io_buf& io, CB_EVAL::label& cbe) +size_t read_model_field(io_buf& io, VW::cb_eval_label& cbe) { size_t bytes = 0; bytes += read_model_field(io, cbe.action); @@ -281,7 +277,7 @@ size_t read_model_field(io_buf& io, CB_EVAL::label& cbe) return bytes; } -size_t write_model_field(io_buf& io, const CB_EVAL::label& cbe, const std::string& upstream_name, bool text) +size_t write_model_field(io_buf& io, const VW::cb_eval_label& cbe, const std::string& upstream_name, bool text) { size_t bytes = 0; bytes += write_model_field(io, cbe.action, upstream_name + "_action", text); diff --git a/vowpalwabbit/core/src/gen_cs_example.cc b/vowpalwabbit/core/src/gen_cs_example.cc index 09dd59b8e28..79b9468211b 100644 --- a/vowpalwabbit/core/src/gen_cs_example.cc +++ b/vowpalwabbit/core/src/gen_cs_example.cc @@ -33,7 +33,7 @@ void gen_cs_example_ips(const VW::multi_ex& examples, VW::cs_label& cs_labels, V cs_labels.costs.clear(); for (uint32_t i = 0; i < examples.size(); i++) { - const CB::label& ld = examples[i]->l.cb; + const VW::cb_label& ld = examples[i]->l.cb; VW::cs_class wc = {0., i, 0., 0.}; if (ld.costs.size() == 1 && ld.costs[0].cost != FLT_MAX) @@ -50,7 +50,7 @@ void gen_cs_example_dm(const VW::multi_ex& examples, VW::cs_label& cs_labels) cs_labels.costs.clear(); for (uint32_t i = 0; i < examples.size(); i++) { - const CB::label& ld = examples[i]->l.cb; + const VW::cb_label& ld = examples[i]->l.cb; VW::cs_class wc = {0., i, 0., 0.}; if (ld.costs.size() == 1 && ld.costs[0].cost != FLT_MAX) { wc.x = ld.costs[0].cost; } @@ -70,7 +70,7 @@ void gen_cs_test_example(const VW::multi_ex& examples, VW::cs_label& cs_labels) } // single line version -void gen_cs_example_ips(cb_to_cs& c, const CB::label& ld, VW::cs_label& cs_ld, VW::io::logger& logger, float clip_p) +void gen_cs_example_ips(cb_to_cs& c, const VW::cb_label& ld, VW::cs_label& cs_ld, VW::io::logger& logger, float clip_p) { // this implements the inverse propensity score method, where cost are importance weighted by the probability of the // chosen action generate cost-sensitive example @@ -133,7 +133,7 @@ void gen_cs_example_mtr(cb_to_cs_adf& c, VW::multi_ex& ec_seq, VW::cs_label& cs_ cs_labels.costs.clear(); for (size_t i = 0; i < ec_seq.size(); i++) { - CB::label& ld = ec_seq[i]->l.cb; + VW::cb_label& ld = ec_seq[i]->l.cb; VW::cs_class wc = {0, 0, 0, 0}; @@ -169,7 +169,7 @@ void gen_cs_example_sm(VW::multi_ex&, uint32_t chosen_action, float sign_offset, } } -void cs_prep_labels(VW::multi_ex& examples, std::vector& cb_labels, VW::cs_label& cs_labels, +void cs_prep_labels(VW::multi_ex& examples, std::vector& cb_labels, VW::cs_label& cs_labels, std::vector& prepped_cs_labels, uint64_t offset) { cb_labels.clear(); diff --git a/vowpalwabbit/core/src/label_parser.cc b/vowpalwabbit/core/src/label_parser.cc index 6de92d974bc..3c72b62e0b2 100644 --- a/vowpalwabbit/core/src/label_parser.cc +++ b/vowpalwabbit/core/src/label_parser.cc @@ -23,10 +23,10 @@ VW::label_parser VW::get_label_parser(VW::label_type_t label_type) return VW::simple_label_parser_global; case VW::label_type_t::CB: - return CB::cb_label; + return VW::cb_label_parser_global; case VW::label_type_t::CB_EVAL: - return CB_EVAL::cb_eval; + return VW::cb_eval_label_parser_global; case VW::label_type_t::CS: return VW::cs_label_parser_global; diff --git a/vowpalwabbit/core/src/learner.cc b/vowpalwabbit/core/src/learner.cc index cc42c1a6333..d183ed12e7c 100644 --- a/vowpalwabbit/core/src/learner.cc +++ b/vowpalwabbit/core/src/learner.cc @@ -306,7 +306,7 @@ void generic_driver_onethread(VW::workspace& all) float VW::LEARNER::details::recur_sensitivity(void*, base_learner& base, example& ec) { return base.sensitivity(ec); } bool ec_is_example_header(const example& ec, label_type_t label_type) { - if (label_type == VW::label_type_t::CB) { return CB::ec_is_example_header(ec); } + if (label_type == VW::label_type_t::CB) { return VW::ec_is_example_header_cb(ec); } else if (label_type == VW::label_type_t::CCB) { return reductions::ccb::ec_is_example_header(ec); } else if (label_type == VW::label_type_t::CS) { return VW::is_cs_example_header(ec); } return false; diff --git a/vowpalwabbit/core/src/reductions/automl.cc b/vowpalwabbit/core/src/reductions/automl.cc index 9e63d559ff0..6c0fcf50ee2 100644 --- a/vowpalwabbit/core/src/reductions/automl.cc +++ b/vowpalwabbit/core/src/reductions/automl.cc @@ -54,7 +54,7 @@ void predict_automl(automl& data, multi_learner& base, VW::multi_ex& ec) template void learn_automl(automl& data, multi_learner& base, VW::multi_ex& ec) { - CB::cb_class logged{}; + VW::cb_class logged{}; uint64_t labelled_action = 0; const auto it = std::find_if(ec.begin(), ec.end(), [](VW::example* item) { return !item->l.cb.costs.empty(); }); diff --git a/vowpalwabbit/core/src/reductions/baseline_challenger_cb.cc b/vowpalwabbit/core/src/reductions/baseline_challenger_cb.cc index 9ce662e8c4a..ed1afcec812 100644 --- a/vowpalwabbit/core/src/reductions/baseline_challenger_cb.cc +++ b/vowpalwabbit/core/src/reductions/baseline_challenger_cb.cc @@ -85,7 +85,7 @@ class baseline_challenger_data if (lbl_example != examples.end()) { const auto labelled_action = static_cast(std::distance(examples.begin(), lbl_example)); - const CB::cb_class& logged = (*lbl_example)->l.cb.costs[0]; + const VW::cb_class& logged = (*lbl_example)->l.cb.costs[0]; double r = -logged.cost; double w = (labelled_action == chosen_action ? 1 : 0) / logged.probability; diff --git a/vowpalwabbit/core/src/reductions/cats_tree.cc b/vowpalwabbit/core/src/reductions/cats_tree.cc index eb4a29e6164..2fc7fa960d7 100644 --- a/vowpalwabbit/core/src/reductions/cats_tree.cc +++ b/vowpalwabbit/core/src/reductions/cats_tree.cc @@ -22,8 +22,8 @@ using namespace VW::config; using namespace VW::LEARNER; -using CB::cb_class; using std::vector; +using VW::cb_class; #undef VW_DEBUG_LOG #define VW_DEBUG_LOG vw_dbg::CATS_TREE @@ -162,7 +162,7 @@ uint32_t cats_tree::predict(LEARNER::single_learner& base, example& ec) // Handle degenerate cases of zero node trees if (_binary_tree.leaf_node_count() == 0) { return 0; } - CB::label saved_label = std::move(ec.l.cb); + VW::cb_label saved_label = std::move(ec.l.cb); ec.l.simple.label = std::numeric_limits::max(); // says it is a test example auto cur_node = nodes[0]; @@ -369,6 +369,6 @@ VW::LEARNER::base_learner* VW::reductions::cats_tree_setup(VW::setup_base_i& sta .set_output_prediction_type(VW::prediction_type_t::MULTICLASS) .set_input_label_type(VW::label_type_t::CB) .build(); - all.example_parser->lbl_parser = CB::cb_label; + all.example_parser->lbl_parser = VW::cb_label_parser_global; return make_base(*l); } diff --git a/vowpalwabbit/core/src/reductions/cb/cb_adf.cc b/vowpalwabbit/core/src/reductions/cb/cb_adf.cc index b776a711cde..ed29de4a4ad 100644 --- a/vowpalwabbit/core/src/reductions/cb/cb_adf.cc +++ b/vowpalwabbit/core/src/reductions/cb/cb_adf.cc @@ -22,7 +22,6 @@ #include "vw/io/logger.h" using namespace VW::LEARNER; -using namespace CB; using namespace GEN_CS; using namespace CB_ALGS; using namespace VW::config; @@ -30,12 +29,12 @@ using namespace exploration; namespace CB_ADF { -cb_class get_observed_cost_or_default_cb_adf(const VW::multi_ex& examples) +VW::cb_class get_observed_cost_or_default_cb_adf(const VW::multi_ex& examples) { bool found = false; uint32_t found_index = 0; uint32_t i = 0; - CB::cb_class known_cost; + VW::cb_class known_cost; for (const auto* example_ptr : examples) { @@ -125,7 +124,7 @@ void cb_adf::learn_sm(multi_learner& base, VW::multi_ex& examples) for (uint32_t i = 0; i < examples.size(); i++) { - CB::label ld = examples[i]->l.cb; + VW::cb_label ld = examples[i]->l.cb; if (ld.costs.size() == 1 && ld.costs[0].cost != FLT_MAX) { chosen_action = i; @@ -329,8 +328,8 @@ void print_update_cb_adf(VW::workspace& all, VW::shared_data& /* sd */, const CB const bool labeled_example = data.gen_cs.known_cost.probability > 0; const auto& ec = *ec_seq.front(); - if (labeled_example) { CB::print_update(all, !labeled_example, ec, &ec_seq, true, data.known_cost()); } - else { CB::print_update(all, !labeled_example, ec, &ec_seq, true, nullptr); } + if (labeled_example) { VW::details::print_update_cb(all, !labeled_example, ec, &ec_seq, true, data.known_cost()); } + else { VW::details::print_update_cb(all, !labeled_example, ec, &ec_seq, true, nullptr); } } void save_load(CB_ADF::cb_adf& c, VW::io_buf& model_file, bool read, bool text) @@ -463,7 +462,7 @@ VW::LEARNER::base_learner* VW::reductions::cb_adf_setup(VW::setup_base_i& stack_ auto ld = VW::make_unique(cb_type, rank_all, clip_p, no_predict, &all); auto base = as_multiline(stack_builder.setup_base_learner()); - all.example_parser->lbl_parser = CB::cb_label; + all.example_parser->lbl_parser = VW::cb_label_parser_global; CB_ADF::cb_adf* bare = ld.get(); bool lrp = ld->learn_returns_prediction(); diff --git a/vowpalwabbit/core/src/reductions/cb/cb_algs.cc b/vowpalwabbit/core/src/reductions/cb/cb_algs.cc index 27253439b2d..32c9ca78f72 100644 --- a/vowpalwabbit/core/src/reductions/cb/cb_algs.cc +++ b/vowpalwabbit/core/src/reductions/cb/cb_algs.cc @@ -18,7 +18,6 @@ using namespace VW::LEARNER; using namespace VW::config; -using namespace CB; using namespace GEN_CS; namespace @@ -39,7 +38,7 @@ void predict_or_learn(cb& data, single_learner& base, VW::example& ec) auto optional_cost = get_observed_cost_cb(ec.l.cb); // cost observed, not default if (optional_cost.first) { c.known_cost = optional_cost.second; } - else { c.known_cost = CB::cb_class{}; } + else { c.known_cost = VW::cb_class{}; } // cost observed, not default if (optional_cost.first && (c.known_cost.action < 1 || c.known_cost.action > c.num_actions)) @@ -70,7 +69,7 @@ void learn_eval(cb& data, single_learner&, VW::example& ec) auto optional_cost = get_observed_cost_cb(ec.l.cb_eval.event); // cost observed, not default if (optional_cost.first) { c.known_cost = optional_cost.second; } - else { c.known_cost = CB::cb_class{}; } + else { c.known_cost = VW::cb_class{}; } gen_cs_example(c, ec, ec.l.cb_eval.event, ec.l.cs, data.logger); for (size_t i = 0; i < ec.l.cb_eval.event.costs.size(); i++) @@ -110,7 +109,7 @@ void output_example_prediction_cb_algs( std::stringstream output_string_stream; for (unsigned int i = 0; i < ld.costs.size(); i++) { - cb_class cl = ld.costs[i]; + VW::cb_class cl = ld.costs[i]; if (i > 0) { output_string_stream << ' '; } output_string_stream << cl.action << ':' << cl.partial_prediction; } @@ -126,8 +125,8 @@ void print_update_cb_algs( const auto& c = data.cbcs; bool is_ld_test_label = ld.is_test_label(); - if (!is_ld_test_label) { print_update(all, is_ld_test_label, ec, nullptr, false, &c.known_cost); } - else { print_update(all, is_ld_test_label, ec, nullptr, false, nullptr); } + if (!is_ld_test_label) { VW::details::print_update_cb(all, is_ld_test_label, ec, nullptr, false, &c.known_cost); } + else { VW::details::print_update_cb(all, is_ld_test_label, ec, nullptr, false, nullptr); } } } // namespace @@ -197,9 +196,9 @@ base_learner* VW::reductions::cb_algs_setup(VW::setup_base_i& stack_builder) options.insert("csoaa", ss.str()); } - auto base = as_singleline(stack_builder.setup_base_learner()); - if (eval) { all.example_parser->lbl_parser = CB_EVAL::cb_eval; } - else { all.example_parser->lbl_parser = CB::cb_label; } + auto* base = as_singleline(stack_builder.setup_base_learner()); + if (eval) { all.example_parser->lbl_parser = VW::cb_eval_label_parser_global; } + else { all.example_parser->lbl_parser = VW::cb_label_parser_global; } c.scorer = VW::LEARNER::as_singleline(base->get_learner_by_name_prefix("scorer")); std::string name_addition = eval ? "-eval" : ""; diff --git a/vowpalwabbit/core/src/reductions/cb/cb_dro.cc b/vowpalwabbit/core/src/reductions/cb/cb_dro.cc index 8f299bd440d..57e584c5e5a 100644 --- a/vowpalwabbit/core/src/reductions/cb/cb_dro.cc +++ b/vowpalwabbit/core/src/reductions/cb/cb_dro.cc @@ -49,7 +49,7 @@ class cb_dro_data if (it != examples.end()) { - const CB::cb_class logged = (*it)->l.cb.costs[0]; + const VW::cb_class logged = (*it)->l.cb.costs[0]; const uint32_t labelled_action = static_cast(std::distance(examples.begin(), it)); const auto& action_scores = examples[0]->pred.a_s; diff --git a/vowpalwabbit/core/src/reductions/cb/cb_explore.cc b/vowpalwabbit/core/src/reductions/cb/cb_explore.cc index 500c2106628..746cb32c13e 100644 --- a/vowpalwabbit/core/src/reductions/cb/cb_explore.cc +++ b/vowpalwabbit/core/src/reductions/cb/cb_explore.cc @@ -45,7 +45,7 @@ class cb_explore VW::v_array preds; VW::v_array cover_probs; - CB::label cb_label; + VW::cb_label cb_label; VW::cs_label cs_label; VW::cs_label second_cs_label; @@ -206,7 +206,7 @@ void predict_or_learn_cover(cb_explore& data, single_learner& base, VW::example& auto optional_cost = get_observed_cost_cb(data.cb_label); // cost observed, not default if (optional_cost.first) { data.cbcs.known_cost = optional_cost.second; } - else { data.cbcs.known_cost = CB::cb_class{}; } + else { data.cbcs.known_cost = VW::cb_class{}; } gen_cs_example(data.cbcs, ec, data.cb_label, data.cs_label, data.logger); for (uint32_t i = 0; i < num_actions; i++) { probabilities[i] = 0.f; } @@ -254,13 +254,13 @@ void print_update_cb_explore( } } -float calc_loss(const cb_explore& data, const VW::example& ec, const CB::label& ld) +float calc_loss(const cb_explore& data, const VW::example& ec, const VW::cb_label& ld) { float loss = 0.f; const cb_to_cs& c = data.cbcs; - auto optional_cost = CB::get_observed_cost_cb(ld); + auto optional_cost = VW::get_observed_cost_cb(ld); // cost observed, not default if (optional_cost.first == true) { diff --git a/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_bag.cc b/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_bag.cc index 5b59346c368..2ec918a8078 100644 --- a/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_bag.cc +++ b/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_bag.cc @@ -196,7 +196,7 @@ VW::LEARNER::base_learner* VW::reductions::cb_explore_adf_bag_setup(VW::setup_ba size_t problem_multiplier = VW::cast_to_smaller_type(bag_size); VW::LEARNER::multi_learner* base = as_multiline(stack_builder.setup_base_learner()); - all.example_parser->lbl_parser = CB::cb_label; + all.example_parser->lbl_parser = VW::cb_label_parser_global; using explore_type = cb_explore_adf_base; auto data = VW::make_unique(all.global_metrics.are_metrics_enabled(), epsilon, diff --git a/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_cover.cc b/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_cover.cc index 836cc41ed3b..abb88f2c642 100644 --- a/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_cover.cc +++ b/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_cover.cc @@ -67,7 +67,7 @@ class cb_explore_adf_cover VW::cs_label _cs_labels; VW::cs_label _cs_labels_2; std::vector _prepped_cs_labels; - std::vector _cb_labels; + std::vector _cb_labels; template void predict_or_learn_impl(VW::LEARNER::multi_learner& base, VW::multi_ex& examples); }; @@ -309,7 +309,7 @@ VW::LEARNER::base_learner* VW::reductions::cb_explore_adf_cover_setup(VW::setup_ if (cb_type == VW::cb_type_t::MTR) { problem_multiplier *= 2; } VW::LEARNER::multi_learner* base = VW::LEARNER::as_multiline(stack_builder.setup_base_learner()); - all.example_parser->lbl_parser = CB::cb_label; + all.example_parser->lbl_parser = VW::cb_label_parser_global; bool epsilon_decay; if (options.was_supplied("epsilon")) diff --git a/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_first.cc b/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_first.cc index 6e28e0e5e74..60984f8dcb4 100644 --- a/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_first.cc +++ b/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_first.cc @@ -120,7 +120,7 @@ VW::LEARNER::base_learner* VW::reductions::cb_explore_adf_first_setup(VW::setup_ size_t problem_multiplier = 1; multi_learner* base = as_multiline(stack_builder.setup_base_learner()); - all.example_parser->lbl_parser = CB::cb_label; + all.example_parser->lbl_parser = VW::cb_label_parser_global; using explore_type = cb_explore_adf_base; auto data = VW::make_unique( diff --git a/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_greedy.cc b/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_greedy.cc index a6f3cc91cc2..ba5a37ae6e1 100644 --- a/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_greedy.cc +++ b/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_greedy.cc @@ -131,7 +131,7 @@ VW::LEARNER::base_learner* VW::reductions::cb_explore_adf_greedy_setup(VW::setup size_t problem_multiplier = 1; VW::LEARNER::multi_learner* base = as_multiline(stack_builder.setup_base_learner()); - all.example_parser->lbl_parser = CB::cb_label; + all.example_parser->lbl_parser = VW::cb_label_parser_global; using explore_type = cb_explore_adf_base; auto data = VW::make_unique(all.global_metrics.are_metrics_enabled(), epsilon, first_only); diff --git a/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_large_action_space.cc b/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_large_action_space.cc index db2e5b4f6b8..28293313628 100644 --- a/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_large_action_space.cc +++ b/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_large_action_space.cc @@ -63,7 +63,7 @@ bool _test_only_generate_A(VW::workspace* _all, const multi_ex& examples, std::v _triplets.clear(); for (auto* ex : examples) { - assert(!CB::ec_is_example_header(*ex)); + assert(!VW::ec_is_example_header_cb(*ex)); auto& red_features = ex->ex_reduction_features.template get(); auto* shared_example = red_features.shared_example; @@ -403,7 +403,7 @@ VW::LEARNER::base_learner* VW::reductions::cb_explore_adf_large_action_space_set } VW::LEARNER::multi_learner* base = as_multiline(stack_builder.setup_base_learner()); - all.example_parser->lbl_parser = CB::cb_label; + all.example_parser->lbl_parser = VW::cb_label_parser_global; if (use_two_pass_svd_impl) { diff --git a/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_regcb.cc b/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_regcb.cc index 133e1202800..8e617907e43 100644 --- a/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_regcb.cc +++ b/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_regcb.cc @@ -69,7 +69,7 @@ class cb_explore_adf_regcb // for backing up cb example data when computing sensitivities std::vector _ex_as; - std::vector> _ex_costs; + std::vector> _ex_costs; }; cb_explore_adf_regcb::cb_explore_adf_regcb(bool regcbopt, float c0, bool first_only, float min_cb_cost, @@ -219,7 +219,7 @@ void cb_explore_adf_regcb::learn_impl(multi_learner& base, VW::multi_ex& example VW::v_array preds = std::move(examples[0]->pred.a_s); for (size_t i = 0; i < examples.size() - 1; ++i) { - CB::label& ld = examples[i]->l.cb; + VW::cb_label& ld = examples[i]->l.cb; if (ld.costs.size() == 1) { ld.costs[0].probability = 1.f; // no importance weighting @@ -301,7 +301,7 @@ VW::LEARNER::base_learner* VW::reductions::cb_explore_adf_regcb_setup(VW::setup_ size_t problem_multiplier = 1; multi_learner* base = as_multiline(stack_builder.setup_base_learner()); - all.example_parser->lbl_parser = CB::cb_label; + all.example_parser->lbl_parser = VW::cb_label_parser_global; using explore_type = cb_explore_adf_base; auto data = VW::make_unique( diff --git a/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_rnd.cc b/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_rnd.cc index a8ee14503b4..f493dc5aa90 100644 --- a/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_rnd.cc +++ b/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_rnd.cc @@ -70,7 +70,7 @@ class cb_explore_adf_rnd std::vector _bonuses; std::vector _initials; - CB::cb_class _save_class; + VW::cb_class _save_class; template void predict_or_learn_impl(multi_learner& base, VW::multi_ex& examples); @@ -302,7 +302,7 @@ VW::LEARNER::base_learner* VW::reductions::cb_explore_adf_rnd_setup(VW::setup_ba size_t problem_multiplier = 1 + numrnd; multi_learner* base = as_multiline(stack_builder.setup_base_learner()); - all.example_parser->lbl_parser = CB::cb_label; + all.example_parser->lbl_parser = VW::cb_label_parser_global; using explore_type = cb_explore_adf_base; auto data = VW::make_unique(all.global_metrics.are_metrics_enabled(), epsilon, alpha, invlambda, numrnd, diff --git a/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_softmax.cc b/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_softmax.cc index 22d84581133..f99b48efd2e 100644 --- a/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_softmax.cc +++ b/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_softmax.cc @@ -91,7 +91,7 @@ VW::LEARNER::base_learner* VW::reductions::cb_explore_adf_softmax_setup(VW::setu size_t problem_multiplier = 1; VW::LEARNER::multi_learner* base = as_multiline(stack_builder.setup_base_learner()); - all.example_parser->lbl_parser = CB::cb_label; + all.example_parser->lbl_parser = VW::cb_label_parser_global; using explore_type = cb_explore_adf_base; auto data = VW::make_unique(all.global_metrics.are_metrics_enabled(), epsilon, lambda); diff --git a/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_squarecb.cc b/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_squarecb.cc index c16b36bd73a..a4fc04bbb81 100644 --- a/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_squarecb.cc +++ b/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_squarecb.cc @@ -71,7 +71,7 @@ class cb_explore_adf_squarecb // for backing up cb example data when computing sensitivities std::vector _ex_as; - std::vector> _ex_costs; + std::vector> _ex_costs; void get_cost_ranges(float delta, multi_learner& base, VW::multi_ex& examples, bool min_only); float binary_search(float fhat, float delta, float sens, float tol = 1e-6); }; @@ -275,7 +275,7 @@ void cb_explore_adf_squarecb::learn(multi_learner& base, VW::multi_ex& examples) VW::v_array preds = std::move(examples[0]->pred.a_s); for (size_t i = 0; i < examples.size() - 1; ++i) { - CB::label& ld = examples[i]->l.cb; + VW::cb_label& ld = examples[i]->l.cb; if (ld.costs.size() == 1) { ld.costs[0].probability = 1.f; // no importance weighting @@ -379,7 +379,7 @@ VW::LEARNER::base_learner* VW::reductions::cb_explore_adf_squarecb_setup(VW::set size_t problem_multiplier = 1; multi_learner* base = as_multiline(stack_builder.setup_base_learner()); - all.example_parser->lbl_parser = CB::cb_label; + all.example_parser->lbl_parser = VW::cb_label_parser_global; if (epsilon < 0.0 || epsilon > 1.0) { THROW("The value of epsilon must be in [0,1]"); } diff --git a/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_synthcover.cc b/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_synthcover.cc index d98e34c47f6..0b733de9021 100644 --- a/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_synthcover.cc +++ b/vowpalwabbit/core/src/reductions/cb/cb_explore_adf_synthcover.cc @@ -82,7 +82,7 @@ void cb_explore_adf_synthcover::predict_or_learn_impl(VW::LEARNER::multi_learner if (it != examples.end()) { - const CB::cb_class logged = (*it)->l.cb.costs[0]; + const VW::cb_class logged = (*it)->l.cb.costs[0]; _min_cost = std::min(logged.cost, _min_cost); _max_cost = std::max(logged.cost, _max_cost); @@ -197,7 +197,7 @@ VW::LEARNER::base_learner* VW::reductions::cb_explore_adf_synthcover_setup(VW::s size_t problem_multiplier = 1; VW::LEARNER::multi_learner* base = as_multiline(stack_builder.setup_base_learner()); - all.example_parser->lbl_parser = CB::cb_label; + all.example_parser->lbl_parser = VW::cb_label_parser_global; using explore_type = cb_explore_adf_base; auto data = VW::make_unique(all.global_metrics.are_metrics_enabled(), epsilon, psi, diff --git a/vowpalwabbit/core/src/reductions/cb/cb_to_cb_adf.cc b/vowpalwabbit/core/src/reductions/cb/cb_to_cb_adf.cc index 7676b093cdc..dda283bb11b 100644 --- a/vowpalwabbit/core/src/reductions/cb/cb_to_cb_adf.cc +++ b/vowpalwabbit/core/src/reductions/cb/cb_to_cb_adf.cc @@ -30,8 +30,8 @@ void predict_or_learn(cb_to_cb_adf& data, multi_learner& base, VW::example& ec) { data.adf_data.copy_example_to_adf(*data.weights, ec); - CB::label backup_ld; - CB::label new_ld; + VW::cb_label backup_ld; + VW::cb_label new_ld; bool is_test_label = ec.l.cb.is_test_label(); uint32_t chosen_action = 0; diff --git a/vowpalwabbit/core/src/reductions/cb/cbify.cc b/vowpalwabbit/core/src/reductions/cb/cbify.cc index a1b12abaa85..03e44b0cb65 100644 --- a/vowpalwabbit/core/src/reductions/cb/cbify.cc +++ b/vowpalwabbit/core/src/reductions/cb/cbify.cc @@ -121,7 +121,7 @@ class cbify_reg class cbify { public: - CB::label cb_label; + VW::cb_label cb_label; uint64_t app_seed = 0; VW::action_scores a_s; cbify_reg regression_data; @@ -137,7 +137,7 @@ class cbify // for ldf inputs std::vector> cs_costs; - std::vector> cb_costs; + std::vector> cb_costs; std::vector cb_as; }; @@ -219,7 +219,7 @@ void predict_or_learn_regression_discrete(cbify& data, single_learner& base, VW: data.app_seed + data.example_counter++, begin_scores(ec.pred.a_s), end_scores(ec.pred.a_s), chosen_action)) THROW("Failed to sample from pdf"); - CB::cb_class cb; + VW::cb_class cb; cb.action = chosen_action + 1; cb.probability = ec.pred.a_s[chosen_action].score; @@ -368,7 +368,7 @@ void predict_or_learn(cbify& data, single_learner& base, VW::example& ec) // Create a new cb label const auto action = chosen_action + 1; const auto cost = use_cs ? loss_cs(data, csl.costs, action) : loss(data, ld.label, action); - ec.l.cb.costs.push_back(CB::cb_class{ + ec.l.cb.costs.push_back(VW::cb_class{ cost, action, // action ec.pred.a_s[chosen_action].score // probability @@ -411,7 +411,7 @@ void learn_adf(cbify& data, multi_learner& base, VW::example& ec) if (use_cs) { csl = ec.l.cs; } else { ld = ec.l.multi; } - CB::cb_class cl; + VW::cb_class cl; cl.action = out_ec.pred.a_s[data.chosen_action].action + 1; cl.probability = out_ec.pred.a_s[data.chosen_action].score; @@ -467,7 +467,7 @@ void do_actual_predict_ldf(cbify& data, multi_learner& base, VW::multi_ex& ec_se void do_actual_learning_ldf(cbify& data, multi_learner& base, VW::multi_ex& ec_seq) { - CB::cb_class cl; + VW::cb_class cl; cl.action = data.cb_as[0][data.chosen_action].action + 1; cl.probability = data.cb_as[0][data.chosen_action].score; diff --git a/vowpalwabbit/core/src/reductions/cb/details/large_action/two_pass_svd_impl.cc b/vowpalwabbit/core/src/reductions/cb/details/large_action/two_pass_svd_impl.cc index a2bb6750f90..6059bdd50dd 100644 --- a/vowpalwabbit/core/src/reductions/cb/details/large_action/two_pass_svd_impl.cc +++ b/vowpalwabbit/core/src/reductions/cb/details/large_action/two_pass_svd_impl.cc @@ -84,7 +84,7 @@ bool two_pass_svd_impl::generate_Y(const multi_ex& examples, const std::vectorex_reduction_features.template get(); auto* shared_example = red_features.shared_example; @@ -140,7 +140,7 @@ void two_pass_svd_impl::generate_B(const multi_ex& examples, const std::vectorex_reduction_features.template get(); auto* shared_example = red_features.shared_example; diff --git a/vowpalwabbit/core/src/reductions/cb/warm_cb.cc b/vowpalwabbit/core/src/reductions/cb/warm_cb.cc index d9ce3e49c38..d66b2fc68c3 100644 --- a/vowpalwabbit/core/src/reductions/cb/warm_cb.cc +++ b/vowpalwabbit/core/src/reductions/cb/warm_cb.cc @@ -45,7 +45,7 @@ namespace class warm_cb { public: - CB::label cb_label; + VW::cb_label cb_label; uint64_t app_seed = 0; VW::action_scores a_s; // used as the seed @@ -77,7 +77,7 @@ class warm_cb std::vector lambdas; VW::action_scores a_s_adf; std::vector cumulative_costs; - CB::cb_class cl_adf; + VW::cb_class cl_adf; uint32_t ws_train_size = 0; uint32_t ws_vali_size = 0; VW::multi_ex ws_vali; @@ -87,7 +87,7 @@ class warm_cb VW::multiclass_label mc_label; VW::cs_label cs_label; std::vector csls; - std::vector cbls; + std::vector cbls; bool use_cs = 0; ~warm_cb() @@ -282,7 +282,7 @@ uint32_t predict_sublearner_adf(warm_cb& data, multi_learner& base, VW::example& void accumu_costs_iv_adf(warm_cb& data, multi_learner& base, VW::example& ec) { - CB::cb_class& cl = data.cl_adf; + VW::cb_class& cl = data.cl_adf; // IPS for approximating the cumulative costs for all lambdas for (uint32_t i = 0; i < data.choices_lambda; i++) { diff --git a/vowpalwabbit/core/src/reductions/conditional_contextual_bandit.cc b/vowpalwabbit/core/src/reductions/conditional_contextual_bandit.cc index 795d339dd8e..b0d8f5d889e 100644 --- a/vowpalwabbit/core/src/reductions/conditional_contextual_bandit.cc +++ b/vowpalwabbit/core/src/reductions/conditional_contextual_bandit.cc @@ -65,7 +65,7 @@ class ccb_data VW::example* shared = nullptr; VW::multi_ex actions, slots; std::vector origin_index; - CB::cb_class cb_label; + VW::cb_class cb_label; std::vector exclude_list, include_list; std::vector stored_labels; size_t action_with_label = 0; @@ -82,7 +82,7 @@ class ccb_data bool all_slots_loss_report = false; bool no_pred = false; - VW::vector_pool cb_label_pool; + VW::vector_pool cb_label_pool; VW::v_array_pool action_score_pool; VW::version_struct model_file_version; @@ -137,7 +137,7 @@ bool split_multi_example_and_stash_labels(const VW::multi_ex& examples, ccb_data void create_cb_labels(ccb_data& data) { data.cb_label_pool.acquire_object(data.shared->l.cb.costs); - data.shared->l.cb.costs.push_back(CB::cb_class{}); + data.shared->l.cb.costs.push_back(VW::cb_class{}); for (VW::example* action : data.actions) { data.cb_label_pool.acquire_object(action->l.cb.costs); } data.shared->l.cb.weight = 1.0; } @@ -190,7 +190,7 @@ void exclude_chosen_action(ccb_data& data, const VW::multi_ex& examples) int32_t action_index = -1; for (size_t i = 0; i < examples.size(); i++) { - const CB::label& ld = examples[i]->l.cb; + const VW::cb_label& ld = examples[i]->l.cb; if (ld.costs.size() == 1 && ld.costs[0].cost != FLT_MAX) { action_index = static_cast(i) - 1; /* un-1-index for shared */ @@ -485,7 +485,7 @@ void learn_or_predict(ccb_data& data, multi_learner& base, VW::multi_ex& example << "slot:" << slot_id << " " << ccb_decision_to_string(data) << std::endl; for (const auto& ex : data.cb_ex) { - if (CB::ec_is_example_header(*ex)) { slot->num_features = (data.cb_ex.size() - 1) * ex->num_features; } + if (VW::ec_is_example_header_cb(*ex)) { slot->num_features = (data.cb_ex.size() - 1) * ex->num_features; } else { slot->num_features += ex->num_features; diff --git a/vowpalwabbit/core/src/reductions/details/automl/automl_impl.cc b/vowpalwabbit/core/src/reductions/details/automl/automl_impl.cc index 0e523b226f5..7cc95347e07 100644 --- a/vowpalwabbit/core/src/reductions/details/automl/automl_impl.cc +++ b/vowpalwabbit/core/src/reductions/details/automl/automl_impl.cc @@ -368,7 +368,7 @@ template class interaction_config_manager, VW::estima template void automl::one_step( - LEARNER::multi_learner& base, multi_ex& ec, CB::cb_class& logged, uint64_t labelled_action) + LEARNER::multi_learner& base, multi_ex& ec, VW::cb_class& logged, uint64_t labelled_action) { cm->total_learn_count++; cm->process_example(ec); @@ -379,7 +379,7 @@ void automl::one_step( template void automl::offset_learn( - LEARNER::multi_learner& base, multi_ex& ec, CB::cb_class& logged, uint64_t labelled_action) + LEARNER::multi_learner& base, multi_ex& ec, VW::cb_class& logged, uint64_t labelled_action) { interaction_vec_t* incoming_interactions = ec[0]->interactions; for (VW::example* ex : ec) diff --git a/vowpalwabbit/core/src/reductions/epsilon_decay.cc b/vowpalwabbit/core/src/reductions/epsilon_decay.cc index a48895269ee..9b246bfc7be 100644 --- a/vowpalwabbit/core/src/reductions/epsilon_decay.cc +++ b/vowpalwabbit/core/src/reductions/epsilon_decay.cc @@ -66,7 +66,7 @@ epsilon_decay_data::epsilon_decay_data(uint64_t model_count, uint64_t min_scope, void epsilon_decay_data::update_weights(float init_ep, VW::LEARNER::multi_learner& base, VW::multi_ex& examples) { auto model_count = static_cast(conf_seq_estimators.size()); - CB::cb_class logged{}; + VW::cb_class logged{}; uint64_t labelled_action = 0; const auto it = std::find_if(examples.begin(), examples.end(), [](VW::example* item) { return !item->l.cb.costs.empty(); }); diff --git a/vowpalwabbit/core/src/reductions/explore_eval.cc b/vowpalwabbit/core/src/reductions/explore_eval.cc index 40d9db3ce8e..847747c7af4 100644 --- a/vowpalwabbit/core/src/reductions/explore_eval.cc +++ b/vowpalwabbit/core/src/reductions/explore_eval.cc @@ -74,12 +74,12 @@ class rate_target class explore_eval { public: - CB::cb_class known_cost; + VW::cb_class known_cost; VW::workspace* all = nullptr; std::shared_ptr random_state; uint64_t offset = 0; - CB::label action_label; - CB::label empty_label; + VW::cb_label action_label; + VW::cb_label empty_label; size_t example_counter = 0; rate_target rt_target; @@ -167,7 +167,7 @@ void output_example(VW::workspace& all, const explore_eval& c, const VW::example all.print_text_by_ref(all.raw_prediction.get(), output_string_stream.str(), ec.tag, all.logger); } - CB::print_update(all, !labeled_example, ec, ec_seq, true, nullptr); + VW::details::print_update_cb(all, !labeled_example, ec, ec_seq, true, nullptr); } void output_example_seq(VW::workspace& all, const explore_eval& data, const VW::multi_ex& ec_seq) @@ -314,7 +314,7 @@ base_learner* VW::reductions::explore_eval_setup(VW::setup_base_i& stack_builder if (!options.was_supplied("cb_explore_adf")) { options.insert("cb_explore_adf", ""); } multi_learner* base = as_multiline(stack_builder.setup_base_learner()); - all.example_parser->lbl_parser = CB::cb_label; + all.example_parser->lbl_parser = VW::cb_label_parser_global; auto* l = make_reduction_learner(std::move(data), base, do_actual_learning, do_actual_learning, stack_builder.get_setupfn_name(explore_eval_setup)) diff --git a/vowpalwabbit/core/src/reductions/interaction_ground.cc b/vowpalwabbit/core/src/reductions/interaction_ground.cc index d22e73884a5..ae5e8f2fbc0 100644 --- a/vowpalwabbit/core/src/reductions/interaction_ground.cc +++ b/vowpalwabbit/core/src/reductions/interaction_ground.cc @@ -46,7 +46,7 @@ void negate_cost(VW::multi_ex& ec_seq) void learn(interaction_ground& ig, multi_learner& base, VW::multi_ex& ec_seq) { // find reward of sequence - CB::cb_class label = CB_ADF::get_observed_cost_or_default_cb_adf(ec_seq); + VW::cb_class label = CB_ADF::get_observed_cost_or_default_cb_adf(ec_seq); ig.total_uniform_cost += label.cost / label.probability / ec_seq.size(); //=p(uniform) * IPS estimate ig.total_uniform_reward += -label.cost / label.probability / ec_seq.size(); diff --git a/vowpalwabbit/core/src/reductions/mwt.cc b/vowpalwabbit/core/src/reductions/mwt.cc index af7354f2c8c..76e77980a0b 100644 --- a/vowpalwabbit/core/src/reductions/mwt.cc +++ b/vowpalwabbit/core/src/reductions/mwt.cc @@ -61,7 +61,7 @@ class mwt public: std::array namespaces{}; // the set of namespaces to evaluate. std::vector evals; // accrued losses of features. - std::pair optional_observation; + std::pair optional_observation; VW::v_array policies; double total = 0.; uint32_t num_classes = 0; @@ -326,6 +326,6 @@ base_learner* VW::reductions::mwt_setup(VW::setup_base_i& stack_builder) .set_print_update(::print_update_mwt) .build(); - all.example_parser->lbl_parser = CB::cb_label; + all.example_parser->lbl_parser = VW::cb_label_parser_global; return make_base(*l); } diff --git a/vowpalwabbit/core/src/reductions/offset_tree.cc b/vowpalwabbit/core/src/reductions/offset_tree.cc index 06566ffc1dd..b0256dc40e2 100644 --- a/vowpalwabbit/core/src/reductions/offset_tree.cc +++ b/vowpalwabbit/core/src/reductions/offset_tree.cc @@ -150,7 +150,7 @@ const offset_tree::scores_t& offset_tree::predict(LEARNER::single_learner& base, return _scores; } - const CB::label saved_label = ec.l.cb; + const VW::cb_label saved_label = ec.l.cb; ec.l.cb.costs.clear(); // Get predictions for all internal nodes diff --git a/vowpalwabbit/core/src/reductions/pmf_to_pdf.cc b/vowpalwabbit/core/src/reductions/pmf_to_pdf.cc index 53a3e756ca9..e7e47d45fd7 100644 --- a/vowpalwabbit/core/src/reductions/pmf_to_pdf.cc +++ b/vowpalwabbit/core/src/reductions/pmf_to_pdf.cc @@ -166,9 +166,9 @@ void pmf_to_pdf_reduction::learn(example& ec) auto actual_bandwidth = !tree_bandwidth ? 1 : 2 * b; // avoid zero division ec.l.cb.costs.push_back( - CB::cb_class(cost, local_min_value + 1, pdf_value * actual_bandwidth * continuous_range / num_actions)); + VW::cb_class(cost, local_min_value + 1, pdf_value * actual_bandwidth * continuous_range / num_actions)); ec.l.cb.costs.push_back( - CB::cb_class(cost, local_max_value + 1, pdf_value * actual_bandwidth * continuous_range / num_actions)); + VW::cb_class(cost, local_max_value + 1, pdf_value * actual_bandwidth * continuous_range / num_actions)); auto swap_prediction = VW::swap_guard(ec.pred.a_s, temp_pred_a_s); diff --git a/vowpalwabbit/core/src/reductions/search/search.cc b/vowpalwabbit/core/src/reductions/search/search.cc index 569e018a662..8aa702c392f 100644 --- a/vowpalwabbit/core/src/reductions/search/search.cc +++ b/vowpalwabbit/core/src/reductions/search/search.cc @@ -910,7 +910,7 @@ inline void cs_cost_push_back(bool is_cb, VW::polylabel& ld, uint32_t index, flo { if (is_cb) { - CB::cb_class cost{value, index, 0.}; + VW::cb_class cost{value, index, 0.}; ld.cb.costs.push_back(cost); } else @@ -3217,7 +3217,7 @@ base_learner* VW::reductions::search_setup(VW::setup_base_i& stack_builder) if (options.was_supplied("cb")) { priv.cb_learner = true; - CB::cb_label.default_label(priv.allowed_actions_cache); + VW::cb_label_parser_global.default_label(priv.allowed_actions_cache); priv.learn_losses.cb.costs.clear(); priv.gte_label.cb.costs.clear(); } diff --git a/vowpalwabbit/core/tests/cats_tree_test.cc b/vowpalwabbit/core/tests/cats_tree_test.cc index a255ad2fbf4..293e44fc389 100644 --- a/vowpalwabbit/core/tests/cats_tree_test.cc +++ b/vowpalwabbit/core/tests/cats_tree_test.cc @@ -133,8 +133,8 @@ TEST(CatsTree, OtcAlgoLearn1ActionTillRoot) VW::example ec; ec.ft_offset = 0; ec.debug_current_reduction_depth = 0; - ec.l.cb = CB::label(); - ec.l.cb.costs.push_back(CB::cb_class{3.5f, 2, 0.5f}); + ec.l.cb = VW::cb_label(); + ec.l.cb.costs.push_back(VW::cb_class{3.5f, 2, 0.5f}); tree.learn(*as_singleline(base), ec); @@ -163,8 +163,8 @@ TEST(CatsTree, OtcAlgoLearn1Action) VW::example ec; ec.ft_offset = 0; ec.debug_current_reduction_depth = 0; - ec.l.cb = CB::label(); - ec.l.cb.costs.push_back(CB::cb_class{3.5f, 2, 0.5f}); + ec.l.cb = VW::cb_label(); + ec.l.cb.costs.push_back(VW::cb_class{3.5f, 2, 0.5f}); tree.learn(*as_singleline(base), ec); @@ -187,9 +187,9 @@ TEST(CatsTree, OtcAlgoLearn2ActionSiblings) VW::example ec; ec.ft_offset = 0; ec.debug_current_reduction_depth = 0; - ec.l.cb = CB::label(); - ec.l.cb.costs.push_back(CB::cb_class{3.5f, 3, 0.5f}); - ec.l.cb.costs.push_back(CB::cb_class{3.5f, 4, 0.5f}); + ec.l.cb = VW::cb_label(); + ec.l.cb.costs.push_back(VW::cb_class{3.5f, 3, 0.5f}); + ec.l.cb.costs.push_back(VW::cb_class{3.5f, 4, 0.5f}); predictions_t preds_to_return = {1.f, -1.f}; @@ -219,9 +219,9 @@ TEST(CatsTree, OtcAlgoLearn2ActionNotSiblings) VW::example ec; ec.ft_offset = 0; ec.debug_current_reduction_depth = 0; - ec.l.cb = CB::label(); - ec.l.cb.costs.push_back(CB::cb_class{3.5f, 2, 0.5f}); - ec.l.cb.costs.push_back(CB::cb_class{3.5f, 3, 0.5f}); + ec.l.cb = VW::cb_label(); + ec.l.cb.costs.push_back(VW::cb_class{3.5f, 2, 0.5f}); + ec.l.cb.costs.push_back(VW::cb_class{3.5f, 3, 0.5f}); predictions_t preds_to_return = {1.f, 1.f, -1.f, 1.f}; @@ -251,9 +251,9 @@ TEST(CatsTree, OtcAlgoLearn2ActionNotSiblingsBandwidth1) VW::example ec; ec.ft_offset = 0; ec.debug_current_reduction_depth = 0; - ec.l.cb = CB::label(); - ec.l.cb.costs.push_back(CB::cb_class{3.5f, 2, 0.5f}); - ec.l.cb.costs.push_back(CB::cb_class{3.5f, 3, 0.5f}); + ec.l.cb = VW::cb_label(); + ec.l.cb.costs.push_back(VW::cb_class{3.5f, 2, 0.5f}); + ec.l.cb.costs.push_back(VW::cb_class{3.5f, 3, 0.5f}); predictions_t preds_to_return = {1.f, -1.f, 1.f}; @@ -287,9 +287,9 @@ TEST(CatsTree, OtcAlgoLearn2ActionSeparate) VW::example ec; ec.ft_offset = 0; ec.debug_current_reduction_depth = 0; - ec.l.cb = CB::label(); - ec.l.cb.costs.push_back(CB::cb_class{3.5f, 3, 0.5f}); - ec.l.cb.costs.push_back(CB::cb_class{3.5f, 6, 0.5f}); + ec.l.cb = VW::cb_label(); + ec.l.cb.costs.push_back(VW::cb_class{3.5f, 3, 0.5f}); + ec.l.cb.costs.push_back(VW::cb_class{3.5f, 6, 0.5f}); predictions_t preds_to_return = {-1.f, -1.f, -1.f}; @@ -319,9 +319,9 @@ TEST(CatsTree, OtcAlgoLearn2ActionSeparate2) VW::example ec; ec.ft_offset = 0; ec.debug_current_reduction_depth = 0; - ec.l.cb = CB::label(); - ec.l.cb.costs.push_back(CB::cb_class{3.5f, 3, 0.5f}); - ec.l.cb.costs.push_back(CB::cb_class{3.5f, 7, 0.5f}); + ec.l.cb = VW::cb_label(); + ec.l.cb.costs.push_back(VW::cb_class{3.5f, 3, 0.5f}); + ec.l.cb.costs.push_back(VW::cb_class{3.5f, 7, 0.5f}); predictions_t preds_to_return = {1.f, 1.f, 1.f, -1.f}; @@ -351,9 +351,9 @@ TEST(CatsTree, OtcAlgoLearn2ActionSeparateBandwidth2) VW::example ec; ec.ft_offset = 0; ec.debug_current_reduction_depth = 0; - ec.l.cb = CB::label(); - ec.l.cb.costs.push_back(CB::cb_class{3.5f, 3, 0.5f}); - ec.l.cb.costs.push_back(CB::cb_class{3.5f, 6, 0.5f}); + ec.l.cb = VW::cb_label(); + ec.l.cb.costs.push_back(VW::cb_class{3.5f, 3, 0.5f}); + ec.l.cb.costs.push_back(VW::cb_class{3.5f, 6, 0.5f}); predictions_t preds_to_return = {}; @@ -383,9 +383,9 @@ TEST(CatsTree, OtcAlgoLearn2ActionSeparate2Bandwidth2) VW::example ec; ec.ft_offset = 0; ec.debug_current_reduction_depth = 0; - ec.l.cb = CB::label(); - ec.l.cb.costs.push_back(CB::cb_class{3.5f, 3, 0.5f}); - ec.l.cb.costs.push_back(CB::cb_class{3.5f, 11, 0.5f}); + ec.l.cb = VW::cb_label(); + ec.l.cb.costs.push_back(VW::cb_class{3.5f, 3, 0.5f}); + ec.l.cb.costs.push_back(VW::cb_class{3.5f, 11, 0.5f}); predictions_t preds_to_return = {1, 1, -1}; @@ -415,9 +415,9 @@ TEST(CatsTree, OtcAlgoLearn2ActionSeparateBandwidth1Asym) VW::example ec; ec.ft_offset = 0; ec.debug_current_reduction_depth = 0; - ec.l.cb = CB::label(); - ec.l.cb.costs.push_back(CB::cb_class{3.5f, 2, 0.5f}); - ec.l.cb.costs.push_back(CB::cb_class{3.5f, 5, 0.5f}); + ec.l.cb = VW::cb_label(); + ec.l.cb.costs.push_back(VW::cb_class{3.5f, 2, 0.5f}); + ec.l.cb.costs.push_back(VW::cb_class{3.5f, 5, 0.5f}); predictions_t preds_to_return = {-1.f, 1.f, -1.f}; diff --git a/vowpalwabbit/core/tests/cb_large_actions_test.cc b/vowpalwabbit/core/tests/cb_large_actions_test.cc index 918c1e3764f..e1f0cc21b33 100644 --- a/vowpalwabbit/core/tests/cb_large_actions_test.cc +++ b/vowpalwabbit/core/tests/cb_large_actions_test.cc @@ -64,7 +64,7 @@ TEST(Las, CreationOfTheOgAMatrix) uint64_t action_index = 0; auto* ex = examples[action_index]; // test sanity - test assumes no shared features - EXPECT_EQ(!CB::ec_is_example_header(*ex), true); + EXPECT_EQ(!VW::ec_is_example_header_cb(*ex), true); for (auto ns : ex->indices) { for (size_t i = 0; i < ex->feature_space[ns].indices.size(); i++) @@ -275,7 +275,7 @@ TEST(Las, CheckAtTimesOmegaIsY) { auto* ex = examples[action_index]; // test sanity - test assumes no shared features - EXPECT_EQ(!CB::ec_is_example_header(*ex), true); + EXPECT_EQ(!VW::ec_is_example_header_cb(*ex), true); for (auto ns : ex->indices) { _UNUSED(ns); diff --git a/vowpalwabbit/core/tests/example_header_test.cc b/vowpalwabbit/core/tests/example_header_test.cc index 09a9a981f45..34637c23b6b 100644 --- a/vowpalwabbit/core/tests/example_header_test.cc +++ b/vowpalwabbit/core/tests/example_header_test.cc @@ -18,13 +18,13 @@ TEST(ExampleHeader, IsExampleHeaderCb) examples.push_back(VW::read_example(vw, "0:1.0:0.5 | a:1 b:1 c:1")); examples.push_back(VW::read_example(vw, "| a:0.5 b:2 c:1")); - EXPECT_EQ(CB::ec_is_example_header(*examples[0]), true); + EXPECT_EQ(VW::ec_is_example_header_cb(*examples[0]), true); EXPECT_EQ(VW::is_cs_example_header(*examples[0]), false); - EXPECT_EQ(CB::ec_is_example_header(*examples[1]), false); + EXPECT_EQ(VW::ec_is_example_header_cb(*examples[1]), false); EXPECT_EQ(VW::is_cs_example_header(*examples[1]), false); - EXPECT_EQ(CB::ec_is_example_header(*examples[2]), false); + EXPECT_EQ(VW::ec_is_example_header_cb(*examples[2]), false); EXPECT_EQ(VW::is_cs_example_header(*examples[2]), false); VW::finish_example(vw, examples); VW::finish(vw); @@ -50,10 +50,10 @@ TEST(ExampleHeader, IsExampleHeaderCsoaa) examples.push_back(VW::read_example(vw, "shared | a_2 b_2 c_2")); examples.push_back(VW::read_example(vw, "3:2.0 | a_3 b_3 c_3")); - EXPECT_EQ(CB::ec_is_example_header(*examples[0]), false); + EXPECT_EQ(VW::ec_is_example_header_cb(*examples[0]), false); EXPECT_EQ(VW::is_cs_example_header(*examples[0]), true); - EXPECT_EQ(CB::ec_is_example_header(*examples[1]), false); + EXPECT_EQ(VW::ec_is_example_header_cb(*examples[1]), false); EXPECT_EQ(VW::is_cs_example_header(*examples[1]), false); VW::finish_example(vw, examples); VW::finish(vw); diff --git a/vowpalwabbit/core/tests/offset_tree_test.cc b/vowpalwabbit/core/tests/offset_tree_test.cc index 5179d72994c..747919175c1 100644 --- a/vowpalwabbit/core/tests/offset_tree_test.cc +++ b/vowpalwabbit/core/tests/offset_tree_test.cc @@ -105,7 +105,7 @@ TEST(OffsetTree, OffsetTreeLearnBasic) VW::reductions::offset_tree::offset_tree tree(3); tree.init(); VW::example ec; - ec.l.cb.costs.push_back(CB::cb_class{-1.0f, 1, 0.5f}); + ec.l.cb.costs.push_back(VW::cb_class{-1.0f, 1, 0.5f}); tree.learn(*as_singleline(test_harness), ec); delete test_harness; diff --git a/vowpalwabbit/fb_parser/src/parse_label.cc b/vowpalwabbit/fb_parser/src/parse_label.cc index 719b770a376..0d176588c8e 100644 --- a/vowpalwabbit/fb_parser/src/parse_label.cc +++ b/vowpalwabbit/fb_parser/src/parse_label.cc @@ -36,7 +36,7 @@ void parser::parse_cb_label(polylabel* l, const CBLabel* label) l->cb.weight = label->weight(); for (auto const& cost : *(label->costs())) { - CB::cb_class f; + VW::cb_class f; f.action = cost->action(); f.cost = cost->cost(); f.probability = cost->probability(); @@ -86,7 +86,7 @@ void parser::parse_cb_eval_label(polylabel* l, const CB_EVAL_Label* label) l->cb_eval.event.weight = label->event()->weight(); for (const auto& cb_cost : *(label->event()->costs())) { - CB::cb_class f; + VW::cb_class f; f.cost = cb_cost->cost(); f.action = cb_cost->action(); f.probability = cb_cost->probability(); diff --git a/vowpalwabbit/json_parser/src/parse_example_json.cc b/vowpalwabbit/json_parser/src/parse_example_json.cc index 86d4f44885d..42aaf006622 100644 --- a/vowpalwabbit/json_parser/src/parse_example_json.cc +++ b/vowpalwabbit/json_parser/src/parse_example_json.cc @@ -214,7 +214,7 @@ template class LabelObjectState : public BaseState { public: - CB::cb_class cb_label; + VW::cb_class cb_label; VW::cb_continuous::continuous_label_elm cont_label_element = {0., 0., 0.}; bool found = false; bool found_cb = false; @@ -382,7 +382,7 @@ class LabelObjectState : public BaseState probs.clear(); ld.outcome = outcome; - cb_label = CB::cb_class{}; + cb_label = VW::cb_class{}; } } else if (ctx._label_parser.label_type == VW::label_type_t::SLATES) @@ -396,7 +396,7 @@ class LabelObjectState : public BaseState for (size_t i = 0; i < this->actions.size(); i++) { ld.probabilities.push_back({actions[i], probs[i]}); } actions.clear(); probs.clear(); - cb_label = CB::cb_class{}; + cb_label = VW::cb_class{}; } } else if (found_cb) @@ -405,7 +405,7 @@ class LabelObjectState : public BaseState ld.costs.push_back(cb_label); found_cb = false; - cb_label = CB::cb_class{}; + cb_label = VW::cb_class{}; } else if (found_cb_continuous) { @@ -580,8 +580,8 @@ class MultiState : public BaseState // mark shared example if (ctx._label_parser.label_type == VW::label_type_t::CB) { - CB::label* ld = &ctx.ex->l.cb; - CB::cb_class f; + VW::cb_label* ld = &ctx.ex->l.cb; + VW::cb_class f; f.partial_prediction = 0.; f.action = static_cast(VW::uniform_hash("shared", 6, 0));