### Creating and Validating Example from Scratch - Vowpal Wabbit - Python Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/python/docs/source/examples/predict.ipynb Creates an empty example, manually sets its label and features, sets up the example, compares predictions before learning, performs multiple learning steps, compares predictions after learning, and finishes the example. ```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) ``` -------------------------------- ### Vowpal Wabbit Input Example 1 Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/vowpalwabbit/slim/test/data/cb_data_5.txt An example demonstrating the Vowpal Wabbit input format, including a shared example line and subsequent individual example lines with features and namespaces. ```Vowpal Wabbit Input shared |a 0:1 5:12 0:1.0:0.3 |b 0:1 |b 0:2 |b 0:3 ``` -------------------------------- ### Learning and Getting Prediction on VowpalWabbit Example (String Input) Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/python/docs/source/examples/basics.ipynb Trains the VowpalWabbit model on the provided example (`ex`) and then retrieves the prediction that would be made on this example *after* the learning step. `get_updated_prediction()` is used to get this post-learning prediction. ```python vw.learn(ex) print(f"current prediction = {ex.get_updated_prediction()}") ``` -------------------------------- ### Example Vowpal Wabbit Input Line (Label 1) Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/java/src/test/resources/test.txt An example line in the Vowpal Wabbit input format. It starts with the label '1', followed by a feature namespace 'a', and then lists features ':1', ':2', and ':3' within that namespace. ```Vowpal Wabbit Format 1 |a :1 :2 :3 ``` -------------------------------- ### Example Vowpal Wabbit Input Line (Label 0) Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/java/src/test/resources/test.txt An example line in the Vowpal Wabbit input format. It starts with the label '0', followed by a feature namespace 'a', and then lists features ':1', ':2', and ':3' within that namespace. ```Vowpal Wabbit Format 0 |a :1 :2 :3 ``` -------------------------------- ### Iterating and Inspecting Example Properties - Vowpal Wabbit - Python Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/python/docs/source/examples/predict.ipynb Loops through examples, performs learning, and prints various properties like tag, partial prediction, loss, and label before finishing each example. ```python for i in range(2): ex = vw.example("1 foo| a b") ex.learn() print("tag =", ex.get_tag()) print("partial pred =", ex.get_partial_prediction()) print("loss =", ex.get_loss()) print("label =", ex.get_label()) vw.finish_example(ex) ``` -------------------------------- ### Install VowpalWabbit.JSON Main Artifacts (CMake) Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/cs/cs_json/netstandard/CMakeLists.txt This command defines installation rules for the main VowpalWabbit.JSON assembly (`.dll`), its debugging symbols (`.pdb`), and dependency information (`.deps.json`). These files are installed to a runtime-specific directory under `./runtimes/${NUGET_RUNTIME_ID}/lib/netstandard2.1`. ```CMake install( FILES "$/VowpalWabbit.JSON.dll" "$/VowpalWabbit.JSON.pdb" "$/VowpalWabbit.JSON.deps.json" DESTINATION "./runtimes/${NUGET_RUNTIME_ID}/lib/netstandard2.1" ) ``` -------------------------------- ### Install VowpalWabbit.JSON Reference Assembly (CMake) Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/cs/cs_json/netstandard/CMakeLists.txt This command defines installation rules specifically for the VowpalWabbit.JSON reference assembly. This assembly is installed to the `./ref/netstandard2.1` directory, typically used for compiling against the library. ```CMake install( FILES "$/ref/VowpalWabbit.JSON.dll" DESTINATION "./ref/netstandard2.1" ) ``` -------------------------------- ### Example Vowpal Wabbit Data Format Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/vowpalwabbit/slim/test/data/multiclass_data_4.txt This snippet shows a simple example of Vowpal Wabbit's input data format. The first line represents shared features ('|a 0:1 5:12') that apply to subsequent examples. The following lines are individual examples, each starting with a label (e.g., '1:1.0'), followed by a namespace ('|b'), and then sparse features (e.g., '0:1', '0:2', '0:3') represented as index:value pairs. ```Vowpal Wabbit Data Format shared |a 0:1 5:12 1:1.0 |b 0:1 2:0.3 |b 0:2 3:0.1 |b 0:3 ``` -------------------------------- ### Making Prediction with Vowpal Wabbit Model Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/python/docs/source/tutorials/python_first_steps.ipynb Defines a single test example in Vowpal Wabbit's text format and uses the 'predict' method of the trained model instance to get a prediction for this example. The prediction result is then printed to the console. ```python test_example = "| price:.46 sqft:.4 age:.10 1924" prediction = model.predict(test_example) print(prediction) ``` -------------------------------- ### Example Data Points Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/vowpalwabbit/slim/test/data/regression_data_7.txt These lines demonstrate the basic Vowpal Wabbit input format. Each line starts with a label (1 or 0), followed by feature namespaces (prefixed by '|'). Within each namespace, features are listed as name:value pairs. ```Vowpal Wabbit Data Format 1 |a x:1 |b y:2 0 |a x:1 |5 y:4 ``` -------------------------------- ### Processing and Validating Read Example - Vowpal Wabbit - Python Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/python/docs/source/examples/predict.ipynb Creates an example from a string, performs multiple learning steps, retrieves the updated prediction, compares it against a custom prediction function, and finishes the example. ```python print("# do some stuff with a read example:") ex = vw.example("1 |x a b |y c") ex.learn() ex.learn() ex.learn() ex.learn() updated_pred = ex.get_updated_prediction() print("current partial prediction =", updated_pred) # compute our own prediction print( " my view of example =", str([(f, v, vw.get_weight(f)) for f, v in ex.iter_features()]), ) my_pred = my_predict(vw, ex) print(" my partial prediction =", my_pred) ensure_close(updated_pred, my_pred) print("") vw.finish_example(ex) ``` -------------------------------- ### Setting Label and Iterative Learning on VowpalWabbit Example (Dictionary Input) Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/python/docs/source/examples/basics.ipynb Sets a label ("-2.0") on the dictionary-created example (`ex2`), converting it into a training example. It then trains the model on this example multiple times (5 times) and prints the final prediction after training. ```python ex2.set_label_string("-2.0") for _ in range(5): vw.learn(ex2) print(f"current prediction = {ex2.get_updated_prediction()}") ``` -------------------------------- ### Vowpal Wabbit Input Example 2 Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/vowpalwabbit/slim/test/data/cb_data_5.txt Another example of the Vowpal Wabbit input format, showing variations in feature values and labels compared to the first example. ```Vowpal Wabbit Input shared |a 0:4 5:12 |b 0:1 0:1.0:0.4 |b 0:2 |b 0:3 ``` -------------------------------- ### Implementing Search Task Logic (_run method) (Python) Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/python/docs/source/examples/search_sequence_ldf.ipynb Implements the core logic of the search task in the `_run` method. It iterates through the input sentence, creates LDF examples for each possible tag for the current word, uses `self.sch.predict` to get a prediction conditioned on previous predictions, and collects the predictions. The `vw.finish_example` call ensures proper example lifecycle management. ```python def _run( self, sentence ): # it's called _run to remind you that you shouldn't call it directly! output = [] for n in range(len(sentence)): pos, word = sentence[n] # use "with...as..." to guarantee that the example is finished properly ex = [self.makeExample(word, p) for p in [DET, NOUN, VERB, ADJ]] pred = self.sch.predict( examples=ex, my_tag=n + 1, oracle=pos, condition=(n, "p") ) vw.finish_example(ex) output.append(pred) return output ``` -------------------------------- ### Install VowpalWabbit.Common Target (CMake) Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/cs/common/CMakeLists.txt Configures the installation rule for the VowpalWabbit.Common library, specifying that the runtime artifact should be placed in a framework-specific subdirectory within the library installation directory. ```CMake install(TARGETS VowpalWabbit.Common RUNTIME DESTINATION "${CMAKE_INSTALL_LIBDIR}/${VW_NET_FRAMEWORK_TFM}" ) ``` -------------------------------- ### Define Installation Rules (CMake) Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/cs/cs_json/CMakeLists.txt Specifies the installation rules for the VowpalWabbit.JSON target, placing the runtime library in a framework-specific subdirectory within the installation library directory. ```CMake install(TARGETS VowpalWabbit.JSON RUNTIME DESTINATION "${CMAKE_INSTALL_LIBDIR}/${VW_NET_FRAMEWORK_TFM}" ) ``` -------------------------------- ### Install Target VowpalWabbit CMake Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/cs/cs/CMakeLists.txt Configures the installation rule for the `VowpalWabbit` target, specifying that the runtime components should be installed to a subdirectory based on the .NET framework target moniker. ```CMake install(TARGETS VowpalWabbit RUNTIME DESTINATION "${CMAKE_INSTALL_LIBDIR}/${VW_NET_FRAMEWORK_TFM}" ) ``` -------------------------------- ### Managing Example Lifecycles in a List - Vowpal Wabbit - Python Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/python/docs/source/examples/predict.ipynb Demonstrates creating a list of examples and explicitly finishing them using `vw.finish_example()` to manage memory and allow reuse within Vowpal Wabbit. ```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) ``` -------------------------------- ### Validate Build Options and Warn CMake Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/CMakeLists.txt Checks for specific combinations of build options that are either unsupported or not recommended, issuing warnings or fatal errors to guide the user towards a valid configuration. Examples include installing with vendored dependencies or enabling gcov without a Debug build. ```CMake if(VW_INSTALL AND NOT VW_ZLIB_SYS_DEP) message(WARNING "Installing with a vendored version of zlib is not recommended. Use VW_ZLIB_SYS_DEP to use a system dependency or specify VW_INSTALL=OFF to silence this warning.") endif() # The only way to tell it was used is if it was turned off, since the default is true. if(DEFINED BUILD_TESTS) message(WARNING "Value of BUILD_TESTS option ignored. Please use the standard option BUILD_TESTING.") endif() if(VW_INSTALL AND NOT FMT_SYS_DEP) message(WARNING "Installing with a vendored version of fmt is not recommended. Use FMT_SYS_DEP to use a system dependency or specify VW_INSTALL=OFF to silence this warning.") endif() if(VW_INSTALL AND NOT SPDLOG_SYS_DEP) message(WARNING "Installing with a vendored version of spdlog is not recommended. Use SPDLOG_SYS_DEP to use a system dependency or specify VW_INSTALL=OFF to silence this warning.") endif() if(VW_INSTALL AND NOT RAPIDJSON_SYS_DEP) message(WARNING "Installing with a vendored version of rapidjson is not recommended. Use RAPIDJSON_SYS_DEP to use a system dependency or specify VW_INSTALL=OFF to silence this warning.") endif() if(VW_GCOV AND (NOT CMAKE_BUILD_TYPE STREQUAL "Debug")) message(FATAL_ERROR "VW_GCOV requires Debug build type.") endif() if(WIN32 AND (STATIC_LINK_VW OR BUILD_JAVA OR VW_GOV)) message(FATAL_ERROR "Unsupported option enabled on Windows build") endif() ``` -------------------------------- ### CCB Action Features Example Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/test/train-sets/ccb_losses.txt This line represents features specific to a particular action within a CCB example. It starts with 'ccb action' followed by feature namespaces and features. ```Vowpal Wabbit Input ccb action |TAction af:1.0 ``` -------------------------------- ### Training Vowpal Wabbit Model with Examples Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/python/docs/source/tutorials/python_first_steps.ipynb Defines a list of training examples in Vowpal Wabbit's text format and iterates through them, calling the 'learn' method on the Vowpal Wabbit workspace instance to train the model incrementally. ```python train_examples = [ "0 | price:.23 sqft:.25 age:.05 2006", "1 | price:.18 sqft:.15 age:.35 1976", "0 | price:.53 sqft:.32 age:.87 1924", ] for example in train_examples: model.learn(example) ``` -------------------------------- ### CCB Action Features Example Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/test/train-sets/ccb_losses.txt This line represents features specific to a particular action within a CCB example. It starts with 'ccb action' followed by feature namespaces and features. ```Vowpal Wabbit Input ccb action |TAction af:2.0 ``` -------------------------------- ### Initializing VowpalWabbit Workspace in Python Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/python/docs/source/examples/basics.ipynb Creates a new VowpalWabbit workspace instance. This initializes the learning environment, allowing configuration via command-line arguments passed as Python keyword arguments (e.g., `quiet=True`, `q="ab"`, `l2=0.01`). ```python vw = vowpalwabbit.Workspace(quiet=True, q="ab", l2=0.01) ``` -------------------------------- ### CCB Action Features Example Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/test/train-sets/ccb_losses.txt This line represents features specific to a particular action within a CCB example. It starts with 'ccb action' followed by feature namespaces and features. ```Vowpal Wabbit Input ccb action |TAction af:3.0 ``` -------------------------------- ### CCB Shared Features Example Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/test/train-sets/ccb_losses.txt This line represents shared features that apply to all actions and slots in a CCB example. It starts with 'ccb shared' followed by feature namespaces and features. ```Vowpal Wabbit Input ccb shared |Shared f:1.0 ``` -------------------------------- ### Training VW Model with Simple Examples (Python) Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/python/docs/source/tutorials/python_simplified_dftovw_tuto.ipynb Initializes a Vowpal Wabbit `Workspace` and iterates through the generated examples to train the model using the `learn` method. Finally, it calls `finish` to finalize the training process and release resources. ```python model = Workspace(P=1, enable_logging=True) for ex in examples: model.learn(ex) model.finish() ``` -------------------------------- ### Basic Usage with VowpalWabbit Python Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/python/docs/source/reference/vowpalwabbit.rst This snippet demonstrates the fundamental steps to use the VowpalWabbit Python library: importing necessary classes, initializing a Workspace, creating an Example, and performing learn and predict operations on the example. ```python from vowpalwabbit import Workspace, Example workspace = Workspace(quiet=True) ex = Example('1 | a b c') workspace.learn(ex) workspace.predict(ex) ``` -------------------------------- ### Example Vowpal Wabbit Data Line Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/test/train-sets/x.txt This snippet shows a single data example in the Vowpal Wabbit format. It starts with a label (1695), followed by a space-separated list of feature identifiers and their corresponding weights, separated by a colon. ```Vowpal Wabbit Input Format 1695 74959:0.007232 74956:0.007232 74953:0.007232 74949:0.007232 74946:0.007232 74943:0.007232 74931:0.007232 74924:0.007232 74923:0.007232 74917:0.028926 74914:0.007232 74902:0.007232 74895:0.007232 74893:0.007232 74886:0.007232 74884:0.007232 74883:0.007232 74881:0.007232 74879:0.007232 74866:0.007232 74851:0.014463 74844:0.007232 74840:0.007232 74837:0.014463 74835:0.007232 74824:0.021695 74819:0.007232 74801:0.014463 74800:0.007232 74797:0.007232 74782:0.007232 74773:0.036158 74770:0.007232 74765:0.007232 74760:0.007232 74759:0.007232 74757:0.021695 74751:0.007232 74750:0.014463 74741:0.007232 74738:0.014463 74730:0.007232 74719:0.007232 74718:0.007232 74697:0.021695 74690:0.007232 74686:0.007232 74679:0.021695 74671:0.007232 74667:0.007232 74666:0.007232 74661:0.050621 74657:0.014463 74649:0.007232 74642:0.021695 74637:0.007232 74625:0.007232 74624:0.007232 74620:0.007232 74617:0.007232 74616:0.007232 74615:0.007232 74613:0.007232 74612:0.007232 74610:0.007232 74608:0.014463 74606:0.007232 74604:0.007232 74601:0.007232 74600:0.007232 74597:0.007232 74595:0.007232 74589:0.007232 74574:0.007232 74569:0.007232 74560:0.007232 74556:0.007232 74554:0.007232 74553:0.007232 74548:0.007232 74542:0.007232 74534:0.007232 74531:0.007232 74530:0.021695 74511:0.007232 74508:0.007232 74503:0.036158 74502:0.007232 74501:0.007232 74497:0.007232 74496:0.007232 74495:0.007232 74494:0.014463 74493:0.007232 74492:0.007232 74491:0.007232 74476:0.021695 74474:0.007232 74472:0.007232 74470:0.007232 74460:0.028926 74454:0.007232 74449:0.007232 74443:0.007232 74438:0.007232 74435:0.007232 74428:0.007232 74423:0.007232 74421:0.007232 74418:0.007232 74417:0.007232 74416:0.007232 74414:0.007232 74411:0.007232 74410:0.007232 74409:0.007232 74405:0.036158 74398:0.007232 74391:0.007232 74357:0.007232 74356:0.007232 74355:0.007232 74354:0.007232 74352:0.007232 74351:0.007232 74350:0.007232 74348:0.014463 74340:0.007232 74339:0.007232 74338:0.007232 74330:0.007232 74328:0.014463 74326:0.007232 74321:0.007232 74288:0.007232 74287:0.007232 74282:0.007232 74155:0.007232 74046:0.007232 73993:0.007232 73982:0.021695 73964:0.007232 73949:0.028926 73894:0.007232 73890:0.007232 73841:0.007232 73832:0.007232 73829:0.007232 73822:0.014463 73801:0.007232 73797:0.007232 73796:0.007232 73148:0.007232 72707:0.007232 72701:0.007232 72699:0.021695 72697:0.007232 72693:0.007232 72689:0.007232 72684:0.007232 72678:0.007232 72665:0.007232 72661:0.007232 72659:0.007232 72650:0.007232 72635:0.007232 72095:0.007232 72087:0.007232 72059:0.007232 72056:0.028926 72007:0.007232 71997:0.007232 71992:0.007232 71893:0.007232 71708:0.007232 71689:0.021695 71681:0.007232 71680:0.007232 71649:0.007232 71647:0.007232 71646:0.007232 71645:0.007232 71644:0.007232 71637:0.007232 71633:0.007232 71627:0.007232 71625:0.007232 71623:0.021695 71619:0.007232 71304:0.007232 71058:0.007232 71013:0.014463 70996:0.007232 70989:0.007232 70983:0.007232 70507:0.007232 70416:0.014463 70413:0.007232 70385:0.007232 70368:0.007232 70360:0.007232 70359:0.007232 70346:0.007232 70344:0.007232 70336:0.014463 70325:0.007232 70322:0.007232 70309:0.007232 70294:0.014463 69994:0.007232 69832:0.007232 69661:0.007232 69549:0.007232 69547:0.007232 69538:0.007232 69537:0.007232 69526:0.007232 69524:0.007232 69518:0.007232 69504:0.036158 69492:0.007232 69491:0.007232 69482:0.007232 69476:0.014463 69460:0.007232 69456:0.007232 69453:0.014463 69448:0.007232 69441:0.007232 69440:0.007232 69437:0.007232 69436:0.021695 69434:0.007232 69433:0.007232 69432:0.007232 69430:0.007232 69428:0.007232 69414:0.007232 69412:0.007232 69409:0.007232 69408:0.007232 69405:0.007232 69404:0.007232 69395:0.021695 69379:0.007232 69372:0.007232 69369:0.021695 69358:0.007232 69350:0.007232 69347:0.007232 69346:0.007232 69338:0.007232 69323:0.007232 69314:0.014463 69310:0.007232 69306:0.007232 69302:0.007232 69279:0.014463 69274:0.007232 69266:0.014463 69239:0.007232 69238:0.007232 69235:0.014463 69227:0.007232 69202:0.014463 69195:0.007232 68972:0.021695 68968:0.007232 68821:0.007232 68807:0.007232 68768:0.007232 68730:0.007232 68669:0.007232 68664:0.007232 68413:0.007232 68412:0.007232 68411:0.007232 68409:0.007232 68395:0.007232 68374:0.014463 68371:0.007232 68270:0.007232 68210:0.007232 68200:0.007232 68199:0.014463 68165:0.007232 68164:0.007232 68139:0.007232 68098:0.007232 68084:0.007232 68080:0.007232 68004:0.007232 67997:0.014463 67994:0.007232 67965:0.007232 67926:0.007232 67913:0.014463 67894:0.007232 67892:0.007232 67870:0.007232 67861:0.007232 67857:0.007232 67850:0.007232 67849:0.007232 67845:0.007232 67816:0.007232 67785:0.007232 67784:0.021695 67765:0.007232 67745:0.007232 67670:0.014463 67665:0.007232 67650:0.007232 67636:0.007232 67622:0.007232 67575:0.014463 67573:0.007232 67488:0.007232 67484:0.014463 67334:0.007232 67325:0.028926 67297:0.007232 67280:0.007232 67276:0.007232 67270:0.007232 67250:0.014463 67247:0.007232 67246:0.007232 67242:0.021695 67234:0.007232 67225:0.007232 67224:0.007232 67204:0.007232 ``` -------------------------------- ### Initializing Vowpal Wabbit Workspace for Slates - Python Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/python/docs/source/tutorials/python_slates.ipynb Creates an instance of the Vowpal Wabbit workspace using the Python binding. It enables the `--slates` algorithm and configures exploration (`--epsilon`), interactions (`--interactions`), learning rate (`-l`), and power_t (`--power_t`). ```python slates_vw = vowpalwabbit.Workspace( "--slates --epsilon 0.2 --interactions SA UAS US UA -l 0.05 --power_t 0", quiet=True ) ``` -------------------------------- ### Sparse Feature Vector Example Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/test/train-sets/automl_spin_off.txt This snippet shows a single example data point in Vowpal Wabbit's input format. It starts with '|E' (indicating an example without a label), followed by space-separated feature entries in the format 'index:value', and ends with 'const:value' which represents a constant feature. ```Vowpal Wabbit Input Format |E 24:1.6681092e-02 34:8.7006912e-02 36:3.9006412e-02 52:2.7113589e-02 57:3.3980906e-02 63:3.4217179e-02 89:3.3573695e-02 90:2.6088802e-02 98:3.1000959e-02 103:5.4646749e-02 110:4.2517200e-02 112:3.2853317e-02 121:3.1246958e-02 126:3.0707149e-02 128:6.3531041e-02 131:3.5151221e-02 161:4.1473381e-02 167:3.4431037e-02 179:2.1845059e-02 183:4.3929115e-02 188:3.7980244e-02 189:2.5516599e-02 196:4.1719068e-02 208:3.3796955e-02 236:3.6424126e-02 247:3.7867215e-02 252:2.4123959e-02 259:2.6362309e-02 260:4.5529597e-02 276:3.9958235e-02 282:4.4648245e-02 293:1.9950837e-02 297:4.5014553e-02 298:3.0321069e-02 307:1.1620269e-01 315:4.9880113e-02 326:2.4434734e-02 334:3.2472100e-02 342:3.2984704e-02 345:4.0612213e-02 354:3.0354893e-02 380:3.2550137e-02 422:4.9084399e-02 453:2.8375888e-02 454:2.7641883e-02 457:4.7994979e-02 492:6.3277572e-02 496:3.8358137e-02 497:2.9680919e-02 526:1.9478582e-02 533:1.9237831e-02 545:3.2141346e-02 571:5.8464967e-02 572:5.5901140e-02 580:4.1821182e-02 631:3.8628019e-02 638:3.4391385e-02 646:4.2061348e-02 655:2.2435315e-02 660:2.0476371e-02 670:4.3193322e-02 678:2.4655759e-02 689:5.1799946e-02 708:4.8981685e-02 723:4.1835558e-02 757:3.2595687e-02 758:8.1216425e-02 803:3.6054567e-02 833:5.6183152e-02 836:3.6621619e-02 871:3.9642647e-02 908:5.5703666e-02 932:3.2732666e-02 941:4.6777215e-02 968:4.7535121e-02 1011:3.3378333e-02 1025:3.9797876e-02 1056:3.5021726e-02 1059:2.0700853e-02 1071:7.3087670e-02 1077:4.4485878e-02 1105:7.1731344e-02 1125:4.6666380e-02 1169:5.0571408e-02 1170:6.8190120e-02 1196:1.0902449e-01 1213:4.3689135e-02 1218:5.9058551e-02 1231:5.9254725e-02 1235:9.0554573e-02 1238:1.1190374e-01 1246:7.1243942e-02 1266:6.8007238e-02 1279:5.6767773e-02 1292:5.2634060e-02 1321:3.8080353e-02 1350:4.4295829e-02 1389:4.2093731e-02 1410:1.2059744e-01 1421:4.5961052e-02 1426:2.9886989e-02 1443:3.9329596e-02 1454:4.8444130e-02 1455:5.2843451e-02 1459:1.0318444e-01 1461:5.4662514e-02 1498:5.6184784e-02 1511:5.7722006e-02 1563:8.7550074e-02 1599:6.6866830e-02 1615:5.8867633e-02 1666:2.3430904e-02 1685:5.0325189e-02 1855:7.8266673e-02 1889:3.3996686e-02 1966:6.8595454e-02 2010:4.3304298e-02 2074:4.1652452e-02 2087:4.8628904e-02 2097:9.3288384e-02 2098:4.2366885e-02 2099:4.2611409e-02 2115:6.1190169e-02 2122:4.2895064e-02 2231:5.6971446e-02 2259:7.2507828e-02 2264:1.0764164e-01 2339:9.3937062e-02 2409:4.9224563e-02 2431:9.2486531e-02 2564:7.3310763e-02 2582:5.0960474e-02 2586:6.0021155e-02 2589:5.8008734e-02 2757:5.4568022e-02 2759:6.1011195e-02 2762:4.8548143e-02 2846:5.2721836e-02 3009:6.0899768e-02 3021:5.1683761e-02 3066:5.6048576e-02 3117:5.2040361e-02 3130:6.8848491e-02 3132:5.5179354e-02 3195:5.3805474e-02 3247:5.7020281e-02 3271:3.9907690e-02 3291:4.5665115e-02 3325:4.2207263e-02 3338:5.2647430e-02 3386:5.6618098e-02 3443:5.9488375e-02 3721:6.6329211e-02 3881:6.2509604e-02 3966:1.0240217e-01 3980:8.2520232e-02 4029:5.8378585e-02 4660:6.3988276e-02 4986:6.9426216e-02 5051:9.4979614e-02 5080:8.0375440e-02 5283:1.0933269e-01 5531:7.6160625e-02 5542:9.2754453e-02 5592:7.0058763e-02 5660:7.7603064e-02 5999:9.0772331e-02 6051:5.6518771e-02 6643:7.1306653e-02 7089:8.8140242e-02 7165:6.6659003e-02 7330:6.0454782e-02 7707:1.3494925e-01 7956:6.4432487e-02 8385:7.5215399e-02 8521:1.5496588e-01 8528:9.4383650e-02 8798:6.9227338e-02 8900:7.5247057e-02 8934:6.2506847e-02 8973:1.6488221e-01 10158:7.3625341e-02 10902:8.9405313e-02 10934:1.0471538e-01 11548:8.6242296e-02 11725:1.2736413e-01 12182:1.0051626e-01 13963:6.9608547e-02 15331:7.0935160e-02 15580:8.3579771e-02 16008:8.9534260e-02 17373:8.7866232e-02 22240:1.0007322e-01 22699:9.5521070e-02 23664:9.5268145e-02 23701:8.1229754e-02 26162:1.0724679e-01 29015:2.3341818e-01 29578:1.0680433e-01 31005:8.8303000e-02 32061:1.2430258e-01 34350:2.6703054e-01 34720:1.2873581e-01 36036:1.0770612e-01 40571:9.7864822e-02 41683:9.4229579e-02 const:.01 ``` -------------------------------- ### Get Help for Testing Framework (Shell) Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/big_tests/HOWTO.use_it.txt Displays the help message for the Vowpal Wabbit testing framework, showing available commands and options. This is useful when you forget how to use the framework. ```Shell make help ``` -------------------------------- ### Logging CB Examples to File Stream with VWExampleLogger Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/wasm/README.md Illustrates how to use the VWExampleLogger in a Node.js environment to log contextual bandit examples directly to a file stream. It shows initializing the logger, starting a stream to a specified file, logging an example object, and closing the stream. ```JavaScript const vwPromise = require('@vowpalwabbit/vowpalwabbit'); vwPromise.then((vw) => { let example = { text_context: `shared | s_1 s_2 | a_1 b_1 c_1 | a_2 b_2 c_2 | a_3 b_3 c_3`, labels = [{ action: 0, cost: 1.0, probability: 1}] }; let model = new vw.CbWorkspace({ args_str: "--cb_explore_adf" }); let vwLogger = new vw.VWExampleLogger(); vwLogger.startLogStream("mylogfile.txt"); vwLogger.logCBExampleToStream(example); vwLogger.endLogStream(); model.delete(); }); ``` -------------------------------- ### Learn and Predict with CbWorkspace Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/wasm/README.md Illustrates how to use `predictAndSample` on a Contextual Bandit ADF model with a text-based example. It shows how to define an example with context, get a prediction (including action and score), calculate a cost based on the action, add labels to the example, and then call `learn`. ```Javascript const vwPromise = require('@vowpalwabbit/vowpalwabbit'); vwPromise.then((vw) => { let model = new vw.CbWorkspace({ args_str: "--cb_explore_adf" }); let example = { text_context: `shared | s_1 s_2 | a_1 b_1 c_1 | a_2 b_2 c_2 | a_3 b_3 c_3`, }; let pred = model.predictAndSample(example); # user defined cost function let action_cost = calculate_cost_from_action(pred["action"]) example.labels = [{ action: pred["action"], cost: action_cost, probability: pred["score"] }]; model.learn(example); model.delete() }); ``` -------------------------------- ### Simple Regression Example with Generic VW Workspace Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/wasm/README.md Shows a basic example of using the generic vw.Workspace for a simple regression task. It demonstrates initializing a workspace, parsing an example string, making a prediction, and properly cleaning up resources. ```JavaScript const vwPromise = require('@vowpalwabbit/vowpalwabbit'); vwPromise.then((vw) => { let model = new vw.Workspace({ args_str: "" }); let example = model.parse("|f 6:6.8953723e-02"); let prediction = model.predict(example); model.finishExample(example); example.delete(); model.delete(); }); ``` -------------------------------- ### Running Vowpal Wabbit Python Tests Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/python/README.rst Command line instruction to execute the test suite for the Vowpal Wabbit Python wrapper using the 'setup.py' script. Requires a local development setup of the repository. ```bash python setup.py test ``` -------------------------------- ### Vowpal Wabbit Input Format Examples Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/test/train-sets/cache_interaction_audit.txt These examples demonstrate the basic Vowpal Wabbit input format. Each line represents a data point starting with a label (and optionally importance weight), followed by namespaces ('s' and 't' in these examples) containing features. Features can have weights (e.g., 'w^the') or be simple presence indicators (e.g., 'p^the_man'). ```Vowpal Wabbit Format 1:1 |s p^the_man w^the w^man |t p^un_homme w^un w^homme ``` ```Vowpal Wabbit Format 2:0 |s p^the_man w^the w^man |t p^le_homme w^le w^homme ``` ```Vowpal Wabbit Format 1:0 |s p^a_man w^a w^man |t p^un_homme w^un w^homme ``` ```Vowpal Wabbit Format 2:1 |s p^a_man w^a w^man |t p^le_homme w^le w^homme ``` -------------------------------- ### Example Vowpal Wabbit Input Line Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/test/train-sets/las_100_actions.txt This snippet shows a single line of input data for Vowpal Wabbit. It starts with '|Action' followed by a space, and then a list of feature:value pairs separated by spaces. This format is commonly used to represent examples for training or prediction in Vowpal Wabbit. ```Text |Action politics:93 sports:120 music:147 food:48 math:144 science:0 computers:81 literature:54 social_media:54 dancing:51 news:129 celebrities:3 coffee:126 baking:132 ai:48 taxes:51 technology:147 pandemic:108 world_war_i:90 world_war_ii:9 religion:117 vaccination:126 the_queen:129 immigration:165 economics:75 fashion:36 NYC:135 LA:15 elections:114 brunch:78 space_exploration:153 climate_change:60 dogs:21 cats:48 inflation:99 sourdough:69 vegan:99 vacation:21 asteroid:60 eyewear:54 stationary:45 movies:24 oscars:15 acupuncture:111 hiking:138 swimming:102 barrys:15 ``` -------------------------------- ### Running VW with CB_Explore and First-N Exploration Source: https://github.com/vowpalwabbit/vowpal_wabbit/blob/master/python/docs/source/tutorials/python_Contextual_bandits_and_Vowpal_Wabbit.ipynb This command-line snippet demonstrates using the --cb_explore algorithm with the --first N exploration strategy, where the first N examples explore actions uniformly. ```text vw -d train.dat --cb_explore 4 --first 2 ```