You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -25,7 +20,7 @@ You'll need to install the Personalizer client library forN ode.js to:
25
20
* You'll need the key and endpoint from the resource you create to connect your application to the Personalizer API. You'll paste your key and endpoint into the code below later in the quickstart.
26
21
* You can use the free pricing tier (`F0`) to try the service, and upgrade later to a paid tier for production.
27
22
28
-
## Setting Up
23
+
## Model configuration
29
24
30
25
[!INCLUDE [Change model frequency](change-model-frequency.md)]
31
26
@@ -45,28 +40,9 @@ Run the `npm init -y` command to create a `package.json` file.
45
40
npm init -y
46
41
```
47
42
48
-
Create a new Node.js application in your preferred editor or IDE named `sample.js` and create variables for your resource's endpoint and subscription key.
> Remember to remove the key from your code when you're done, and never post it publicly. For production, use a secure way of storing and accessing your credentials like [Azure Key Vault](../../../key-vault/general/overview.md). For more information about security see the Cognitive Services [security](../../cognitive-services-security.md) article.
Create a new Node.js script in your preferred editor or IDE named `personalizer-quickstart.js` and create variables for your resource's endpoint and subscription key. TBD
68
44
69
-
### Install the Node.js library for Personalizer
45
+
### Install the client library
70
46
71
47
Install the Personalizer client library for Node.js with the following command:
Personalizer is meant to run on applications that receive and interpret real-time data. For the purpose of this quickstart, you'll use sample code to generate imaginary customer actions on a grocery website. The following code block defines three key methods: **getActionsList**, **getContextFeaturesList** and **getReward**.
85
-
86
-
87
-
88
-
## Authenticate the client
89
-
90
-
Instantiate the `PersonalizerClient` with your `serviceKey` and `baseUri` that you created earlier.
Actions represent the content choices from which you want Personalizer to select the best content item. Add the following methods to the Program class to represent the set of actions and their features.
The Personalizer learning loop is a cycle of [Rank](#request-the-best-action) and [Reward](#send-a-reward) calls. In this quickstart, each Rank call, to personalize the content, is followed by a Reward call to tell Personalizer how well the service performed.
60
+
## Code block 1: Generate sample data
193
61
194
-
The following code loops through a cycle of asking the user their preferences at the command line, sending that information to Personalizer to select the best action, presenting the selection to the customer to choose from among the list, and then sending a reward to Personalizer signaling how well the service did in its selection.
Take a closer look at the rank and reward calls in the following sections.
245
-
246
-
Add the following methods, which [get the content choices](#get-content-choices-represented-as-actions), before running the code file:
247
-
248
-
* getActionsList
249
-
* getContextFeaturesList
62
+
Personalizer is meant to run on applications that receive and interpret real-time data. For the purpose of this quickstart, you'll use sample code to generate imaginary customer actions on a grocery website. The following code block defines three key methods: **getActionsList**, **getContextFeaturesList** and **getReward**.
250
63
251
-
## Request the best action
64
+
-**getActionsList** returns a list of the choices that the grocery website needs to rank. In this example, the actions are meal products. Each action choice has details (features) that may affect user behavior later on. Actions are used as input for the Rank API
252
65
253
-
To make a Rank request, you'll need to provide: a list of 'RankActions' (_actions_), a list of context features (_context_), an optional list of actions (_excludeActions_) to remove from consideration by Personalizer, and a unique event ID to receive the response.
66
+
-**getContextFeaturesList** returns a simulated customer visit. It selects randomized details (context features) like which customer is present and what time of day the visit is taking place. In general, a context represents the current state of your application, system, environment, or user. The context object is used as input for the Rank API.
254
67
255
-
This quickstart has simple context features of time of day and user food preference. In production systems, determining and [evaluating](../how-to-feature-evaluation.md)[actions and features](../concepts-features.md)can be a non-trivial matter.
68
+
The context features in this quickstart are simplistic. However, in a real production system, designing your [features](../concepts-features.md)and [evaluating their effectiveness](../how-to-feature-evaluation.md)is very important. Refer to the linked documentation for guidance.
256
69
257
-
```javascript
258
-
let rankRequest = {}
70
+
-**getReward** prompts the user to score the service's recommendation as a success or failure. It returns a score between zero and one that represents the success of a customer interaction. In a real scenario, Personalizer will learn user preferences from realtime customer interactions.
259
71
260
-
// Generate an ID to associate with the request.
261
-
rankRequest.eventId=uuidv1();
72
+
In a real production system, the [reward score](../concept-rewards.md) should be designed to align with your business objectives and KPIs. Determining how to calculate the reward metric may require some experimentation.
1. Open _personalizer-quickstart.js_ in a text editor or IDE and paste in the code below.
271
79
272
-
rankRequest.deferActivation=false;
80
+
1.1. Paste your key and endpoint into the code where indicated. Your endpoint has the form `https://<your_resource_name>.cognitiveservices.azure.com/`.
> Remember to remove the key from your code when you're done, and never post it publicly. For production, use a secure way of storing and accessing your credentials like [Azure Key Vault](../../../key-vault/general/overview.md). For more information about security see the Cognitive Services [security](../../cognitive-services-security.md) article.
To get the reward score to send in the Reward request, the program gets the user's selection from the command line, assigns a numeric value to the selection, then sends the unique event ID and the reward score as the numeric value to the Reward API.
87
+
## Code block 2: Iterate the learning loop
281
88
282
-
This quickstart assigns a simple number as a reward score, either a zero or a 1. In production systems, determining when and what to send to the [Reward](../concept-rewards.md) call can be a non-trivial matter, depending on your specific needs.
89
+
The next block of code defines the **main** method and closes out the script. It runs a learning loop iteration, in which it asks the user their preferences at the command line and sends that information to Personalizer to select the best action. It presents the selected action to the user, who makes a choice using the command line. Then it sends a reward score to the Personalizer service to signal how well the service did in its selection.
283
90
284
-
```javascript
285
-
constrewardRequest= {
286
-
value: reward
287
-
}
91
+
The Personalizer learning loop is a cycle of **Rank** and **Reward** calls. In this quickstart, each Rank call, to personalize the content, is followed by a Reward call to tell Personalizer how well the service performed.
Run the application with the Node.js from your application directory.
97
+
Run the application with the Node.js command from your application directory.
295
98
296
99
```console
297
-
node sample.js
100
+
node personalizer-quickstart.js
298
101
```
299
102
103
+
Iterate through a few learning loops. After about 10 minutes, the service will start to show improvements in its recommendations.
104
+
300
105

106
+
107
+
The source code for this quickstart is available on [GitHub](https://github.com/Azure-Samples/cognitive-services-quickstart-code/blob/master/javascript/Personalizer/quickstart-sdk/personalizer-quickstart.js).
0 commit comments