The EncoderVersion API provides a scriptable object used in Predictive Intelligence stores.
This API requires the Predictive Intelligence plugin (com.glide.platform_ml) and is provided within the sn_ml namespace.
This API is used for working with encoder versions based on Encoder API objects in the Encoder store.
The system activates the most recent version of the encoder when it completes training, and only allows one version to be active at a time. However, you can activate any previously trained version you want to use to make predictions.
Methods in this API are accessible using the following Encoder methods:
Name of the algorithm for training this encoder. Possible values:
paravec: Paragraph vector word embedding.
tf-idf: Term Frequency–Inverse Document Frequency (TF-IDF)-based text.
Data type: String.
<Object>.datasetsProperties
List of DatasetDefinition() properties associated with the encoder. ``` { "encodedQuery": "String", "fieldDetails": [Array], "fieldNames": [Array], "tableName": "String" }
Data type: Array.
</td></tr><tr><td>
<Object>.datasetsProperties.tableName
</td><td>
Name of the table for the dataset. For example, `"tableName" : "Incident"`. Data type: String.
</td></tr><tr><td>
<Object>.datasetsProperties.fieldNames
</td><td>
List of field names from the specified table as strings. For example, `"fieldNames" : ["short_description", "priority"]`. Data type: Array.
</td></tr><tr><td>
<Object>.datasetsProperties.fieldNames.fieldDetails
</td><td>
List of JavaScript objects that specify field properties.
[ { "name": "String", "type": "String" } ]
Data type: Array.
</td></tr><tr><td>
<Object>.datasetsProperties.fieldNames.fieldDetails.<object>.name
</td><td>
Name of the field defining the type of information to restrict this dataset to. Data type: String.
</td></tr><tr><td>
<Object>.datasetsProperties.fieldDetails.<object>.type
</td><td>
Machine-learning field type. Data type: String.
</td></tr><tr><td>
<Object>.datasetsProperties.fieldDetails.encodedQuery
</td><td>
Encoded query string in the standard platform format. See <a href="../../../platform-user-interface/c_EncodedQueryStrings/">Encoded query strings</a>.Data type: String.
</td></tr><tr><td>
<Object>.domainName
</td><td>
Domain name associated with this dataset. See <a href="../../../intelligent-experiences/predictive-intelligence/domain-separation-predictive-intelligence/">Domain separation and Predictive Intelligence</a>.Type: String
</td></tr><tr><td>
<Object>.isActive
</td><td>
Flag that indicates whether this version is active.Valid values:
- true: Version is active.
- false: Version is not active.
Data type: String
</td></tr><tr><td>
<Object>.label
</td><td>
Identifies the prediction task.
{ "label": "my first prediction" }
Data type: String.
</td></tr><tr><td>
<Object>.name
</td><td>
System-assigned name. Data type: String.
</td></tr><tr><td>
<Object>.predictedFieldName
</td><td>
Identifies a field to be trained for predictability. Data type: String.
</td></tr><tr><td>
<Object>.processingLanguage
</td><td>
Processing language in two-letter ISO 639-1 language code format. Data type: String.
</td></tr><tr><td>
<Object>.scope
</td><td>
Object scope. Currently the only valid value is `global`.Data type: String
</td></tr><tr><td>
<Object>.stopwords
</td><td>Optional. Preset list of strings that the system automatically generates based on the <strong>language</strong> property setting. For details, see <a href="../../../intelligent-experiences/predictive-intelligence/create-custom-stopwords-list/">Create a custom stopwords list</a>. Data type: Array.</td></tr><tr><td>
<Object>.trainingFrequency
</td><td>
The frequency to retrain the model. Possible values:
- every\_30\_days
- every\_60\_days
- every\_90\_days
- every\_120\_days
- every\_180\_days
- run\_once
Default: run\_once
Data type: String.
</td></tr><tr><td>
<Object>.versionNumber
</td><td>
Version number of the Encoder object.Data type: String.
</td></tr></tbody>
</table>
The following example gets properties of the active object version in the store.
// Get properties var mlEncoder = sn_ml.EncoderStore.get('ml_incident_categorization'); gs.print(JSON.stringify(JSON.parse(mlEncoder.getActiveVersion().getProperties()), null, 2));
## EncoderVersion - getSentenceVectors\(Array input\)
Returns vectors for each input sentence.
|Name|Type|Description|
|----|----|-----------|
|input|Array|Array of strings as sentences from which to receive vectors.|
|Type|Description|
|----|-----------|
|String|Array of sentence vectors.|
The following example shows how to return a vector for a single sentence.
var myEncoderName = 'GloVe'; var myEncoder = sn_ml.EncoderStore.get(myEncoderName); var input = ["I like to code."]; var vectors = myEncoder.getActiveVersion().getSentenceVectors(input); gs.print(vectors);
## EncoderVersion - getSimilarWords\(Array input, Object options\)
Returns words similar to each input word in the descending rank order of similarity.
<table id="table_mxj_kdb_rlb" class="parameters"><thead><tr><th>
Name
</th><th>
Type
</th><th>
Description
</th></tr></thead><tbody><tr><td>
input
</td><td>
Array
</td><td>
Array of words for which to find similar words.
</td></tr><tr><td>
options
</td><td>
Object
</td><td>
Map to refine results.
{ "topN":"String" }
</td></tr><tr><td>
options.topN
</td><td>
String
</td><td>
If provided, returns the top results up to the specified number of words. For example, use `"10"` to return the top 10 most similar words.
</td></tr></tbody>
</table>
|Type|Description|
|----|-----------|
|Array|List of elements containing the similar words for the input word in the corresponding position. These similar words are represented by an of array of pairs in the format `[word, similarity score]`.|
The following example shows how to get similar words using the `GloVe` encoder.
var myEncoderName = 'GloVe'; var myEncoder = sn_ml.EncoderStore.get(myEncoderName); var input = ["apple"]; var options = {"topN":"5"}; gs.print(myEncoder.getActiveVersion().getSimilarWords(input, options));
## EncoderVersion - getStatus\(Boolean includeDetails\)
Gets training completion status.
<table id="table_xfh_vbw_plb" class="parameters"><thead><tr><th>
Name
</th><th>
Type
</th><th>
Description
</th></tr></thead><tbody><tr><td>
includeDetails
</td><td>
Boolean
</td><td><p>Flag that indicates whether to return status <strong>details</strong>.Valid values:</p>
<ul>
<li>true: Return additional details.</li>
<li>false: Don't return additional details.</li>
</ul>
<p>Default: False</p></td></tr></tbody>
</table>
<table id="table_yfh_vbw_plb" class="returns"><thead><tr><th>
Type
</th><th>
Description
</th></tr></thead><tbody><tr><td>
Object
</td><td>
JavaScript object containing training status information for an <a href="../EncoderAPI/">Encoder</a> object.
{ "state": "String", "percentComplete": "Number as a String", "hasJobEnded": "Boolean value as a String", "details": {Object} }
</td></tr><tr><td>
<Object>.state
</td><td><p>Training completion state. If the training job reaches a terminal state, the job does not leave that state. If the state is terminal, the <strong>hasJobEnded</strong> property is set to <code>true</code>.Possible values:</p>
<ul>
<li><code>fetching_files_for_training</code></li>
<li><code>preparing_data</code></li>
<li><code>retry</code></li>
<li><code>solution_cancelled</code> (terminal)</li>
<li><code>solution_complete</code>(terminal)</li>
<li><code>solution_error</code> (terminal)</li>
<li><code>solution_incomplete</code></li>
<li><code>training_request_received</code></li>
<li><code>training_request_timed_out</code> (terminal)</li>
<li><code>training_solution</code></li>
<li><code>uploading_solution</code></li>
<li><code>waiting_for_training</code></li>
</ul>
<p>Data type: String</p></td></tr><tr><td>
<Object>.hasJobEnded
</td><td>
Flag that indicates whether training is complete.Valid values:
- true: Training is complete.
- false: Training is incomplete.
Data type: Boolean value as a String
</td></tr><tr><td>
<Object>.percentComplete
</td><td>
Training percent complete. If the completion percentage is less than 100, the job might be in a terminal state. For example, if training times out.Data type: Number as a String
Range: 0 thru 100
</td></tr><tr><td>
<Object>.details
</td><td>
Object containing a list of additional training details.Data type: Object
</td></tr></tbody>
</table>
The following example shows a successful result with training complete.
// Get status var mlEncoder = sn_ml.EncoderStore.get('ml_incident_categorization'); gs.print(JSON.stringify(JSON.parse(mlEncoder.getActiveVersion().getStatus(true), null, 2)));
Output:
{ "state":"solution_complete", "percentComplete":"100", "hasJobEnded":"true", "details":{"stepLabel":"Encoder Complete"} // This information is only returned if getStatus(true); }
The following example shows an unsuccessful result with training complete.
// Get status var encoderName = 'ml_x_snc_global_global_encoder'; var mlEncoder = sn_ml.EncoderStore.get(encoderName); var trainingStatus = mlEncoder.getLatestVersion().getStatus(); gs.print(JSON.stringify(JSON.parse(trainingStatus), null, 2));
## EncoderVersion - getVersionNumber\(\)
Gets the version number of a solution object.
|Name|Type|Description|
|----|----|-----------|
|None| | |
|Type|Description|
|----|-----------|
|String|Version number.|
The following example shows how to get a version number.
// Get version number var mlEncoder = sn_ml.EncoderStore.get('ml_incident_categorization'); gs.print("Version number: "+JSON.stringify(JSON.parse(mlEncoder.getActiveVersion().getVersionNumber()), null, 2));
Output:
Version number: 1
## EncoderVersion - getWordVectors\(Array input\)
Returns vectors for each input word.
|Name|Type|Description|
|----|----|-----------|
|input|Array|List of strings as words from which to receive vectors.|
|Type|Description|
|----|-----------|
|Array|List of vectors for each word provided.|
The following example shows how to get a vector from the word `hello`.
var myEncoderName = 'GloVe'; var myEncoder = sn_ml.EncoderStore.get(myEncoderName); var input = ["hello"]; gs.print(myEncoder.getActiveVersion().getWordVectors(input));