Module ImportFrom alias alias alias alias Expr Str Import alias Import alias Import alias ImportFrom alias Assign NameStore Num FunctionDef arguments args defaults body Expr Str Assign NameStore Call AttributeLoad NameLoad attr AttributeLoad NameLoad attr NameLoad Assign NameStore Call NameLoad ListComp NameLoad comprehension NameStore NameLoad CompareIn NameLoad AttributeLoad NameLoad attr Assign NameStore Call NameLoad ListComp NameLoad comprehension NameStore NameLoad CompareIn NameLoad AttributeLoad NameLoad attr If CompareGt NameLoad NameLoad body Assign NameStore Num orelse Assign NameStore Num Return TupleLoad NameLoad NameLoad decorator_list Assign NameStore Num Expr Call NameLoad Str Expr Call NameLoad Str NameLoad Assign NameStore Call NameLoad keyword Str keyword NameLoad keyword NameLoad Expr Call NameLoad Str Expr Call NameLoad Str AttributeLoad NameLoad attr Expr Call NameLoad Expr Call NameLoad Str For NameStore Call NameLoad Num body Assign TupleStore NameStore NameStore Call NameLoad If CompareGt NameLoad Num body Expr Call NameLoad Call AttributeLoad Str attr NameLoad NameLoad orelse Expr Call NameLoad Call AttributeLoad Str attr NameLoad NameLoad Expr Call AttributeLoad NameLoad attr NameLoad keyword NameLoad Expr Call NameLoad Expr Call NameLoad Str Assign NameStore Num Assign NameStore Num For NameStore Call NameLoad NameLoad body Assign TupleStore NameStore NameStore Call NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign TupleStore NameStore NameStore TupleLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr If CompareGt BinOpMult NameLoad NameLoad Num body AugAssignAdd NameStore Num Expr Call NameLoad Str NameLoad Str NameLoad Expr Call NameLoad Expr Call NameLoad Str Assign NameStore Num For NameStore Call NameLoad Num body Assign TupleStore NameStore NameStore Call NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad If CompareGtE AttributeLoad NameLoad attr Num body Expr Call NameLoad Call AttributeLoad Str attr NameLoad AttributeLoad NameLoad attr NameLoad Expr Call AttributeLoad NameLoad attr NameLoad keyword NameLoad AugAssignAdd NameStore Num Expr Call NameLoad Str NameLoad Str Expr Call NameLoad Expr Call NameLoad Str Assign NameStore Num Assign NameStore Num For NameStore Call NameLoad NameLoad body Assign TupleStore NameStore NameStore Call NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign TupleStore NameStore NameStore TupleLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr If CompareGt BinOpMult NameLoad NameLoad Num body AugAssignAdd NameStore Num Expr Call NameLoad Str NameLoad Str NameLoad Expr Call NameLoad Expr Call NameLoad Str Assign NameStore Num Assign NameStore ListComp Call NameLoad comprehension NameStore Call NameLoad NameLoad Expr Call NameLoad Str NameLoad Str Assign NameStore Num Assign NameStore Call AttributeLoad NameLoad attr For NameStore NameLoad body Assign TupleStore NameStore NameStore NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad If CompareGtE AttributeLoad NameLoad attr Num body Expr Call AttributeLoad NameLoad attr NameLoad keyword NameLoad AugAssignAdd NameStore Num Expr Call NameLoad Str NameLoad Str Assign NameStore BinOpSub Call AttributeLoad NameLoad attr NameLoad Assign NameStore BinOpDiv NameLoad NameLoad Expr Call NameLoad Str NameLoad Str Assign NameStore Call AttributeLoad NameLoad attr Expr Call NameLoad Str NameLoad Str For NameStore NameLoad body Assign TupleStore NameStore NameStore NameLoad Assign NameStore Call AttributeLoad NameLoad attr NameLoad Assign TupleStore NameStore NameStore TupleLoad AttributeLoad NameLoad attr AttributeLoad NameLoad attr Assign NameStore BinOpSub Call AttributeLoad NameLoad attr NameLoad Assign NameStore BinOpDiv NameLoad NameLoad Expr Call NameLoad Str NameLoad Str
N/A __future__ print_function division absolute_import unicode_literals N/A 
Demonstrate Wabbit Wappa by learning to tell capital letters from lowercase.


