The choose_rank() call returns the chosen action among all actions defined in the context.
Here, the context denotes the const char* argument passed to the choose_rank() call.
The format of this context is a JSON string, with a specific structure. This JSON context contains two parts:
- The description of the shared features, i.e. the features shared by all actions.
- The description of the action features, i.e. a JSON array that describes the set of features for each action.
Typically, the shared features describe a user, while the action features describe all the possible actions that can be taken for this user.
In the following, we discuss the expected format for shared features and action features separately, and then at the end we provide an example of the expected context.
Example of shared features:
{
"User": {
"age": 30.6,
"gender": 1
},
"Geo": {
"country": "United States",
"state": "New York",
"city": "Brooklyn"
},
"Refer": {
"referer": "https://www.microsoft.com/"
},
"OUserAgent": {
"ua": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.2 Safari/605.1.15",
"DeviceBrand": "",
"DeviceFamily": "Other",
"DeviceIsSpider": false,
"DeviceModel": "",
"OSFamily": "Mac OS X",
"OSMajor": "10",
"OSPatch": "6",
"DeviceType": "Desktop"
},
...
}
Any field can take either a numeric value (like "age": 30.6 or "gender": 1), or a string value (like "country": "United States").
In this example we used namespaces (i.e. "User", "Geo", "Refer" and "OUserAgent"). It is always a good practice to use namespaces, even if the namespace contains only 1 single feature, because namespaces enable convenient featurization options like filtering or crossing namespaces (see Vowpal Wabbit options https://github.com/VowpalWabbit/vowpal_wabbit/wiki).
Example of actions features (3 actions):
{
...
"_multi": [{
"Action": {
"global_id": 1,
"template": "123"
},
"MoreInfo": {
"video": true,
"blogId": "123456"
}
}, {
"Action": {
"global_id": 1,
"template": "70"
}
}, {
"Action": {
"global_id": 2,
"template": "73"
}
}
]
}
The action features follow the same rules as shared features. Note that each action can have a different set of features.
Reserved field names:
The field name "_multi" is reserved for action features. Its value is a JSON array, where each JSON object in the array defines one specific action.
Another field name, "_text", splits the containing string into features. For example:
becomes
A full example of the expected context (note that newlines shouldn't be included):
{
"User": {
"age": 30.6,
"gender": 1
},
"Geo": {
"country": "United States",
"state": "New York",
"city": "Brooklyn"
},
"Refer": {
"referer": "https://www.microsoft.com/"
},
"OUserAgent": {
"ua": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_6) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/11.1.2 Safari/605.1.15",
"DeviceBrand": "",
"DeviceFamily": "Other",
"DeviceIsSpider": false,
"DeviceModel": "",
"OSFamily": "Mac OS X",
"OSMajor": "10",
"OSPatch": "6",
"DeviceType": "Desktop"
},
"_multi": [{
"Action": {
"global_id": 1,
"template": "123"
},
"MoreInfo": {
"video": true,
"blogId": "123456"
}
}, {
"Action": {
"global_id": 1,
"template": "70"
}
}, {
"Action": {
"global_id": 2,
"template": "73"
}
}
]
}