vowpalwabbit.pyvw.pylibvw

The Python bindings employ native bindings and then inherit from this in Python to add extra functionality. The classes on this page should not be directly instantiated. The types in vowpalwabbit should be used instead.

class vowpalwabbit.pyvw.pylibvw.vw

Bases: instance

the basic VW object that holds with weight vector, parser, etc.

__init__((object)arg1, (list)arg2) object

__init__( (object)arg1, (list)arg2, (vw_log)arg3) -> object

audit_example((vw)arg1, (example)arg2) None :

print example audit information

finish((vw)arg1) None :

stop VW by calling finish (and, eg, write weights to disk)

get_arguments((vw)arg1) str :

return the arguments after resolving all dependencies

get_enabled_learners((vw)arg1) list :

return the list of names of the enabled learners

get_enabled_reductions((vw)arg1) list :

return the list of names of the enabled learners

get_holdout_sum_loss((vw)arg1) float :

return the total cumulative holdout loss suffered so far

get_id((vw)arg1) str :

return the model id

get_learner_metrics((vw)arg1) dict :

get current learner stack metrics. returns empty dict if –extra_metrics was not supplied.

get_options((vw)arg1, (object)arg2, (bool)arg3) object :

get available vw options

get_search_ptr((vw)arg1) search :

return a pointer to the search data structure

get_stride((vw)arg1) int :

return the internal stride

get_sum_loss((vw)arg1) float :

return the total cumulative loss suffered so far

get_weight((vw)arg1, (int)arg2, (int)arg3) float :

get the weight for a particular index

get_weighted_examples((vw)arg1) float :

return the total weight of examples so far

hash_feature((vw)arg1, (str)arg2, (int)arg3) int :

given a feature string (arg2) and a hashed namespace (arg3), hash that feature

hash_space((vw)arg1, (str)arg2) int :

given a namespace (as a string), compute the hash of that namespace

json_weights((vw)arg1) str :

get json string of current weights

lBinary = 1
lConditionalContextualBandit = 6
lContextualBandit = 4
lContextualBanditEval = 9
lContinuous = 8
lCostSensitive = 3
lDefault = 0
lMax = 5
lMulticlass = 2
lMultilabel = 10
lSimple = 1
lSlates = 7
learn((vw)arg1, (example)arg2) None :

given a pyvw example, learn (and predict) on that example

learn_multi((vw)arg1, (list)arg2) None :

given a list pyvw examples, learn (and predict) on those examples

num_weights((vw)arg1) int :

how many weights are we learning?

pACTION_PDF_VALUE = 9
pACTION_PROBS = 3
pACTION_SCORES = 2
pACTIVE_MULTICLASS = 11
pDECISION_SCORES = 8
pMULTICLASS = 4
pMULTICLASSPROBS = 7
pMULTILABELS = 5
pNOPRED = 12
pPDF = 10
pPROB = 6
pSCALAR = 0
pSCALARS = 1
predict((vw)arg1, (example)arg2) float :

given a pyvw example, predict on that example

predict_multi((vw)arg1, (list)arg2) None :

given a list of pyvw examples, predict on that example

run_parser((vw)arg1) None :

parse external data file

save((vw)arg1, (str)arg2) None :

save model to filename

set_weight((vw)arg1, (int)arg2, (int)arg3, (float)arg4) None :

set the weight for a particular index

setup_example((vw)arg1, (example)arg2) None :

given an example that you’ve created by hand, prepare it for learning (eg, compute quadratic feature)

tACTION = 1
tSHARED = 0
tSLOT = 2
tUNSET = 3
unsetup_example((vw)arg1, (example)arg2) None :

reverse the process of setup, so that you can go back and modify this example

class vowpalwabbit.pyvw.pylibvw.example

Bases: instance

__init__((object)arg1, (vw)arg2, (int)arg3, (str)arg4) object :

Given a string as an argument parse that into a VW example (and run setup on it) – default to multiclass label type

__init__( (object)arg1, (vw)arg2, (int)arg3) -> object :

Construct an empty (non setup) example; you must provide a label type (vw.lBinary, vw.lMulticlass, etc.)

__init__( (object)arg1, (vw)arg2, (int)arg3, (example)arg4) -> object :

Create a new example object pointing to an existing object.

ensure_namespace_exists((example)arg1, (int)arg2) None :

Add a new namespace if it doesn’t already exist

erase_namespace((example)arg1, (int)arg2) None :

Remove all the features from a given namespace

feature((example)arg1, (int)arg2, (int)arg3) int :

Get the feature id for the ith feature in a given namespace id (id=character-ord)

feature_weight((example)arg1, (int)arg2, (int)arg3) float :

