-
Notifications
You must be signed in to change notification settings - Fork 1.9k
What is a learner?
A learner, more commonly called a reduction (I will use the terms interchangeably), represents one stage in the reduction stack. An invocation of VW involves transforming a problem from one type to another through a set of reductions. This allows us to leverage hardened solutions to existing problems to solve new problems.
This document is about describing concretely how one of these reductions is implemented in the codebase.
It is defined by a set of types, functions and a couple of fields.
There are several explicit types, but also several implicit that must match otherwise there will be bugs.
A learner is defined explicitly (in template parameters) by:
-
T
- The type of the data object of this reduction, refered to hereafter asDataT
-
E
- The type of example this reduction expects. Eitherexample
ormulti_ex
. Refered to hereafter asExampleT
A learner is defined implicitly by:
- The base learner (or next learner) that this reduction references in its
predict
/learn
/update
/multipredict
functions. I'll call thisBaseT
- The label type that this learner expects examples to have, let's call it
LabelT
- The prediction type that this learner produces, let's call this one
PredictionT
-
prediction_type_t pred_type
- An enum that corresponds toPredictionT
-
size_t weights
- Describes how many weight vectors are required by this learner. This means that there can essentially be several models that are referenced by this learner. -
size_t increment
- Used along with the per call increment to reference different weight vectors -
bool is_multiline
-true
if the expectedExampleT
ismulti_ex
, otherwisefalse
For the overwhelming majority of reductions only learn
, predict
and finish_example
are important.
Auto-recursion is where for a function each reduction in the stack is invoked in sequence automatically, without the called function knowing about it. Some functions may call the base (next) reduction in the stack explicitly.
This is called once by the driver when it starts up. This does not auto-recurse, the topmost definition will be used.
void(DataT* data);
These three functions are perhaps the most important. They defined the core learning process. update
is not commonly used and by default it simply refers to learn
.
These functions will not auto-recurse, however, in nearly all cases the you want the result of the next reduction and so they often do recurse. This is up to the reduction to implement.
Each example passed to this function implicitly has a valid LabelT
object associated with it. Additionally for ExampleT == example
there is an allocated and empty PredictionT
object on the example. For ExampleT == multi_ex
there is an allocated and empty PredictionT
object on the zeroth example.
When the BaseT
base learner is called, any examples that are passed to it MUST adhere to the contract defined in the previous paragraph but for the LabelT
and PredictionT
values associated with that BaseT
. Thi is a very important implicit contract that if broken causes serious and sometimes hard to find bugs. Especially because LabelT
and PredictionT
are stored in unions.
void(DataT* data, BaseT* base_learner, ExampleT* example);
Multipredict does not need to be defined as the default implementation will use predict
. It makes several predictions using one example, each call increments the offset and so it is effectively using a different weight vector. This is often used internally in reductions but not often used externally.
void(DataT* data, BaseT& base, ExampleT* ex, size_t count, size_t step, polyprediction* pred, bool finalize_predictions);
-
pred
is an array ofcount
number ofpolyprediction
objects. -
step
is the weight increment to be applied per prediction
Does not auto-recurse.
float(DataT* data, BaseT* base, ExampleT* example);
Finish example is called after learn
/predict
and is where the reduction must calculate and report loss as well as free any resources that were allocated for that example. Additionally, the example label and prediction must be returned to a clean slate.
void(vw&, DataT* data, EaxmpleT* ex);
Called at the end of a learning pass. This function is autorecursive.
void(DataT* data);
Called once all of the examples are finished being parsed and processed by the reduction stack. This function is autorecursive.
void(DataT* data);
Called as the reduction is being destroyed. However, do note that the destructor of DataT
WILL be called, so often this function is not necessary. This function is autorecursive.
void(DataT* data);
This is how the reduction implements serialization and deserialization from a model file. This function is auto recursive.
void(DataT* data, io_buf* model_buffer, bool read, bool text);
-
read
is true if a model file is being read and false if the expectation is to write to the buffer -
text
means that a readable model should be written instead of binary
- Home
- First Steps
- Input
- Command line arguments
- Model saving and loading
- Controlling VW's output
- Audit
- Algorithm details
- Awesome Vowpal Wabbit
- Learning algorithm
- Learning to Search subsystem
- Loss functions
- What is a learner?
- Docker image
- Model merging
- Evaluation of exploration algorithms
- Reductions
- Contextual Bandit algorithms
- Contextual Bandit Exploration with SquareCB
- Contextual Bandit Zeroth Order Optimization
- Conditional Contextual Bandit
- Slates
- CATS, CATS-pdf for Continuous Actions
- Automl
- Epsilon Decay
- Warm starting contextual bandits
- Efficient Second Order Online Learning
- Latent Dirichlet Allocation
- VW Reductions Workflows
- Interaction Grounded Learning
- CB with Large Action Spaces
- CB with Graph Feedback
- FreeGrad
- Marginal
- Active Learning
- Eigen Memory Trees (EMT)
- Element-wise interaction
- Bindings
-
Examples
- Logged Contextual Bandit example
- One Against All (oaa) multi class example
- Weighted All Pairs (wap) multi class example
- Cost Sensitive One Against All (csoaa) multi class example
- Multiclass classification
- Error Correcting Tournament (ect) multi class example
- Malicious URL example
- Daemon example
- Matrix factorization example
- Rcv1 example
- Truncated gradient descent example
- Scripts
- Implement your own joint prediction model
- Predicting probabilities
- murmur2 vs murmur3
- Weight vector
- Matching Label and Prediction Types Between Reductions
- Zhen's Presentation Slides on enhancements to vw
- EZExample Archive
- Design Documents
- Contribute: