wasm/documentation.md
<a name="CbWorkspace"></a>
ES6 wrapper around the Vowpal Wabbit C++ library.
Kind: global class
Extends: <code>vw.CbWorkspace</code>
<a name="new_CbWorkspace_new"></a>
Creates a new Vowpal Wabbit workspace for Contextual Bandit exploration algorithms. Can accept either or both string arguments and a model array.
Throws:
| Param | Type | Description |
|---|---|---|
| [args_str] | <code>string</code> | The arguments that are used to initialize Vowpal Wabbit (optional) |
| [model_array] | <code>tuple</code> | The pre-loaded model's array pointer and length (optional). The memory must be allocated via the WebAssembly module's _malloc function and should later be freed via the _free function. |
<a name="new_CbWorkspace_new"></a>
Creates a new Vowpal Wabbit workspace for Contextual Bandit exploration algorithms. Can accept either or both string arguments and a model file.
Throws:
| Param | Type | Description |
|---|---|---|
| [args_str] | <code>string</code> | The arguments that are used to initialize Vowpal Wabbit (optional) |
| [model_file] | <code>string</code> | The path to the file where the model will be loaded from (optional) |
| [model_array] | <code>tuple</code> | The pre-loaded model's array pointer and length (optional). The memory must be allocated via the WebAssembly module's _malloc function and should later be freed via the _free function. |
<a name="CbWorkspace+predict"></a>
Takes a CB example and returns an array of (action, score) pairs, representing the probability mass function over the available actions The returned pmf can be used with samplePmf to sample an action
Example must have the following properties:
Kind: instance method of <code>CbWorkspace</code>
Returns: <code>array</code> - probability mass function, an array of action,score pairs that was returned by predict
Throws:
| Param | Type | Description |
|---|---|---|
| example | <code>object</code> | the example object that will be used for prediction |
<a name="CbWorkspace+learn"></a>
Takes a CB example and uses it to update the model
Example must have the following properties:
A label object should have more than one labels only if a reduction that accepts multiple labels was used (e.g. graph_feedback)
Kind: instance method of <code>CbWorkspace</code>
Throws:
| Param | Type | Description |
|---|---|---|
| example | <code>object</code> | the example object that will be used for prediction |
<a name="CbWorkspace+addLine"></a>
Accepts a CB example (in text format) line by line. Once a full CB example is passed in it will call learnFromString. This is intended to be used with files that have CB examples, that were logged using logCBExampleToStream and are being read line by line.
Kind: instance method of <code>CbWorkspace</code>
| Param | Type | Description |
|---|---|---|
| line | <code>string</code> | a string representing a line from a CB example in text Vowpal Wabbit format |
<a name="CbWorkspace+learnFromString"></a>
Takes a full multiline CB example in text format and uses it to update the model. This is intended to be used with examples that are logged to a file using logCBExampleToStream.
Kind: instance method of <code>CbWorkspace</code>
Throws:
| Param | Type | Description |
|---|---|---|
| example | <code>string</code> | a string representing the CB example in text Vowpal Wabbit format |
<a name="CbWorkspace+samplePmf"></a>
Takes an exploration prediction (array of action, score pairs) and returns a single action and score, along with a unique id that was used to seed the sampling and that can be used to track and reproduce the sampling.
Kind: instance method of <code>CbWorkspace</code>
Returns: <code>object</code> - an object with the following properties:
action: the action index that was sampled
score: the score of the action that was sampled
uuid: the uuid that was passed to the predict function
Throws:
<code>VWError</code> Throws an error if the input is not an array of action,score pairs
| Param | Type | Description |
|---|---|---|
| pmf | <code>array</code> | probability mass function, an array of action,score pairs that was returned by predict |
<a name="CbWorkspace+samplePmfWithUUID"></a>
Takes an exploration prediction (array of action, score pairs) and a unique id that is used to seed the sampling, and returns a single action index and the corresponding score.
Kind: instance method of <code>CbWorkspace</code>
Returns: <code>object</code> - an object with the following properties:
action: the action index that was sampled
score: the score of the action that was sampled
uuid: the uuid that was passed to the predict function
Throws:
<code>VWError</code> Throws an error if the input is not an array of action,score pairs
| Param | Type | Description |
|---|---|---|
| pmf | <code>array</code> | probability mass function, an array of action,score pairs that was returned by predict |
| uuid | <code>string</code> | a unique id that can be used to seed the prediction |
<a name="CbWorkspace+predictAndSample"></a>
Takes an example with a text_context field and calls predict. The prediction (a probability mass function over the available actions) will then be sampled from, and only the chosen action index and the corresponding score will be returned, along with a unique id that was used to seed the sampling and that can be used to track and reproduce the sampling.
Kind: instance method of <code>CbWorkspace</code>
Returns: <code>object</code> - an object with the following properties:
action: the action index that was sampled
score: the score of the action that was sampled
uuid: the uuid that was passed to the predict function
Throws:
<code>VWError</code> if there is no text_context field in the example
| Param | Type | Description |
|---|---|---|
| example | <code>object</code> | an example object containing the context to be used during prediction |
<a name="CbWorkspace+predictAndSampleWithUUID"></a>
Takes an example with a text_context field and calls predict, and a unique id that is used to seed the sampling. The prediction (a probability mass function over the available actions) will then be sampled from, and only the chosen action index and the corresponding score will be returned, along with a unique id that was used to seed the sampling and that can be used to track and reproduce the sampling.
Kind: instance method of <code>CbWorkspace</code>
Returns: <code>object</code> - an object with the following properties:
action: the action index that was sampled
score: the score of the action that was sampled
uuid: the uuid that was passed to the predict function
Throws:
<code>VWError</code> if there is no text_context field in the example
| Param | Type | Description |
|---|---|---|
| example | <code>object</code> | an example object containing the context to be used during prediction |
<a name="WorkspaceBase+predictionType"></a>
Returns the enum value of the prediction type corresponding to the problem type of the model
Kind: instance method of <code>CbWorkspace</code>
Overrides: <code>predictionType</code>
Returns: enum value of prediction type
<a name="WorkspaceBase+sumLoss"></a>
The current total sum of the progressive validation loss
Kind: instance method of <code>CbWorkspace</code>
Overrides: <code>sumLoss</code>
Returns: <code>number</code> - the sum of all losses accumulated by the model
<a name="WorkspaceBase+saveModelToFile"></a>
Takes a file location and stores the VW model in binary format in the file.
Kind: instance method of <code>CbWorkspace</code>
Overrides: <code>saveModelToFile</code>
| Param | Type | Description |
|---|---|---|
| model_file | <code>string</code> | the path to the file where the model will be saved |
<a name="WorkspaceBase+getModelAsArray"></a>
Gets the VW model in binary format as a Uint8Array that can be saved to a file. There is no need to delete or free the array returned by this function. If the same array is however used to re-load the model into VW, then the array needs to be stored in wasm memory (see loadModelFromArray)
Kind: instance method of <code>CbWorkspace</code>
Overrides: <code>getModelAsArray</code>
Returns: <code>Uint8Array</code> - the VW model in binary format
<a name="WorkspaceBase+loadModelFromFile"></a>
Takes a file location and loads the VW model from the file.
Kind: instance method of <code>CbWorkspace</code>
Overrides: <code>loadModelFromFile</code>
| Param | Type | Description |
|---|---|---|
| model_file | <code>string</code> | the path to the file where the model will be loaded from |
<a name="WorkspaceBase+loadModelFromArray"></a>
Takes a model in an array binary format and loads it into the VW instance. The memory must be allocated via the WebAssembly module's _malloc function and should later be freed via the _free function.
Kind: instance method of <code>CbWorkspace</code>
Overrides: <code>loadModelFromArray</code>
| Param | Type | Description |
|---|---|---|
| model_array_ptr | <code>number</code> | the pre-loaded model's array pointer The memory must be allocated via the WebAssembly module's _malloc function and should later be freed via the _free function. |
| model_array_len | <code>number</code> | the pre-loaded model's array length |
<a name="WorkspaceBase+delete"></a>
Deletes the underlying VW instance. This function should be called when the instance is no longer needed.
Kind: instance method of <code>CbWorkspace</code>
Overrides: <code>delete</code>
<a name="Workspace"></a>
ES6 wrapper around the Vowpal Wabbit C++ library.
Kind: global class
Extends: <code>vw.Workspace</code>
<a name="new_Workspace_new"></a>
Creates a new Vowpal Wabbit workspace. Can accept either or both string arguments and a model file.
Throws:
| Param | Type | Description |
|---|---|---|
| readSync | <code>function</code> | A function that reads a file synchronously and returns a buffer |
| writeSync | <code>function</code> | A function that writes a buffer to a file synchronously |
| [args_str] | <code>string</code> | The arguments that are used to initialize Vowpal Wabbit (optional) |
| [model_file] | <code>string</code> | The path to the file where the model will be loaded from (optional) |
| [model_array] | <code>tuple</code> | The pre-loaded model's array pointer and length (optional). The memory must be allocated via the WebAssembly module's _malloc function and should later be freed via the _free function. |
<a name="new_Workspace_new"></a>
Creates a new Vowpal Wabbit workspace. Can accept either or both string arguments and a model array.
Throws:
| Param | Type | Description |
|---|---|---|
| [args_str] | <code>string</code> | The arguments that are used to initialize Vowpal Wabbit (optional) |
| [model_array] | <code>tuple</code> | The pre-loaded model's array pointer and length (optional). The memory must be allocated via the WebAssembly module's _malloc function and should later be freed via the _free function. |
<a name="new_Workspace_new"></a>
Creates a new Vowpal Wabbit workspace. Can accept either or both string arguments and a model file.
Throws:
| Param | Type | Description |
|---|---|---|
| [args_str] | <code>string</code> | The arguments that are used to initialize Vowpal Wabbit (optional) |
| [model_file] | <code>string</code> | The path to the file where the model will be loaded from (optional) |
| [model_array] | <code>tuple</code> | The pre-loaded model's array pointer and length (optional). The memory must be allocated via the WebAssembly module's _malloc function and should later be freed via the _free function. |
<a name="Workspace+parse"></a>
Parse a line of text into a VW example. The example can then be used for prediction or learning. finishExample() must be called and then delete() on the example, when it is no longer needed.
Kind: instance method of <code>Workspace</code>
Returns: a parsed vw example that can be used for prediction or learning
| Param | Type |
|---|---|
| line | <code>string</code> |
<a name="Workspace+createExampleFromDense"></a>
Creates a new example from a dense array of features, where the key of the map is the namespace.
Kind: instance method of <code>Workspace</code>
Returns: a parsed vw example that can be used for prediction or learning
| Param | Type | Description |
|---|---|---|
| features | <code>Map.<string, Array.<number>></code> | |
| label | <code>string</code> | Empty label by default |
Example
let example = model.create_example_from_dense({
my_namespace: [0.3, 0.2, 0.1, 0.3, 0.5, 0.9]
});
<a name="Workspace+predict"></a>
Calls vw predict on the example and returns the prediction.
Kind: instance method of <code>Workspace</code>
Returns: the prediction with a type corresponding to the reduction that was used
Throws:
| Param | Type | Description |
|---|---|---|
| example | <code>object</code> | returned from parse() |
<a name="Workspace+learn"></a>
Calls vw learn on the example and updates the model
Kind: instance method of <code>Workspace</code>
Throws:
| Param | Type | Description |
|---|---|---|
| example | <code>object</code> | returned from parse() |
<a name="Workspace+finishExample"></a>
Cleans the example and returns it to the pool of available examples. delete() must also be called on the example object
Kind: instance method of <code>Workspace</code>
| Param | Type | Description |
|---|---|---|
| example | <code>object</code> | returned from parse() |
<a name="WorkspaceBase+predictionType"></a>
Returns the enum value of the prediction type corresponding to the problem type of the model
Kind: instance method of <code>Workspace</code>
Overrides: <code>predictionType</code>
Returns: enum value of prediction type
<a name="WorkspaceBase+sumLoss"></a>
The current total sum of the progressive validation loss
Kind: instance method of <code>Workspace</code>
Overrides: <code>sumLoss</code>
Returns: <code>number</code> - the sum of all losses accumulated by the model
<a name="WorkspaceBase+saveModelToFile"></a>
Takes a file location and stores the VW model in binary format in the file.
Kind: instance method of <code>Workspace</code>
Overrides: <code>saveModelToFile</code>
| Param | Type | Description |
|---|---|---|
| model_file | <code>string</code> | the path to the file where the model will be saved |
<a name="WorkspaceBase+getModelAsArray"></a>
Gets the VW model in binary format as a Uint8Array that can be saved to a file. There is no need to delete or free the array returned by this function. If the same array is however used to re-load the model into VW, then the array needs to be stored in wasm memory (see loadModelFromArray)
Kind: instance method of <code>Workspace</code>
Overrides: <code>getModelAsArray</code>
Returns: <code>Uint8Array</code> - the VW model in binary format
<a name="WorkspaceBase+loadModelFromFile"></a>
Takes a file location and loads the VW model from the file.
Kind: instance method of <code>Workspace</code>
Overrides: <code>loadModelFromFile</code>
| Param | Type | Description |
|---|---|---|
| model_file | <code>string</code> | the path to the file where the model will be loaded from |
<a name="WorkspaceBase+loadModelFromArray"></a>
Takes a model in an array binary format and loads it into the VW instance. The memory must be allocated via the WebAssembly module's _malloc function and should later be freed via the _free function.
Kind: instance method of <code>Workspace</code>
Overrides: <code>loadModelFromArray</code>
| Param | Type | Description |
|---|---|---|
| model_array_ptr | <code>number</code> | the pre-loaded model's array pointer The memory must be allocated via the WebAssembly module's _malloc function and should later be freed via the _free function. |
| model_array_len | <code>number</code> | the pre-loaded model's array length |
<a name="WorkspaceBase+delete"></a>
Deletes the underlying VW instance. This function should be called when the instance is no longer needed.
Kind: instance method of <code>Workspace</code>
Overrides: <code>delete</code>
<a name="VWExampleLogger"></a>
A class that helps facilitate the stringification of Vowpal Wabbit examples, and the logging of Vowpal Wabbit examples to a file. Currently available for use in nodejs environments only.
Kind: global class
<a name="VWExampleLogger+startLogStream"></a>
Starts a log stream to the specified file. Any new logs will be appended to the file.
Kind: instance method of <code>VWExampleLogger</code>
Throws:
| Param | Type | Description |
|---|---|---|
| log_file | <code>string</code> | the path to the file where the log will be appended to |
<a name="VWExampleLogger+logLineToStream"></a>
Takes a string and appends it to the log file. Line is logged in an asynchronous manner.
Kind: instance method of <code>VWExampleLogger</code>
Throws:
| Param | Type | Description |
|---|---|---|
| line | <code>string</code> | the line to be appended to the log file |
<a name="VWExampleLogger+endLogStream"></a>
Closes the logging stream. Logs a warning to the console if there is no logging stream active, but does not throw
Kind: instance method of <code>VWExampleLogger</code>
<a name="VWExampleLogger+logLineSync"></a>
Takes a string and appends it to the log file. Line is logged in a synchronous manner. Every call to this function will open a new file handle, append the line and close the file handle.
Kind: instance method of <code>VWExampleLogger</code>
Throws:
| Param | Type | Description |
|---|---|---|
| log_file | <code>string</code> | the path to the file where the log will be appended to |
| line | <code>string</code> | the line to be appended to the log file |
<a name="VWExampleLogger+CBExampleToString"></a>
Takes a CB example and returns the string representation of it
Kind: instance method of <code>VWExampleLogger</code>
Returns: <code>string</code> - the string representation of the CB example
Throws:
| Param | Type | Description |
|---|---|---|
| example | <code>object</code> | a CB example that will be stringified |
<a name="VWExampleLogger+logCBExampleToStream"></a>
Takes a CB example, stringifies it by calling CBExampleToString, and appends it to the log file. Line is logged in an asynchronous manner.
Kind: instance method of <code>VWExampleLogger</code>
Throws:
| Param | Type | Description |
|---|---|---|
| example | <code>object</code> | a CB example that will be stringified and appended to the log file |
<a name="VWExampleLogger+logCBExampleSync"></a>
Takes a CB example, stringifies it by calling CBExampleToString, and appends it to the log file. Example is logged in a synchronous manner. Every call to this function will open a new file handle, append the line and close the file handle.
Kind: instance method of <code>VWExampleLogger</code>
Throws:
| Param | Type | Description |
|---|---|---|
| log_file | <code>string</code> | the path to the file where the log will be appended to |
| example | <code>object</code> | a CB example that will be stringified and appended to the log file |
<a name="CbWorkspace"></a>
Nodejs wrapper around the Vowpal Wabbit C++ library.
Kind: global class
Extends: <code>vw.CbWorkspace</code>
<a name="new_CbWorkspace_new"></a>
Creates a new Vowpal Wabbit workspace for Contextual Bandit exploration algorithms. Can accept either or both string arguments and a model array.
Throws:
| Param | Type | Description |
|---|---|---|
| [args_str] | <code>string</code> | The arguments that are used to initialize Vowpal Wabbit (optional) |
| [model_array] | <code>tuple</code> | The pre-loaded model's array pointer and length (optional). The memory must be allocated via the WebAssembly module's _malloc function and should later be freed via the _free function. |
<a name="new_CbWorkspace_new"></a>
Creates a new Vowpal Wabbit workspace for Contextual Bandit exploration algorithms. Can accept either or both string arguments and a model file.
Throws:
| Param | Type | Description |
|---|---|---|
| [args_str] | <code>string</code> | The arguments that are used to initialize Vowpal Wabbit (optional) |
| [model_file] | <code>string</code> | The path to the file where the model will be loaded from (optional) |
| [model_array] | <code>tuple</code> | The pre-loaded model's array pointer and length (optional). The memory must be allocated via the WebAssembly module's _malloc function and should later be freed via the _free function. |
<a name="CbWorkspace+predict"></a>
Takes a CB example and returns an array of (action, score) pairs, representing the probability mass function over the available actions The returned pmf can be used with samplePmf to sample an action
Example must have the following properties:
Kind: instance method of <code>CbWorkspace</code>
Returns: <code>array</code> - probability mass function, an array of action,score pairs that was returned by predict
Throws:
| Param | Type | Description |
|---|---|---|
| example | <code>object</code> | the example object that will be used for prediction |
<a name="CbWorkspace+learn"></a>
Takes a CB example and uses it to update the model
Example must have the following properties:
A label object should have more than one labels only if a reduction that accepts multiple labels was used (e.g. graph_feedback)
Kind: instance method of <code>CbWorkspace</code>
Throws:
| Param | Type | Description |
|---|---|---|
| example | <code>object</code> | the example object that will be used for prediction |
<a name="CbWorkspace+addLine"></a>
Accepts a CB example (in text format) line by line. Once a full CB example is passed in it will call learnFromString. This is intended to be used with files that have CB examples, that were logged using logCBExampleToStream and are being read line by line.
Kind: instance method of <code>CbWorkspace</code>
| Param | Type | Description |
|---|---|---|
| line | <code>string</code> | a string representing a line from a CB example in text Vowpal Wabbit format |
<a name="CbWorkspace+learnFromString"></a>
Takes a full multiline CB example in text format and uses it to update the model. This is intended to be used with examples that are logged to a file using logCBExampleToStream.
Kind: instance method of <code>CbWorkspace</code>
Throws:
| Param | Type | Description |
|---|---|---|
| example | <code>string</code> | a string representing the CB example in text Vowpal Wabbit format |
<a name="CbWorkspace+samplePmf"></a>
Takes an exploration prediction (array of action, score pairs) and returns a single action and score, along with a unique id that was used to seed the sampling and that can be used to track and reproduce the sampling.
Kind: instance method of <code>CbWorkspace</code>
Returns: <code>object</code> - an object with the following properties:
action: the action index that was sampled
score: the score of the action that was sampled
uuid: the uuid that was passed to the predict function
Throws:
<code>VWError</code> Throws an error if the input is not an array of action,score pairs
| Param | Type | Description |
|---|---|---|
| pmf | <code>array</code> | probability mass function, an array of action,score pairs that was returned by predict |
<a name="CbWorkspace+samplePmfWithUUID"></a>
Takes an exploration prediction (array of action, score pairs) and a unique id that is used to seed the sampling, and returns a single action index and the corresponding score.
Kind: instance method of <code>CbWorkspace</code>
Returns: <code>object</code> - an object with the following properties:
action: the action index that was sampled
score: the score of the action that was sampled
uuid: the uuid that was passed to the predict function
Throws:
<code>VWError</code> Throws an error if the input is not an array of action,score pairs
| Param | Type | Description |
|---|---|---|
| pmf | <code>array</code> | probability mass function, an array of action,score pairs that was returned by predict |
| uuid | <code>string</code> | a unique id that can be used to seed the prediction |
<a name="CbWorkspace+predictAndSample"></a>
Takes an example with a text_context field and calls predict. The prediction (a probability mass function over the available actions) will then be sampled from, and only the chosen action index and the corresponding score will be returned, along with a unique id that was used to seed the sampling and that can be used to track and reproduce the sampling.
Kind: instance method of <code>CbWorkspace</code>
Returns: <code>object</code> - an object with the following properties:
action: the action index that was sampled
score: the score of the action that was sampled
uuid: the uuid that was passed to the predict function
Throws:
<code>VWError</code> if there is no text_context field in the example
| Param | Type | Description |
|---|---|---|
| example | <code>object</code> | an example object containing the context to be used during prediction |
<a name="CbWorkspace+predictAndSampleWithUUID"></a>
Takes an example with a text_context field and calls predict, and a unique id that is used to seed the sampling. The prediction (a probability mass function over the available actions) will then be sampled from, and only the chosen action index and the corresponding score will be returned, along with a unique id that was used to seed the sampling and that can be used to track and reproduce the sampling.
Kind: instance method of <code>CbWorkspace</code>
Returns: <code>object</code> - an object with the following properties:
action: the action index that was sampled
score: the score of the action that was sampled
uuid: the uuid that was passed to the predict function
Throws:
<code>VWError</code> if there is no text_context field in the example
| Param | Type | Description |
|---|---|---|
| example | <code>object</code> | an example object containing the context to be used during prediction |
<a name="WorkspaceBase+predictionType"></a>
Returns the enum value of the prediction type corresponding to the problem type of the model
Kind: instance method of <code>CbWorkspace</code>
Overrides: <code>predictionType</code>
Returns: enum value of prediction type
<a name="WorkspaceBase+sumLoss"></a>
The current total sum of the progressive validation loss
Kind: instance method of <code>CbWorkspace</code>
Overrides: <code>sumLoss</code>
Returns: <code>number</code> - the sum of all losses accumulated by the model
<a name="WorkspaceBase+saveModelToFile"></a>
Takes a file location and stores the VW model in binary format in the file.
Kind: instance method of <code>CbWorkspace</code>
Overrides: <code>saveModelToFile</code>
| Param | Type | Description |
|---|---|---|
| model_file | <code>string</code> | the path to the file where the model will be saved |
<a name="WorkspaceBase+getModelAsArray"></a>
Gets the VW model in binary format as a Uint8Array that can be saved to a file. There is no need to delete or free the array returned by this function. If the same array is however used to re-load the model into VW, then the array needs to be stored in wasm memory (see loadModelFromArray)
Kind: instance method of <code>CbWorkspace</code>
Overrides: <code>getModelAsArray</code>
Returns: <code>Uint8Array</code> - the VW model in binary format
<a name="WorkspaceBase+loadModelFromFile"></a>
Takes a file location and loads the VW model from the file.
Kind: instance method of <code>CbWorkspace</code>
Overrides: <code>loadModelFromFile</code>
| Param | Type | Description |
|---|---|---|
| model_file | <code>string</code> | the path to the file where the model will be loaded from |
<a name="WorkspaceBase+loadModelFromArray"></a>
Takes a model in an array binary format and loads it into the VW instance. The memory must be allocated via the WebAssembly module's _malloc function and should later be freed via the _free function.
Kind: instance method of <code>CbWorkspace</code>
Overrides: <code>loadModelFromArray</code>
| Param | Type | Description |
|---|---|---|
| model_array_ptr | <code>number</code> | the pre-loaded model's array pointer The memory must be allocated via the WebAssembly module's _malloc function and should later be freed via the _free function. |
| model_array_len | <code>number</code> | the pre-loaded model's array length |
<a name="WorkspaceBase+delete"></a>
Deletes the underlying VW instance. This function should be called when the instance is no longer needed.
Kind: instance method of <code>CbWorkspace</code>
Overrides: <code>delete</code>
<a name="Workspace"></a>
Nodejs wrapper around the Vowpal Wabbit C++ library.
Kind: global class
Extends: <code>vw.Workspace</code>
<a name="new_Workspace_new"></a>
Creates a new Vowpal Wabbit workspace. Can accept either or both string arguments and a model file.
Throws:
| Param | Type | Description |
|---|---|---|
| readSync | <code>function</code> | A function that reads a file synchronously and returns a buffer |
| writeSync | <code>function</code> | A function that writes a buffer to a file synchronously |
| [args_str] | <code>string</code> | The arguments that are used to initialize Vowpal Wabbit (optional) |
| [model_file] | <code>string</code> | The path to the file where the model will be loaded from (optional) |
| [model_array] | <code>tuple</code> | The pre-loaded model's array pointer and length (optional). The memory must be allocated via the WebAssembly module's _malloc function and should later be freed via the _free function. |
<a name="new_Workspace_new"></a>
Creates a new Vowpal Wabbit workspace. Can accept either or both string arguments and a model array.
Throws:
| Param | Type | Description |
|---|---|---|
| [args_str] | <code>string</code> | The arguments that are used to initialize Vowpal Wabbit (optional) |
| [model_array] | <code>tuple</code> | The pre-loaded model's array pointer and length (optional). The memory must be allocated via the WebAssembly module's _malloc function and should later be freed via the _free function. |
<a name="new_Workspace_new"></a>
Creates a new Vowpal Wabbit workspace. Can accept either or both string arguments and a model file.
Throws:
| Param | Type | Description |
|---|---|---|
| [args_str] | <code>string</code> | The arguments that are used to initialize Vowpal Wabbit (optional) |
| [model_file] | <code>string</code> | The path to the file where the model will be loaded from (optional) |
| [model_array] | <code>tuple</code> | The pre-loaded model's array pointer and length (optional). The memory must be allocated via the WebAssembly module's _malloc function and should later be freed via the _free function. |
<a name="Workspace+parse"></a>
Parse a line of text into a VW example. The example can then be used for prediction or learning. finishExample() must be called and then delete() on the example, when it is no longer needed.
Kind: instance method of <code>Workspace</code>
Returns: a parsed vw example that can be used for prediction or learning
| Param | Type |
|---|---|
| line | <code>string</code> |
<a name="Workspace+createExampleFromDense"></a>
Creates a new example from a dense array of features, where the key of the map is the namespace.
Kind: instance method of <code>Workspace</code>
Returns: a parsed vw example that can be used for prediction or learning
| Param | Type | Description |
|---|---|---|
| features | <code>Map.<string, Array.<number>></code> | |
| label | <code>string</code> | Empty label by default |
Example
let example = model.create_example_from_dense({
my_namespace: [0.3, 0.2, 0.1, 0.3, 0.5, 0.9]
});
<a name="Workspace+predict"></a>
Calls vw predict on the example and returns the prediction.
Kind: instance method of <code>Workspace</code>
Returns: the prediction with a type corresponding to the reduction that was used
Throws:
| Param | Type | Description |
|---|---|---|
| example | <code>object</code> | returned from parse() |
<a name="Workspace+learn"></a>
Calls vw learn on the example and updates the model
Kind: instance method of <code>Workspace</code>
Throws:
| Param | Type | Description |
|---|---|---|
| example | <code>object</code> | returned from parse() |
<a name="Workspace+finishExample"></a>
Cleans the example and returns it to the pool of available examples. delete() must also be called on the example object
Kind: instance method of <code>Workspace</code>
| Param | Type | Description |
|---|---|---|
| example | <code>object</code> | returned from parse() |
<a name="WorkspaceBase+predictionType"></a>
Returns the enum value of the prediction type corresponding to the problem type of the model
Kind: instance method of <code>Workspace</code>
Overrides: <code>predictionType</code>
Returns: enum value of prediction type
<a name="WorkspaceBase+sumLoss"></a>
The current total sum of the progressive validation loss
Kind: instance method of <code>Workspace</code>
Overrides: <code>sumLoss</code>
Returns: <code>number</code> - the sum of all losses accumulated by the model
<a name="WorkspaceBase+saveModelToFile"></a>
Takes a file location and stores the VW model in binary format in the file.
Kind: instance method of <code>Workspace</code>
Overrides: <code>saveModelToFile</code>
| Param | Type | Description |
|---|---|---|
| model_file | <code>string</code> | the path to the file where the model will be saved |
<a name="WorkspaceBase+getModelAsArray"></a>
Gets the VW model in binary format as a Uint8Array that can be saved to a file. There is no need to delete or free the array returned by this function. If the same array is however used to re-load the model into VW, then the array needs to be stored in wasm memory (see loadModelFromArray)
Kind: instance method of <code>Workspace</code>
Overrides: <code>getModelAsArray</code>
Returns: <code>Uint8Array</code> - the VW model in binary format
<a name="WorkspaceBase+loadModelFromFile"></a>
Takes a file location and loads the VW model from the file.
Kind: instance method of <code>Workspace</code>
Overrides: <code>loadModelFromFile</code>
| Param | Type | Description |
|---|---|---|
| model_file | <code>string</code> | the path to the file where the model will be loaded from |
<a name="WorkspaceBase+loadModelFromArray"></a>
Takes a model in an array binary format and loads it into the VW instance. The memory must be allocated via the WebAssembly module's _malloc function and should later be freed via the _free function.
Kind: instance method of <code>Workspace</code>
Overrides: <code>loadModelFromArray</code>
| Param | Type | Description |
|---|---|---|
| model_array_ptr | <code>number</code> | the pre-loaded model's array pointer The memory must be allocated via the WebAssembly module's _malloc function and should later be freed via the _free function. |
| model_array_len | <code>number</code> | the pre-loaded model's array length |
<a name="WorkspaceBase+delete"></a>
Deletes the underlying VW instance. This function should be called when the instance is no longer needed.
Kind: instance method of <code>Workspace</code>
Overrides: <code>delete</code>