by Michael J.T. O'Kelly, 2014-04-02
 N/A string N/A random N/A time wabbit_wappa * N/A NUM_SAMPLES 9 get_example N/A N/A N/A N/A N/A Make an example for training and testing.  Outputs a tuple
    (label, features) where label is +1 if capital letters are the majority,
    and -1 otherwise; and features is a list of letters.
     N/A features N/A N/A random sample N/A string ascii_letters NUM_SAMPLES N/A num_capitalized N/A len N/A letter N/A letter features N/A letter N/A string ascii_uppercase N/A num_lowercase N/A len N/A letter N/A letter features N/A letter N/A string ascii_lowercase N/A N/A num_capitalized num_lowercase N/A N/A label 1 N/A N/A label -1 N/A N/A label features N/A N/A MELLOWNESS 0.1 N/A N/A print Start a Vowpal Wabbit learner in logistic regression mode N/A N/A print Active Learning mellowness: MELLOWNESS N/A vw N/A VW loss_function logistic active_mode True active_mellowness MELLOWNESS N/A N/A print vw = VW(loss_function='logistic') N/A N/A print VW command: N/A vw command N/A N/A print N/A N/A print Now generate 10 training examples, feeding them to VW one by one. N/A i N/A range 10 N/A N/A N/A label features N/A get_example N/A N/A label 0 N/A N/A N/A print N/A N/A Label {}: {} is mostly uppercase format label features N/A N/A N/A print N/A N/A Label {}: {} is mostly lowercase format label features N/A N/A N/A vw send_example label features features N/A N/A print N/A N/A print How well trained is our model?  Let's make 100 tests. N/A num_tests 100 N/A num_good_tests 0 N/A i N/A range num_tests N/A N/A N/A label features N/A get_example N/A response N/A N/A vw get_prediction features N/A N/A prediction importance N/A N/A response prediction N/A response importance N/A N/A N/A prediction label 0 N/A N/A num_good_tests 1 N/A N/A print Correctly predicted num_good_tests out of num_tests N/A N/A print N/A N/A print Let's generate 1,000 more samples for training, sending labels only for those the Active Learner marks as important N/A important_example_count 0 N/A i N/A range 1000 N/A N/A N/A label features N/A get_example N/A response N/A N/A vw get_prediction features N/A N/A N/A response importance 1.0 N/A N/A N/A print N/A N/A Training with example {}, importance {}: {} format i N/A response importance features N/A N/A N/A vw send_example label features features N/A important_example_count 1 N/A N/A print Found important_example_count important examples N/A N/A print N/A N/A print Now how good are our predictions? N/A num_tests 100 N/A num_good_tests 0 N/A i N/A range num_tests N/A N/A N/A label features N/A get_example N/A response N/A N/A vw get_prediction features N/A N/A prediction importance N/A N/A response prediction N/A response importance N/A N/A N/A prediction label 0 N/A N/A num_good_tests 1 N/A N/A print Correctly predicted num_good_tests out of num_tests N/A N/A print N/A N/A print How fast can we train and test? N/A num_examples 10000 N/A examples N/A N/A get_example N/A i N/A range num_examples N/A N/A print Training on num_examples examples... N/A important_example_count 0 N/A start_time N/A N/A time time N/A example examples N/A N/A N/A label features example N/A response N/A N/A vw get_prediction features N/A N/A N/A response importance 1 N/A N/A N/A N/A vw send_example label features features N/A important_example_count 1 N/A N/A print Found important_example_count important examples N/A duration N/A N/A N/A time time start_time N/A frequency N/A num_examples duration N/A N/A print Trained frequency examples per second N/A start_time N/A N/A time time N/A N/A print Testing on num_examples examples... N/A example examples N/A N/A N/A label features example N/A response N/A N/A vw get_prediction features N/A N/A prediction importance N/A N/A response prediction N/A response importance N/A duration N/A N/A N/A time time start_time N/A frequency N/A num_examples duration N/A N/A print Tested frequency examples per second