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
Copy file name to clipboardExpand all lines: articles/cognitive-services/personalizer/includes/change-model-frequency.md
+2-2Lines changed: 2 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,9 +7,9 @@ ms.service: cognitive-services
7
7
ms.subservice: personalizer
8
8
ms.topic: include
9
9
ms.custom: include file
10
-
ms.date: 01/15/2020
10
+
ms.date: 08/25/2020
11
11
---
12
-
## Change the model update frequency
12
+
###Change the model update frequency
13
13
14
14
In the Azure portal, in the Personalizer resource on the **Configuration** page, change the **Model update frequency** to 10 seconds. This short duration will train the service rapidly, allowing you to see how the top action changes for each iteration.
title: Find your Personalizer resource endpoint and key
3
+
titleSuffix: Azure Cognitive Services
4
+
services: cognitive-services
5
+
author: erhopf
6
+
manager: nitinme
7
+
ms.service: cognitive-services
8
+
ms.topic: include
9
+
ms.date: 08/25/2019
10
+
ms.author: erhopf
11
+
---
12
+
13
+
> [!IMPORTANT]
14
+
> Go to the Azure portal. If the Personalizer resource you created in the **Prerequisites** section deployed successfully, click the **Go to Resource** button under **Next Steps**. You can find your key and endpoint in the resource's **key and endpoint** page, under **resource management**.
15
+
>
16
+
> Remember to remove the key from your code when you're done, and never post it publicly. For production, consider using a secure way of storing and accessing your credentials. For example, [Azure key vault](https://docs.microsoft.com/azure/key-vault/key-vault-overview).
* Azure subscription - [Create one for free](https://azure.microsoft.com/free/cognitive-services)
17
17
* The current version of [.NET Core](https://dotnet.microsoft.com/download/dotnet-core).
18
+
* Once you have your Azure subscription, <ahref="https://ms.portal.azure.com/#create/Microsoft.CognitiveServicesPersonalizer"title="Create a Personalizer resource"target="_blank">create a Personalizer resource <spanclass="docon docon-navigate-external x-hidden-focus"></span></a> in the Azure portal to get your key and endpoint. After it deploys, click **Go to resource**.
19
+
* You will 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.
20
+
* You can use the free pricing tier (`F0`) to try the service, and upgrade later to a paid tier for production.
18
21
19
-
## Using this quickstart
22
+
## Setting Up
20
23
21
-
There are several steps to use this quickstart:
24
+
[!INCLUDE [Change model frequency](change-model-frequency.md)]
22
25
23
-
* In the Azure portal, create a Personalizer resource
24
-
* In the Azure portal, for the Personalizer resource, on the **Configuration** page, change the model update frequency to a very short interval
25
-
* In a code editor, create a code file and edit the code file
26
-
* In the command line or terminal, install the SDK from the command line
27
-
* In the command line or terminal, run the code file
28
-
29
-
[!INCLUDE [Create Azure resource for Personalizer](create-personalizer-resource.md)]
30
-
31
-
[!INCLUDE [!Change model frequency](change-model-frequency.md)]
32
-
33
-
## Create a new C# application
26
+
### Create a new C# application
34
27
35
28
Create a new .NET Core application in your preferred editor or IDE.
36
29
@@ -56,15 +49,26 @@ Build succeeded.
56
49
...
57
50
```
58
51
59
-
## Install the SDK
52
+
###Install the client library
60
53
61
54
Within the application directory, install the Personalizer client library for .NET with the following command:
@@ -80,53 +84,194 @@ Determining the reward score, in this quickstart is trivial. In a production sys
80
84
81
85
These code snippets show you how to do the following tasks with the Personalizer client library for .NET:
82
86
83
-
*[Create a Personalizer client](#create-a-personalizer-client)
87
+
*[Create a Personalizer client](#authenticate-the-client)
84
88
*[Rank API](#request-the-best-action)
85
89
*[Reward API](#send-a-reward)
86
90
87
-
## Add the dependencies
88
91
89
-
From the project directory, open the **Program.cs** file in your preferred editor or IDE. Replace the existing `using` code with the following `using` directives:
[!code-csharp[Create variables to hold the Personalizer resource key and endpoint values found in the Azure portal.](~/cognitive-services-quickstart-code/dotnet/Personalizer/Program.cs?name=classVariables)]
Next, add a method to your program to create a new Personalizer client.
100
108
101
-
Next, create a method to return a Personalizer client. The parameter to the method is the `PERSONALIZER_RESOURCE_ENDPOINT` and the ApiKey is the `PERSONALIZER_RESOURCE_KEY`.
[!code-csharp[Create the Personalizer client](~/cognitive-services-quickstart-code/dotnet/Personalizer/Program.cs?name=authorization)]
115
+
returnclient;
116
+
}
117
+
```
104
118
105
119
## Get food items as rankable actions
106
120
107
121
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.
108
122
109
-
[!code-csharp[Food items as actions](~/cognitive-services-quickstart-code/dotnet/Personalizer/Program.cs?name=createAction)]
newList<object>() { new { taste="salty", spiceLevel="medium" }, new { nutritionLevel=5, cuisine="italian" } }
133
+
},
134
+
135
+
newRankableAction
136
+
{
137
+
Id="ice cream",
138
+
Features=
139
+
newList<object>() { new { taste="sweet", spiceLevel="none" }, new { nutritionalLevel=2 } }
140
+
},
141
+
142
+
newRankableAction
143
+
{
144
+
Id="juice",
145
+
Features=
146
+
newList<object>() { new { taste="sweet", spiceLevel="none" }, new { nutritionLevel=5 }, new { drink=true } }
147
+
},
148
+
149
+
newRankableAction
150
+
{
151
+
Id="salad",
152
+
Features=
153
+
newList<object>() { new { taste="salty", spiceLevel="low" }, new { nutritionLevel=8 } }
154
+
}
155
+
};
156
+
157
+
returnactions;
158
+
}
159
+
```
110
160
111
161
## Get user preferences for context
112
162
113
163
Add the following methods to the Program class to get a user's input from the command line for the time of day and current food preference. These will be used as context features.
114
164
115
-
[!code-csharp[Present time out day preference to the user](~/cognitive-services-quickstart-code/dotnet/Personalizer/Program.cs?name=createUserFeatureTimeOfDay)]
[!code-csharp[Present food taste preference to the user](~/cognitive-services-quickstart-code/dotnet/Personalizer/Program.cs?name=createUserFeatureTastePreference)]
170
+
Console.WriteLine("\nWhat time of day is it (enter number)? 1. morning 2. afternoon 3. evening 4. night");
171
+
if (!int.TryParse(GetKey(), outinttimeIndex) ||timeIndex<1||timeIndex>timeOfDayFeatures.Length)
172
+
{
173
+
Console.WriteLine("\nEntered value is invalid. Setting feature value to "+timeOfDayFeatures[0] +".");
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.
126
209
127
210
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, then sending a reward score to Personalizer signaling how well the service did in its selection.
Console.WriteLine("\nPress q to break, any other key to continue:");
270
+
runLoop=!(GetKey() =="Q");
271
+
272
+
} while (runLoop);
273
+
}
274
+
```
130
275
131
276
Add the following methods, which [get the content choices](#get-food-items-as-rankable-actions), before running the code file:
132
277
@@ -141,15 +286,57 @@ To complete the Rank request, the program asks the user's preferences to create
141
286
142
287
This quickstart has simple context features of time of day and user food preference. In production systems, determining and [evaluating](../concept-feature-evaluation.md)[actions and features](../concepts-features.md) can be a non-trivial matter.
143
288
144
-
[!code-csharp[The Personalizer learning loop ranks the request.](~/cognitive-services-quickstart-code/dotnet/Personalizer/Program.cs?name=rank)]
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.
149
309
150
310
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.
151
311
152
-
[!code-csharp[The Personalizer learning loop ranks the request.](~/cognitive-services-quickstart-code/dotnet/Personalizer/Program.cs?name=reward)]
312
+
```csharp
313
+
floatreward=0.0f;
314
+
stringanswer=GetKey();
315
+
316
+
if (answer=="Y")
317
+
{
318
+
reward=1;
319
+
Console.WriteLine("\nGreat! Enjoy your food.");
320
+
}
321
+
elseif (answer=="N")
322
+
{
323
+
reward=0;
324
+
Console.WriteLine("\nYou didn't like the recommended food choice.");
325
+
}
326
+
else
327
+
{
328
+
Console.WriteLine("\nEntered choice is invalid. Service assumes that you didn't like the recommended food choice.");
329
+
}
330
+
331
+
Console.WriteLine("\nPersonalizer service ranked the actions with the probabilities as below:");
0 commit comments