The the feature value (weight) per .feature(…)

get_action_pdf_value((example)arg1) tuple :

Get action and pdf value from example prediction

get_action_scores((example)arg1) list :

Get action scores from example prediction

get_active_multiclass((example)arg1) tuple :

Get active multiclass from example prediction

get_cb_continuous_class((example)arg1, (int)arg2) int :

Assuming a cb_continuous label type, get the label at a given index (i=0.. get_cb_continuous_num_costs)

get_cb_continuous_cost((example)arg1, (int)arg2) float :

Assuming a cb_continuous label type, get the cost at a given index (i=0.. get_cb_continuous_num_costs)

get_cb_continuous_num_costs((example)arg1) int :

Assuming a cb_continuous label type, get the total number of costs

get_cb_continuous_pdf_value((example)arg1, (int)arg2) float :

Assuming a cb_continuous label type, get the pdf_value at a given index (i=0.. get_cb_continuous_num_costs)

get_cb_eval_action((example)arg1) int :

Assuming a cb_eval label type, get action

get_cb_eval_class((example)arg1, (int)arg2) int :

Assuming a cb_eval label type, get the label for a given pair (i=0.. get_cb_eval_num_costs)

get_cb_eval_cost((example)arg1, (int)arg2) float :

Assuming a cb_eval label type, get the cost for a given pair (i=0.. get_cb_eval_num_costs)

get_cb_eval_num_costs((example)arg1) int :

Assuming a cb_eval label type, get the total number of label/cost pairs

get_cb_eval_partial_prediction((example)arg1, (int)arg2) float :

Assuming a cb_eval label type, get the partial prediction for a given pair (i=0.. get_cb_eval_num_costs)

get_cb_eval_probability((example)arg1, (int)arg2) float :

Assuming a cb_eval label type, get the bandits probability for a given pair (i=0.. get_cb_eval_num_costs)

get_cb_eval_weight((example)arg1) int :

Assuming a cb_eval label type, get weight

get_cbandits_class((example)arg1, (int)arg2) int :

Assuming a contextual_bandits label type, get the label for a given pair (i=0.. get_cbandits_num_costs)

get_cbandits_cost((example)arg1, (int)arg2) float :

Assuming a contextual_bandits label type, get the cost for a given pair (i=0.. get_cbandits_num_costs)

get_cbandits_num_costs((example)arg1) int :

Assuming a contextual_bandits label type, get the total number of label/cost pairs

get_cbandits_partial_prediction((example)arg1, (int)arg2) float :

Assuming a contextual_bandits label type, get the partial prediction for a given pair (i=0.. get_cbandits_num_costs)

get_cbandits_prediction((example)arg1) int :

Assuming a contextual_bandits label type, get the prediction

get_cbandits_probability((example)arg1, (int)arg2) float :

Assuming a contextual_bandits label type, get the bandits probability for a given pair (i=0.. get_cbandits_num_costs)

get_cbandits_weight((example)arg1) int :

Assuming a contextual_bandits label type, get the weight

get_ccb_action((example)arg1, (int)arg2) int :

Assuming a conditional_contextual_bandits label type, get the action of example at index i

get_ccb_cost((example)arg1) float :

Assuming a conditional_contextual_bandits label type, get the cost of the given label

get_ccb_explicitly_included_actions((example)arg1) list :

Assuming a conditional_contextual_bandits label type, get the array of explicitly included actions for the slot

get_ccb_has_outcome((example)arg1) bool :

Assuming a conditional_contextual_bandits label type, verify if it has an outcome.

get_ccb_num_explicitly_included_actions((example)arg1) int :

Assuming a conditional_contextual_bandits label type, get the number of included actions.

get_ccb_num_probabilities((example)arg1) int :

Assuming a conditional_contextual_bandits label type, get number of actions in example

get_ccb_probability((example)arg1, (int)arg2) float :

Assuming a conditional_contextual_bandits label type, get the probability of example at index i

get_ccb_type((example)arg1) int :

Assuming a conditional_contextual_bandits label type, get the type of example

get_ccb_weight((example)arg1) float :

Assuming a conditional_contextual_bandits label type, get the weight of the example.

get_costsensitive_class((example)arg1, (int)arg2) int :

Assuming a cost_sensitive label type, get the label for a given pair (i=0.. get_costsensitive_num_costs)

get_costsensitive_cost((example)arg1, (int)arg2) float :

Assuming a cost_sensitive label type, get the cost for a given pair (i=0.. get_costsensitive_num_costs)

get_costsensitive_num_costs((example)arg1) int :

Assuming a cost_sensitive label type, get the total number of label/cost pairs

get_costsensitive_partial_prediction((example)arg1, (int)arg2) float :

