### Setup Examples Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespaceVW.html Sets up multiple examples within the Vowpal Wabbit workspace. ```cpp void VW::setup_examples | ( | VW::workspace & | _all_ , | | VW::multi_ex & | _examples_ | ) | | ``` -------------------------------- ### Setup Example Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespaceVW.html Sets up a single example within the Vowpal Wabbit workspace. ```cpp void VW::setup_example | ( | VW::workspace & | _all_ , | | example * | _ae_ | ) | | ``` -------------------------------- ### setup_example() Source: https://vowpalwabbit.org/docs/vowpal_wabbit/python/latest/reference/vowpalwabbit.pyvw.html If this example hasn’t already been setup (e.g., quadratic features constructed), do so. ```APIDOC ## setup_example() ### Description If this example hasn’t already been setup (ie, quadratic features constructed, etc.), do so. ``` -------------------------------- ### unsetup_example() Source: https://vowpalwabbit.org/docs/vowpal_wabbit/python/latest/reference/vowpalwabbit.pyvw.html If this example has been setup, reverse that process to allow further editing. ```APIDOC ## unsetup_example() ### Description If this example has been setup, reverse that process so you can continue editing the examples. ``` -------------------------------- ### learn Source: https://vowpalwabbit.org/docs/vowpal_wabbit/python/latest/reference/vowpalwabbit.html Learns on the current example. Automatically calls setup_example if the example has not yet been set up. ```APIDOC ## learn() ### Description Learn on this example (and before learning, automatically call setup_example if the example hasn’t yet been setup). ``` -------------------------------- ### Return Multiple Examples Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespaceVW.html Returns multiple examples from the Vowpal Wabbit workspace. ```cpp void VW::return_multiple_example | ( | VW::workspace & | _all_ , | | VW::multi_ex & | _examples_ | ) | | ``` -------------------------------- ### VW::setup_examples() Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespaceVW.html Sets up multiple examples for processing within the workspace. ```APIDOC ## VW::setup_examples() ### Description Sets up multiple examples for processing within the workspace. ### Method `void VW::setup_examples(VW::workspace & _all_, VW::multi_ex & _examples_)` ``` -------------------------------- ### Example Creation Source: https://vowpalwabbit.org/docs/vowpal_wabbit/python/latest/reference/vowpalwabbit.html Create an example object associated with a Workspace instance. ```APIDOC ## example ### Description Helper function to create an example object associated with this Workspace instance. ### Parameters * **stringOrDict** (`Union[str, Dict[str, List[Union[Tuple[Union[str, int], float], str, int]]], Any, example, None]`) – See description in `__init__()` for valid values. * **labelType** (`Union[int, LabelType, None]`) – See description in `__init__()` for valid values. ### Return Type `Example` ### Returns Constructed Example ``` -------------------------------- ### get_prob Source: https://vowpalwabbit.org/docs/vowpal_wabbit/python/latest/reference/vowpalwabbit.pyvw.pylibvw.html Get probability from example prediction. ```APIDOC ## get_prob ### Description Get probability from example prediction. ### Signature `get_prob(_self: pylibvw.example_) -> float` ``` -------------------------------- ### setup_examples Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespacemembers_s.html Sets up multiple examples for processing in Vowpal Wabbit. ```APIDOC ## setup_examples() ### Description Prepares a batch or collection of examples for processing by the Vowpal Wabbit learning algorithm. ### Method (Not specified, likely a function call) ### Endpoint (Not applicable for C++ API) ### Parameters (Not specified) ### Request Example (Not applicable) ### Response (Not specified) ``` -------------------------------- ### get_pdf Source: https://vowpalwabbit.org/docs/vowpal_wabbit/python/latest/reference/vowpalwabbit.pyvw.pylibvw.html Get pdf from example prediction. ```APIDOC ## get_pdf ### Description Get pdf from example prediction. ### Signature `get_pdf(_self: pylibvw.example_) -> list` ``` -------------------------------- ### VW::setup_example() Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespaceVW.html Sets up a single example for processing within the workspace. ```APIDOC ## VW::setup_example() ### Description Sets up a single example for processing within the workspace. ### Method `void VW::setup_example(VW::workspace & _all_, example * _ae_)` ``` -------------------------------- ### setup_example Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespacemembers_s.html Sets up an individual example for processing in Vowpal Wabbit. ```APIDOC ## setup_example() ### Description Prepares a single example for processing by the Vowpal Wabbit learning algorithm. ### Method (Not specified, likely a function call) ### Endpoint (Not applicable for C++ API) ### Parameters (Not specified) ### Request Example (Not applicable) ### Response (Not specified) ``` -------------------------------- ### get_scalars Source: https://vowpalwabbit.org/docs/vowpal_wabbit/python/latest/reference/vowpalwabbit.pyvw.pylibvw.html Get scalar values from example prediction. ```APIDOC ## get_scalars ### Description Get scalar values from example prediction. ### Signature `get_scalars(_self: pylibvw.example_) -> list` ``` -------------------------------- ### get_multilabel_labels Source: https://vowpalwabbit.org/docs/vowpal_wabbit/python/latest/reference/vowpalwabbit.pyvw.pylibvw.html Get multilabel labels from example label. ```APIDOC ## get_multilabel_labels ### Description Get multilabel labels from example label. ### Signature `get_multilabel_labels(_self: pylibvw.example_) -> list` ``` -------------------------------- ### get_decision_scores Source: https://vowpalwabbit.org/docs/vowpal_wabbit/python/latest/reference/vowpalwabbit.pyvw.pylibvw.html Get decision scores from example prediction. ```APIDOC ## get_decision_scores ### Description Get decision scores from example prediction. ### Signature `get_decision_scores(_self: pylibvw.example_) -> list` ``` -------------------------------- ### setup_example Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespaceVW.html Sets up an example for processing. ```APIDOC ## setup_example ### Description Initializes or sets up an example structure for use within the VW workspace. ### Signature `void setup_example (VW::workspace &all, example *ae)` ``` -------------------------------- ### Example Management Functions Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespaceVW.html Functions for setting up and retrieving examples from the Vowpal Wabbit workspace. ```APIDOC ## setup_examples (VW::workspace &all, VW::multi_ex &examples) ### Description Sets up a collection of examples for use with the Vowpal Wabbit workspace. ### Signature void setup_examples(VW::workspace &all, VW::multi_ex &examples) ## get_unused_example (VW::workspace *all) ### Description Retrieves an unused example from the Vowpal Wabbit workspace. ### Signature VW::example *get_unused_example(VW::workspace *all) ``` -------------------------------- ### get_setupfn_name(reduction_setup_fn) Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/classVW_1_1cached__learner-members.html Gets the name of the reduction setup function. ```APIDOC ## get_setupfn_name(reduction_setup_fn) ### Description Retrieves the name of the reduction setup function. This is typically used for introspection and debugging purposes. ### Method override ### Parameters * **reduction_setup_fn** (reduction_setup_fn) - The reduction setup function for which to get the name. ``` -------------------------------- ### setup_examples Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespacemembers_func_s.html Sets up multiple examples for processing. Belongs to the VW namespace. ```APIDOC ## setup_examples() ### Description Sets up multiple examples for processing. ### Namespace VW ``` -------------------------------- ### VW::setup_example Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/example_8h.html Sets up an example structure for use with the Vowpal Wabbit workspace. ```APIDOC ## VW::setup_example ### Description Initializes or prepares an example structure for processing within a Vowpal Wabbit workspace. ### Signature `void setup_example(VW::workspace &all, example *ae)` ### Parameters - `all` (*VW::workspace&*): Reference to the Vowpal Wabbit workspace. - `ae` (*example*): Pointer to the example structure to be set up. ``` -------------------------------- ### Get Prediction from Example Source: https://vowpalwabbit.org/docs/vowpal_wabbit/python/latest/reference/vowpalwabbit.pyvw.html Retrieves a specific type of prediction from a Vowpal Wabbit example. Use this function when you need to extract predictions in a defined format. ```python >>> from vowpalwabbit import Workspace, PredictionType, pyvw >>> vw = Workspace(quiet=True) >>> ex = vw.example('1 |a two features |b more features here') >>> pyvw.get_prediction(ex, PredictionType.SCALAR) 0.0 ``` -------------------------------- ### VW::setup_examples Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/parser_8h.html Sets up a collection of examples for processing within the Vowpal Wabbit workspace. This typically involves allocating or preparing example structures. ```APIDOC ## VW::setup_examples ### Description Prepares a collection of examples for processing by the Vowpal Wabbit learning algorithm. ### Signature ```cpp void setup_examples(VW::workspace &all, VW::multi_ex &examples) ``` ### Parameters * **all** (VW::workspace &) - The Vowpal Wabbit workspace containing global settings and state. * **examples** (VW::multi_ex &) - A collection of examples to be set up. ``` -------------------------------- ### VW::get_action_score_length Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespaceVW.html Gets the number of action scores available for an example. ```APIDOC ## VW::get_action_score_length() size_t VW::get_action_score_length(example * _ec_) ``` -------------------------------- ### Example Handling Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/vw_8h.html Functions for reading, creating, and manipulating examples within Vowpal Wabbit. ```APIDOC ## VW::is_ring_example ### Description Checks if an example is part of a ring buffer. ### Signature `bool is_ring_example (const VW::workspace &all, const example *ae)` ### Parameters - `all`: The Vowpal Wabbit workspace. - `ae`: Pointer to the example to check. ``` ```APIDOC ## VW::read_example ### Description Reads an example from a string. ### Overloads - `example * read_example (VW::workspace &all, const char *example_line)` - `example * read_example (VW::workspace &all, const std::string &example_line)` ### Parameters - `all`: The Vowpal Wabbit workspace. - `example_line`: The string representing the example. ``` ```APIDOC ## VW::import_example ### Description Imports an example with specified label and features. ### Signature `example * import_example (VW::workspace &all, const std::string &label, primitive_feature_space *features, size_t len)` ### Parameters - `all`: The Vowpal Wabbit workspace. - `label`: The label for the example. - `features`: Pointer to the feature space. - `len`: The number of features. ``` ```APIDOC ## VW::alloc_examples ### Description Allocates memory for a specified number of examples. ### Signature `example * alloc_examples (size_t count)` ### Parameters - `count`: The number of examples to allocate. ``` ```APIDOC ## VW::dealloc_examples ### Description Deallocates memory for a specified number of examples. ### Signature `void dealloc_examples (example *example_ptr, size_t count)` ### Parameters - `example_ptr`: Pointer to the beginning of the example memory. - `count`: The number of examples to deallocate. ``` ```APIDOC ## VW::parse_example_label ### Description Parses the label of an example. ### Signature `void parse_example_label (VW::workspace &all, example &ec, const std::string &label)` ### Parameters - `all`: The Vowpal Wabbit workspace. - `ec`: The example to parse the label for. - `label`: The label string. ``` ```APIDOC ## VW::setup_examples ### Description Sets up multiple examples for processing. ### Signature `void setup_examples (VW::workspace &all, VW::multi_ex &examples)` ### Parameters - `all`: The Vowpal Wabbit workspace. - `examples`: A collection of examples to set up. ``` ```APIDOC ## VW::setup_example ### Description Sets up a single example for processing. ### Signature `void setup_example (VW::workspace &all, example *ae)` ### Parameters - `all`: The Vowpal Wabbit workspace. - `ae`: Pointer to the example to set up. ``` ```APIDOC ## VW::new_unused_example ### Description Creates a new, unused example. ### Signature `example * new_unused_example (VW::workspace &all)` ### Parameters - `all`: The Vowpal Wabbit workspace. ``` ```APIDOC ## VW::get_example ### Description Retrieves an example from a parser. ### Signature `example * get_example (parser *pf)` ### Parameters - `pf`: Pointer to the parser. ``` -------------------------------- ### Get Prediction from Example Source: https://vowpalwabbit.org/docs/vowpal_wabbit/python/latest/reference/vowpalwabbit.pyvw.html Retrieves the prediction for an example. If prediction_type is None, it defaults to the workspace's prediction type. Deprecated: Supplying an int for prediction_type is deprecated. ```python >>> from vowpalwabbit import Workspace, PredictionType >>> vw = Workspace(quiet=True) >>> ex = vw.example('1 |a two features |b more features here') >>> ex.get_prediction() 0.0 ``` -------------------------------- ### setup_example Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespacemembers_func_s.html Sets up an example for processing. Belongs to the VW namespace. ```APIDOC ## setup_example() ### Description Sets up an example for processing. ### Namespace VW ``` -------------------------------- ### Learn and Get Updated Prediction Source: https://vowpalwabbit.org/docs/vowpal_wabbit/python/latest/examples/basics.html Train the model with an example and then retrieve the prediction for that same example after the update. The 'updated' prediction reflects the model's state post-learning. ```python vw.learn(ex) print(f"current prediction = {ex.get_updated_prediction()}") ``` -------------------------------- ### num_features_in(_ns_) Source: https://vowpalwabbit.org/docs/vowpal_wabbit/python/latest/reference/vowpalwabbit.pyvw.html Get the total number of features in a given namespace of an example. ```APIDOC ## num_features_in(_ns_) ### Description Get the total number of features in a given namespace. ### Parameters - **ns** (`Union`[`NamespaceId`, `str`, `int`]) - Required - namespace Get the total features of this namespace ### Return Type `int` ### Returns Total number of features in the given ns ``` -------------------------------- ### ect_setup Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespacemembers_func_e.html Sets up the example context for a reduction. ```APIDOC ## ect_setup() ### Description Sets up the example context for a given reduction. This function is part of the reduction mechanism in Vowpal Wabbit. ### Signature `void ect_setup(VW::reductions& reductions)` ### Parameters * `reductions` (VW::reductions&): A reference to the reductions object. ``` -------------------------------- ### get_or_calculate_order_independent_feature_space_hash() Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/functions_func_g.html Gets or calculates the order-independent feature space hash for an example prediction. ```APIDOC ## get_or_calculate_order_independent_feature_space_hash() ### Description Gets or calculates the order-independent feature space hash for an example prediction. ### Signature `uint64_t get_or_calculate_order_independent_feature_space_hash(const VW::example_predict& ec)` ``` -------------------------------- ### binary_setup Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespacemembers_b.html Sets up the binary reduction. ```APIDOC ## binary_setup() ### Description Sets up the binary reduction. ### Namespace VW::reductions ``` -------------------------------- ### expreplay_setup Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespacemembers_func_e.html Sets up the experience replay reduction. ```APIDOC ## expreplay_setup() ### Description Sets up the experience replay (expreplay) reduction. This function initializes the necessary structures and parameters for using experience replay during training. ### Signature `void expreplay_setup(VW::reductions& reductions)` ### Parameters * `reductions` (VW::reductions&): A reference to the reductions object. ``` -------------------------------- ### VW::get_unused_example Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/parser_8h.html Retrieves an unused example structure from the Vowpal Wabbit workspace's pool. This is an efficient way to get an example object without reallocating memory. ```APIDOC ## VW::get_unused_example ### Description Fetches an available example object from the workspace's internal pool for reuse. ### Signature ```cpp VW::example &get_unused_example(VW::workspace *all) ``` ### Parameters * **all** (VW::workspace *) - Pointer to the Vowpal Wabbit workspace. ### Returns A reference to an unused `VW::example` object. ``` -------------------------------- ### parse_examples(VW::workspace *all, io_buf &buf, VW::multi_ex &examples, const uint8_t *buffer_pointer=nullptr, VW::experimental::api_status *status=nullptr) Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/classVW_1_1parsers_1_1flatbuffer_1_1parser-members.html Parses examples from a buffer into the provided multi_ex structure. ```APIDOC ## parse_examples(VW::workspace *all, io_buf &buf, VW::multi_ex &examples, const uint8_t *buffer_pointer=nullptr, VW::experimental::api_status *status=nullptr) ### Description Parses examples from a buffer into the provided multi_ex structure. This method is used to deserialize example data from a flatbuffer format. ### Method (Implicitly called) ### Parameters - **all** (VW::workspace *) - Pointer to the Vowpal Wabbit workspace. - **buf** (io_buf &) - The input buffer containing the data to parse. - **examples** (VW::multi_ex &) - The structure to populate with parsed examples. - **buffer_pointer** (const uint8_t *, optional) - A pointer to the buffer data. If nullptr, `buf` is used. - **status** (VW::experimental::api_status *, optional) - Pointer to an API status object for error reporting. ### Response (No explicit return value documented, likely modifies `examples` in place and uses `status` for errors.) ``` -------------------------------- ### vowpalwabbit.pyvw.get_prediction(_ec_, _prediction_type_) Source: https://vowpalwabbit.org/docs/vowpal_wabbit/python/latest/reference/vowpalwabbit.pyvw.html Gets a specified type of prediction from an example. Deprecated, use `get_prediction()` instead. ```APIDOC ## vowpalwabbit.pyvw.get_prediction(_ec_, _prediction_type_) ### Description Get specified type of prediction from example Deprecated since version 9.0.0: Use `get_prediction()` instead ### Parameters * **ec** (Example) - Example * **prediction_type** (Union[int, PredictionType]) – either the integer value of the `PredictionType` enum or the enum itself ### Returns Prediction according to parameter prediction_type ### Example ```python >>> from vowpalwabbit import Workspace, PredictionType, pyvw >>> vw = Workspace(quiet=True) >>> ex = vw.example('1 |a two features |b more features here') >>> pyvw.get_prediction(ex, PredictionType.SCALAR) 0.0 ``` ``` -------------------------------- ### plt_setup() Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespacemembers_func_p.html Sets up the 'plt' reduction. ```APIDOC ## plt_setup() ### Description Initializes and sets up the 'plt' (likely related to plotting or prediction logging) reduction. ### Signature `VW::reductions plt_setup()` ``` -------------------------------- ### Basic Vowpal Wabbit Workspace Usage Source: https://vowpalwabbit.org/docs/vowpal_wabbit/python/latest/reference/vowpalwabbit.html Demonstrates initializing a Vowpal Wabbit workspace, creating an example, learning from it, and making a prediction. Ensure Vowpal Wabbit is installed. ```python from vowpalwabbit import Workspace, Example workspace = Workspace(quiet=True) ex = Example('1 | a b c') workspace.learn(ex) workspace.predict(ex) ``` -------------------------------- ### Import Python Libraries for Vowpal Wabbit Slates Source: https://vowpalwabbit.org/docs/vowpal_wabbit/python/latest/tutorials/python_slates.html Import necessary Python libraries for Vowpal Wabbit, plotting, data manipulation, and numerical operations. Ensure these are installed before running the example. ```python import vowpal_wabbit import matplotlib.pyplot as plt import pandas as pd import random import numpy as np ``` -------------------------------- ### get_example() Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespacemembers_func_g.html Retrieves an example from Vowpal Wabbit. ```APIDOC ## get_example() ### Description Retrieves an example from Vowpal Wabbit. ### Signature `VW get_example()` ``` -------------------------------- ### gd_setup() Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespacemembers_func_g.html Sets up the Gradient Descent reduction. ```APIDOC ## gd_setup() ### Description Sets up the Gradient Descent reduction. ### Signature `VW::reductions gd_setup()` ``` -------------------------------- ### Contextual Bandit (CB) Loop Example Source: https://vowpalwabbit.org/docs/reinforcement_learning/cpp/latest/rl_sim_8cc-example.html Implements the loop for a Contextual Bandit problem. It repeatedly picks a person, gets their features, chooses an action using the RL model, and reports the outcome. ```cpp int rl_sim::cb_loop() { r::ranking_response response; simulation_stats stats; while (_run_loop) { auto& p = pick_a_random_person(); const auto context_features = p.get_features(); const auto action_features = get_action_features(); const auto context_json = create_context_json(context_features, action_features); const auto req_id = create_event_id(); r::api_status status; // Choose an action if (_rl->choose_rank(req_id.c_str(), context_json.c_str(), response, &status) != err::success) { std::cout << status.get_error_msg() << std::endl; continue; } // Use the chosen action size_t chosen_action = 0; if (response.get_chosen_action_id(chosen_action) != err::success) { std::cout << status.get_error_msg() << std::endl; continue; } // What outcome did this action get? const auto outcome = p.get_outcome(_topics[chosen_action], _random_seed); // Report outcome received if (_rl->report_outcome(req_id.c_str(), outcome, &status) != err::success && outcome > 0.00001f) { std::cout << status.get_error_msg() << std::endl; continue; } stats.record(p.id(), chosen_action, outcome); if (!_quiet) { std::cout << " " << stats.count() << ", ctxt, " << p.id() << ", action, " << chosen_action << ", outcome, " << outcome << ", dist, " << get_dist_str(response) << ", " << stats.get_stats(p.id(), chosen_action) << std::endl; } std::this_thread::sleep_for(std::chrono::milliseconds(_delay)); } return 0; } ``` -------------------------------- ### cb_explore_setup Function Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/cb__explore_8h.html The `cb_explore_setup` function is part of the Vowpal Wabbit reductions for contextual bandits. It is responsible for initializing the exploration mechanism. ```APIDOC ## VW::reductions::cb_explore_setup ### Description Sets up the contextual bandit exploration reducer. ### Signature std::shared_ptr< VW::LEARNER::learner > cb_explore_setup(VW::setup_base_i &stack_builder) ### Parameters * `stack_builder` (VW::setup_base_i &): The stack builder interface for setting up the learner. ### Returns A shared pointer to the initialized learner for contextual bandit exploration. ``` -------------------------------- ### start() and Start() Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/classVW_1_1spanning__tree.html Initiates the spanning tree process. Start() is deprecated. ```APIDOC ## start() ### Description Initiates the spanning tree process. This is typically a non-blocking call that starts the process in the background. ### Method void ``` ```APIDOC ## Start() ### Description Initiates the spanning tree process. This method is deprecated and will be removed in VW 10. Use `start()` instead. ### Method void ``` -------------------------------- ### CB Explore Setup Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespaceVW_1_1reductions.html Sets up the CB explore reduction. ```APIDOC ## cb_explore_setup ### Description Sets up the CB explore reduction. ### Signature std::shared_ptr< VW::LEARNER::learner > cb_explore_setup (VW::setup_base_i &stack_builder) ``` -------------------------------- ### Set Label and Train on Test Example Source: https://vowpalwabbit.org/docs/vowpal_wabbit/python/latest/examples/basics.html Assign a label to a test example and train the model on it multiple times. This converts the test example into a training example. ```python ex2.set_label_string("-2.0") for _ in range(5): vw.learn(ex2) print(f"current prediction = {ex2.get_updated_prediction()}") ``` -------------------------------- ### Cost Sensitive Example Header Check Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/cost__sensitive_8h.html Checks if an example is a cost-sensitive example header. ```APIDOC ## VW::is_cs_example_header ### Description Checks if the provided `VW::example` is a cost-sensitive example header. ### Signature ```cpp bool VW::is_cs_example_header(const VW::example &ec) ``` ### Parameters - **ec** (const VW::example &): The example to check. ``` -------------------------------- ### expreplay_setup function Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/expreplay_8h.html The `expreplay_setup` function is a factory function used to create and initialize an expreplay learner. ```APIDOC ## expreplay_setup ### Description Factory function to set up and initialize an expreplay learner. ### Signature ```cpp template std::shared_ptr< VW::LEARNER::learner > expreplay_setup(VW::setup_base_i &stack_builder) ``` ### Parameters * `stack_builder`: The stack builder object used for setting up the learner. ``` -------------------------------- ### Example Class Methods Source: https://vowpalwabbit.org/docs/vowpal_wabbit/python/latest/reference/vowpalwabbit.html Methods available for the Example class, used for constructing and manipulating training examples. ```APIDOC ## Example Class ### Description Provides methods for creating, modifying, and accessing features and labels within a Vowpal Wabbit example. ### Methods - `__init__()`: Initializes an Example object. - `ensure_namespace_exists(ns)`: Ensures a namespace exists in the example. - `feature(name, value)`: Adds or updates a feature with a given name and value. - `feature_weight(name, weight)`: Sets the weight for a feature. - `finished`: Property indicating if the example setup is complete. - `get_feature_id(ns, name)`: Retrieves the ID of a feature within a namespace. - `get_label()`: Retrieves the label associated with the example. - `get_ns(ns)`: Retrieves a namespace object. - `get_prediction()`: Retrieves the prediction for the example. - `iter_features()`: Iterates over the features in the example. - `labelType`: Property to get the type of label. - `learn()`: Processes the example for learning. - `num_features_in(ns)`: Returns the number of features in a namespace. - `pop_feature(ns, name)`: Removes a feature from a namespace. - `pop_namespace(ns)`: Removes a namespace from the example. - `push_feature(ns, name, value)`: Adds a feature to a namespace. - `push_features(ns, features)`: Adds multiple features to a namespace. - `push_hashed_feature(ns, index, value)`: Adds a hashed feature. - `push_namespace(ns)`: Adds a namespace to the example. - `set_label_string(label_str)`: Sets the label using a string representation. - `setup_done`: Property indicating if the example setup is done. - `setup_example()`: Sets up the example for processing. - `stride`: Property for stride information. - `sum_feat_sq(ns)`: Calculates the sum of squared feature values in a namespace. - `unsetup_example()`: Cleans up example setup. - `vw`: Property to access the Vowpal Wabbit instance. ``` -------------------------------- ### topk_setup() Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespaceVW_1_1reductions.html Initializes the top-k reduction strategy. This is useful for problems where selecting the top k actions or items is the goal. ```APIDOC ## topk_setup() ### Description Initializes the top-k reduction strategy for selecting top actions or items. ### Signature std::shared_ptr< VW::LEARNER::learner > VW::reductions::topk_setup(VW::setup_base_i &, VW::LEARNER::stack_builder &) ### Parameters * **setup_base_i** (VW::setup_base_i &) - The setup interface for Vowpal Wabbit. * **_stack_builder_** (VW::LEARNER::stack_builder &) - The stack builder for managing reduction layers. ``` -------------------------------- ### Cost Sensitive Example Header Check (Alternative) Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/cost__sensitive_8h.html Checks if an example is a cost-sensitive example header (alternative implementation). ```APIDOC ## VW::ec_is_example_header ### Description Checks if the provided `VW::example` is a cost-sensitive example header. ### Signature ```cpp bool VW::ec_is_example_header(VW::example const &ec) ``` ### Parameters - **ec** (VW::example const &): The example to check. ``` -------------------------------- ### Iterate Learning Between Two Examples Source: https://vowpalwabbit.org/docs/vowpal_wabbit/python/latest/examples/basics.html Alternate learning between two examples, `ex` and `ex2`, over several iterations. This demonstrates how training on one example can influence predictions on others, and shows the predictions for both examples after each iteration. ```python ex.set_label_string("1") for i in range(10): vw.learn(ex) vw.learn(ex2) print(f"ex prediction = {ex.get_updated_prediction()}") print(f"ex2 prediction = {ex2.get_updated_prediction()}") ``` -------------------------------- ### Efficient Example Management Source: https://vowpalwabbit.org/docs/vowpal_wabbit/python/latest/examples/predict.html Demonstrates how to manage a list of examples efficiently, including creating and finishing them to allow Vowpal Wabbit to reuse memory. ```python exList = [] for i in range(120): ex = vw.example() exList.append(ex) # this is the safe way to delete the examples for VW to reuse: for ex in exList: vw.finish_example(ex) exList = [] # this should __del__ the examples, we hope :) for i in range(120): ex = vw.example() exList.append(ex) for ex in exList: vw.finish_example(ex) ``` -------------------------------- ### next(VW::workspace &all, io_buf &buf, VW::multi_ex &examples) override Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/classVW_1_1parsers_1_1csv_1_1csv__parser-members.html Parses the next example from the input buffer. ```APIDOC ## next(VW::workspace &all, io_buf &buf, VW::multi_ex &examples) override ### Description This is the core method for parsing the next example from the provided input buffer (`io_buf`). It populates the `VW::multi_ex` structure with the parsed example data, using the `VW::workspace` context. This method overrides a virtual function from the base `input_parser` class. ### Parameters * **all** (VW::workspace &) - The Vowpal Wabbit workspace containing global settings and data. * **buf** (io_buf &) - The input buffer containing the data to be parsed. * **examples** (VW::multi_ex &) - A multi-example structure to store the parsed example. ``` -------------------------------- ### start() Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/classVW_1_1spanning__tree-members.html Starts the spanning tree. ```APIDOC ## start() ### Description Starts the spanning tree. This function initiates the operation of the spanning tree. ### Method (Implicitly called, likely a starter) ### Endpoint N/A ### Parameters None ### Request Example ```cpp st.start(); ``` ### Response None (Typically starts a process or performs an action) ``` -------------------------------- ### topk_setup Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespaceVW_1_1reductions.html Sets up the Top-K learning algorithm. ```APIDOC ## topk_setup ### Description Sets up the Top-K learning algorithm. ### Signature std::shared_ptr< VW::LEARNER::learner > topk_setup (VW::setup_base_i &stack_builder) ``` -------------------------------- ### Create Example from Dictionary Source: https://vowpalwabbit.org/docs/vowpal_wabbit/python/latest/examples/basics.html Create a Vowpal Wabbit example using Python dictionaries. This maps namespaces to lists of features, which can be strings or (string, float) pairs. This example is created without a label, making it a test example. ```python ex2 = vw.example({"a": ["features"], "b": ["more", "features", "there"]}) ``` -------------------------------- ### cbify_setup Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespaceVW_1_1reductions.html Sets up the cbify reduction. ```APIDOC ## cbify_setup() ### Description Sets up the cbify reduction. ### Signature std::shared_ptr< VW::LEARNER::learner > VW::reductions::cbify_setup(VW::setup_base_i & _stack_builder_) ``` -------------------------------- ### Example Management Functions Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/vw_8h.html Functions for managing and manipulating Vowpal Wabbit examples, including adding labels, finishing, and emptying examples. ```APIDOC ## add_constant_feature ### Description Adds a constant feature to a Vowpal Wabbit example. ### Signature `void VW::add_constant_feature (const VW::workspace &all, example *ec)` ## add_label ### Description Adds a label to a Vowpal Wabbit example. ### Signature `void VW::add_label (example *ec, float label, float weight=1, float base=0)` ## finish_example ### Description Cleans up and finalizes a Vowpal Wabbit example. ### Signature `void VW::finish_example (VW::workspace &all, example &ec)` `void VW::finish_example (VW::workspace &all, multi_ex &ec)` ## empty_example ### Description Resets a Vowpal Wabbit example, freeing its resources. ### Signature `void VW::empty_example (VW::workspace &all, example &ec)` ``` -------------------------------- ### VW::LEARNER::ec_is_example_header Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/learner_8h.html Checks if a given example is an example header based on its label type. This is useful for parsing multi-line examples. ```APIDOC ## VW::LEARNER::ec_is_example_header ### Description Checks if a given example is an example header based on its label type. This is useful for parsing multi-line examples. ### Signature ```cpp bool ec_is_example_header(example const &ec, label_type_t label_type) ``` ### Parameters * `ec` (example const &): A constant reference to the example to check. * `label_type` (label_type_t): The label type to check against. ``` -------------------------------- ### lrqfa_setup Function Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/lrqfa_8h.html The `lrqfa_setup` function initializes and returns a shared pointer to the LRQFA learner. It is part of the `VW::reductions` namespace and requires a `VW::setup_base_i` object for setup. ```APIDOC ## VW::reductions::lrqfa_setup ### Description Sets up the LRQFA (Linear Regression Quantile Factorization Algorithm) learner. ### Signature std::shared_ptr< VW::LEARNER::learner > lrqfa_setup(VW::setup_base_i &stack_builder) ### Parameters * `stack_builder` (VW::setup_base_i &) - The base interface for setting up the learner stack. ### Returns A `std::shared_ptr` to the initialized `VW::LEARNER::learner` object for LRQFA. ``` -------------------------------- ### CB Algs Setup Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespaceVW_1_1reductions.html Sets up the CB algorithms reduction. ```APIDOC ## cb_algs_setup ### Description Sets up the CB algorithms reduction. ### Signature std::shared_ptr< VW::LEARNER::learner > cb_algs_setup (VW::setup_base_i &stack_builder) ``` -------------------------------- ### Start Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/functions_func_s.html Starts a spanning tree process. ```APIDOC ## Start ### Description Initiates the process related to a spanning tree. ### Signature `void Start(VW::spanning_tree &)` ``` -------------------------------- ### cb_sample_setup Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespaceVW_1_1reductions.html Sets up the cb_sample reduction. ```APIDOC ## cb_sample_setup() ### Description Sets up the cb_sample reduction. ### Signature std::shared_ptr< VW::LEARNER::learner > VW::reductions::cb_sample_setup(VW::setup_base_i & _stack_builder_) ``` -------------------------------- ### read_span_flatbuffer Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/parse__example__flatbuffer_8h.html Reads a span of flatbuffer data and converts it into Vowpal Wabbit examples. It supports custom example factories and optional example sinks. ```APIDOC ## read_span_flatbuffer ### Description Reads a span of flatbuffer data and converts it into Vowpal Wabbit examples. Supports custom example factories and optional example sinks. ### Signature `int VW::parsers::flatbuffer::read_span_flatbuffer(VW::workspace *all, const uint8_t *span, size_t length, example_factory_t example_factory, VW::multi_ex &examples, example_sink_f example_sink = nullptr, VW::experimental::api_status *status = nullptr)` ### Parameters - **all** (`VW::workspace *`): Pointer to the Vowpal Wabbit workspace. - **span** (`const uint8_t *`): Pointer to the beginning of the flatbuffer data span. - **length** (`size_t`): The length of the flatbuffer data span. - **example_factory** (`example_factory_t`): A function to create new examples. - **examples** (`VW::multi_ex &`): The container to store the converted examples. - **example_sink** (`example_sink_f`, optional): A function to process examples as they are read. Defaults to `nullptr`. - **status** (`VW::experimental::api_status *`, optional): Pointer to an API status object for error reporting. Defaults to `nullptr`. ``` -------------------------------- ### output_and_account_example Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespaceVW_1_1details.html Outputs an example and accounts for it in the Vowpal Wabbit workspace. ```APIDOC ## output_and_account_example() ### Description Outputs the provided example to the configured output streams and updates the Vowpal Wabbit workspace's internal accounting based on the example. ### Parameters - **_all_** (VW::workspace &) - The Vowpal Wabbit workspace object. - **_ec_** (const VW::example &) - A constant reference to the example to be processed. ``` -------------------------------- ### substring_to_example Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespaceVW_1_1parsers_1_1text_1_1details.html Converts a string view representing an example into a Vowpal Wabbit example structure. This function is used for parsing individual examples from text. ```APIDOC ## substring_to_example() ### Description Converts a string view representing an example into a Vowpal Wabbit example structure. ### Parameters - **_all_** (VW::workspace*): Pointer to the Vowpal Wabbit workspace. - **_ae_** (VW::example*): Pointer to the Vowpal Wabbit example structure to populate. - **_example_** (VW::string_view): A string view containing the text representation of the example. ``` -------------------------------- ### CB Sample Setup Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespaceVW_1_1reductions.html Sets up the CB sample reduction. ```APIDOC ## cb_sample_setup ### Description Sets up the CB sample reduction. ### Signature std::shared_ptr< VW::LEARNER::learner > cb_sample_setup (VW::setup_base_i &stack_builder) ``` -------------------------------- ### Start() Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/classVW_1_1spanning__tree-members.html Inline function to start the spanning tree. ```APIDOC ## Start() ### Description An inline function to start the spanning tree. This may be an alias or a more optimized version of `run()`. ### Method (Implicitly called, likely a starter) ### Endpoint N/A ### Parameters None ### Request Example ```cpp st.Start(); ``` ### Response None (Typically starts a process or performs an action) ``` -------------------------------- ### get_example Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespacemembers_g.html Retrieves an example. ```APIDOC ## get_example() ### Description Fetches a single example from the dataset or internal storage. ### Type VW ``` -------------------------------- ### example Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/functions_func_e.html Represents a single example in Vowpal Wabbit. ```APIDOC ## example() ### Description Represents a single data example used for training or prediction in Vowpal Wabbit. It encapsulates features, label, and other relevant information. ### Signature `example() : VW::example` ``` -------------------------------- ### CBify Setup Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespaceVW_1_1reductions.html Sets up the CBify reduction. ```APIDOC ## cbify_setup ### Description Sets up the CBify reduction. ### Signature std::shared_ptr< VW::LEARNER::learner > cbify_setup (VW::setup_base_i &stack_builder) ``` -------------------------------- ### learn Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/classVW_1_1workspace.html Learns from a single example or a collection of examples. ```APIDOC ## learn ### Description Learns from a single example or a collection of examples. ### Method Signature - `void learn(example &)` - `void learn(multi_ex &)` ``` -------------------------------- ### Create and Learn from a New Example Source: https://vowpalwabbit.org/docs/vowpal_wabbit/python/latest/examples/predict.html Constructs a new example from scratch, sets its label and features, and then learns from it multiple times. It also calculates and compares custom and Vowpal Wabbit predictions. ```python print("# make our own example from scratch") ex = vw.example() ex.set_label_string("0") ex.push_features("x", ["a", "b"]) ex.push_features("y", [("c", 1.0)]) ex.setup_example() print( " my view of example =", str([(f, v, vw.get_weight(f)) for f, v in ex.iter_features()]), ) my_pred2 = my_predict(vw, ex) print(" my partial prediction =", my_pred2) ensure_close(my_pred, my_pred2) ex.learn() ex.learn() ex.learn() ex.learn() print(" final partial prediction =", ex.get_updated_prediction()) ensure_close(ex.get_updated_prediction(), my_predict(vw, ex)) print("") vw.finish_example(ex) ``` -------------------------------- ### is_multiline() Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/classVW_1_1polymorphic__ex.html Checks if the current example is a multiline example. ```APIDOC ## is_multiline() ### Description Checks if the current example is a multiline example. ### Signature `bool VW::polymorphic_ex::is_multiline() const` ### Returns `true` if the example is multiline, `false` otherwise. ``` -------------------------------- ### mf_setup Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespaceVW_1_1reductions.html Sets up the Matrix Factorization (MF) learning algorithm. ```APIDOC ## mf_setup ### Description Sets up the Matrix Factorization (MF) learning algorithm. ### Signature std::shared_ptr< VW::LEARNER::learner > mf_setup (VW::setup_base_i &stack_builder) ``` -------------------------------- ### Observe Impact on Original Example Source: https://vowpalwabbit.org/docs/vowpal_wabbit/python/latest/examples/basics.html After training on a new example, observe how it affects the prediction of a previously trained example by removing its label, learning, and printing the prediction. ```python ex.set_label_string("") vw.learn(ex) print(f"current prediction = {ex.get_updated_prediction()}") ``` -------------------------------- ### VW::parser::reader Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/classVW_1_1parser.html A function pointer that reads and parses examples from an io_buf. It consumes the io_buf and produces parsed examples, with the number of produced examples being implementation-defined. ```APIDOC ## VW::parser::reader ### Description A function pointer that reads and parses examples from an `io_buf`. It consumes the `io_buf` and produces parsed examples. The number of produced examples is implementation-defined. For single-line parsers, a single example is produced. For multi-line parsers, multiple examples are produced, all corresponding to the same overall logical example. The `examples` must contain a single empty example when this call is made. ### Type `int(*)(VW::workspace *, io_buf &, VW::multi_ex &examples)` ``` -------------------------------- ### gd_setup Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespacemembers_g.html Sets up the Gradient Descent learner. ```APIDOC ## gd_setup() ### Description Configures the standard Gradient Descent learning algorithm. ### Namespace VW::reductions ``` -------------------------------- ### gd_setup Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespaceVW_1_1reductions.html Sets up the gd reduction. ```APIDOC ## gd_setup() ### Description Sets up the gd reduction. ### Signature std::shared_ptr< VW::LEARNER::learner > VW::reductions::gd_setup(VW::setup_base_i & _stack_builder_) ``` -------------------------------- ### start Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/functions_s.html Starts the spanning tree process (lowercase variant). ```APIDOC ## start() ### Description Starts the spanning tree process (lowercase variant). ### Signature `VW::spanning_tree start()` ``` -------------------------------- ### bs_setup Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespacemembers_b.html Sets up the BS (likely Bootstrap Sampling) reduction. ```APIDOC ## bs_setup() ### Description Sets up the BS (likely Bootstrap Sampling) reduction. ### Namespace VW::reductions ``` -------------------------------- ### Start Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/functions_s.html Starts the spanning tree process (uppercase variant). ```APIDOC ## Start() ### Description Starts the spanning tree process (uppercase variant). ### Signature `VW::spanning_tree Start()` ``` -------------------------------- ### append_example_namespaces_from_example Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespaceVW_1_1details.html Appends namespaces from a source example to a target example. ```APIDOC ## append_example_namespaces_from_example() Appends namespaces from a source example to a target example. ### Signature ```cpp void VW::details::append_example_namespaces_from_example(VW::example & _target_, const VW::example & _source_) ``` ### Parameters - `_target_` (VW::example &): The target example to which namespaces will be appended. - `_source_` (const VW::example &): The source example from which namespaces will be copied. ``` -------------------------------- ### pylibvw.example.__init__ Source: https://vowpalwabbit.org/docs/vowpal_wabbit/python/latest/reference/vowpalwabbit.pyvw.pylibvw.html Constructs an empty example. A label type must be provided. ```APIDOC ## pylibvw.example.__init__ ### Description Construct an empty example; you must provide a label type. ### Signature `__init__(self: pylibvw.example, arg0: pylibvw.vw, arg1: typing.SupportsInt | typing.SupportsIndex, arg2: pylibvw.example) -> None` ``` -------------------------------- ### read_example Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespacemembers_r.html Reads a single example. Returns the example object. ```APIDOC ## read_example() ### Description Reads a single example. ### Returns `VW` - The read example. ``` -------------------------------- ### expreplay_setup Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/namespaceVW_1_1reductions.html Sets up the expreplay reduction with a specified level and label parser. ```APIDOC ## expreplay_setup() ### Description Sets up the expreplay reduction with a specified level and label parser. ### Signature std::shared_ptr< VW::LEARNER::learner > VW::reductions::expreplay_setup(VW::setup_base_i & _stack_builder_) ``` -------------------------------- ### process_example Source: https://vowpalwabbit.org/docs/vowpal_wabbit/cpp/latest/classVW_1_1reductions_1_1automl_1_1interaction__config__manager.html Processes an incoming example for interaction configuration. ```APIDOC ## void process_example() template void VW::reductions::automl::interaction_config_manager< config_oracle_impl, estimator_impl >::process_example( const multi_ex & _ec_ ) ```