Assuming a cost_sensitive label type, get the partial prediction for a given pair (i=0.. get_costsensitive_num_costs)

get_costsensitive_prediction((example)arg1) int :

Assuming a cost_sensitive label type, get the prediction

get_costsensitive_wap_value((example)arg1, (int)arg2) float :

Assuming a cost_sensitive label type, get the weighted-all-pairs recomputed cost for a given pair (i=0.. get_costsensitive_num_costs)

get_decision_scores((example)arg1) list :

Get decision scores from example prediction

get_example_counter((example)arg1) int :

Returns the counter of total number of examples seen up to and including this one

get_feature_number((example)arg1) int :

Returns the total number of features for this example

get_ft_offset((example)arg1) int :

Returns the feature offset for this example (used, eg, by multiclass classification to bulk offset all features)

get_loss((example)arg1) float :

Returns the loss associated with this example

get_multiclass_label((example)arg1) int :

Assuming a multiclass label type, get the true label

get_multiclass_prediction((example)arg1) int :

Assuming a multiclass label type, get the prediction

get_multiclass_weight((example)arg1) float :

Assuming a multiclass label type, get the importance weight

get_multilabel_labels((example)arg1) list :

Assuming a multilabel label type, get a list of labels

get_multilabel_predictions((example)arg1) list :

Get multilabel predictions from example prediction

get_partial_prediction((example)arg1) float :

Returns the partial prediction associated with this example

get_pdf((example)arg1) list :

Get pdf from example prediction

get_prob((example)arg1) float :

Get probability from example prediction

get_scalars((example)arg1) list :

Get scalar values from example prediction

get_simplelabel_initial((example)arg1) float :

Assuming a simple_label label type, return the initial (baseline) prediction

get_simplelabel_label((example)arg1) float :

Assuming a simple_label label type, return the corresponding label (class/regression target/etc.)

get_simplelabel_prediction((example)arg1) float :

Assuming a simple_label label type, return the final prediction

get_simplelabel_weight((example)arg1) float :

Assuming a simple_label label type, return the importance weight

get_slates_action((example)arg1, (int)arg2) int :

Assuming a slates label type, get the action of example at index i

get_slates_cost((example)arg1) float :

Assuming a slates label type, get the cost of example

get_slates_labeled((example)arg1) bool :

Assuming a slates label type, get if example is labeled

get_slates_num_probabilities((example)arg1) int :

Assuming a slates label type, get number of actions in example

get_slates_probability((example)arg1, (int)arg2) float :

Assuming a slates label type, get the probability of example at index i

get_slates_slot_id((example)arg1) int :

Assuming a slates label type, get the slot_id of example

get_slates_type((example)arg1) int :

Assuming a slates label type, get the type of example

get_slates_weight((example)arg1) float :

Assuming a slates label type, get the weight of example

get_tag((example)arg1) str :

Returns the tag associated with this example

get_topic_prediction((example)arg1, (int)arg2) float :

For LDA models, returns the topic prediction for the topic id given

get_total_sum_feat_sq((example)arg1) float :

The total sum of feature-value squared for this example

get_updated_prediction((example)arg1) float :

Returns the partial prediction as if we had updated it after learning

namespace((example)arg1, (int)arg2) int :

Get the namespace id for namespace i (for i = 0.. num_namespaces); specifically returns the ord() of the corresponding character id

num_features_in((example)arg1, (int)arg2) int :

Get the number of features in a given namespace id (id=character-ord)

num_namespaces((example)arg1) int :

The total number of namespaces associated with this example

pop_feature((example)arg1, (int)arg2) bool :

Remove the top feature from a given namespace; returns True iff the list was non-empty

pop_namespace((example)arg1) bool :

Remove the top namespace off; returns True iff the list was non-empty

push_feature_dict((example)arg1, (vw)arg2, (object)arg3) None :

Add a (Python) dictionary of namespace/feature-list pairs

push_feature_list((example)arg1, (vw)arg2, (int)arg3, (int)arg4, (list)arg5) None :

Add a (Python) list of features to a given namespace

push_hashed_feature((example)arg1, (int)arg2, (int)arg3, (float)arg4) None :

Add a hashed feature to a given namespace (id=character-ord)

push_namespace((example)arg1, (int)arg2) None :

Add a new namespace

set_label_string((example)arg1, (vw)arg2, (str)arg3, (int)arg4) None :

(Re)assign the label of this example to this string

set_test_only((example)arg1, (bool)arg2) None :

Change the test-only bit on an example

sum_feat_sq((example)arg1, (int)arg2) float :

Get the sum of feature-values squared for a given namespace id (id=character-ord)