>> And I’m Martin Kearn.
>> And today, we’re going to be talking about.
>> Yeah, specifically the Cognitive Services Recommendations API.
>> It’s an API?
>> Yeah, yeah.
>> In the production meeting, when you mentioned recommendations, I thought you wanted recommendations for the show, so I booked someone to do recommendations for us.
>> Did you?
>> I prefer the term Hotel Concierge.
>> So we’ve got a concierge for the show.
>> Indeed, yeah, yep.
>> Okay, fine.
>> Just deal with it.
>> That’s good.
>> So what are we gonna do with recommendations then?
>> So one of the many things that Cognitive Services does, is it has a whole API for recommendations. So the idea is if you’ve got an inventory of products or SKUs or any items really, it’s able to kind of, and you’ve got usage information about those items, it’s able to determine customers that bought that or this, customers that liked that liked this.
>> These things are often brought together. All those kind of things that you see in e-commerce sites all the time.
>> And it’s able to do that for any of your [INAUDIBLE] basically, so we’re going to take a look at that. So just to start off with, I’m just going to go into Amazon. So presumably, you’ve been to Amazon before, presumably.
>> I have-
>> Once or twice been to Amazon, yep.
>> Good, so I’m just going to do a little search for an XBox game here, just to show what we’re talking about here. So I can’t think quite what to search for.
>> I’d recommend Forza Horizon 3. It’s new and it’s really good.
>> Okay, well, that’s fair enough. I’m just gonna go with that, so Forza Horizon 3. Let’s have a look at that. So when I open the actual item details page for this game, so I’m not signed into Amazon at the moment. And if I scroll down here, we can see, hopefully you can see that there. Frequently bought together is Forza Horizon 3 and the Xbox One Minecraft Console bundle.
>> So Amazon has determined that those two items are actually frequently bought together. They’ve also determined that customers who bought Horizon 3 also bought Tomb Raider, Just Dance 2017, Rocket League, and these other Xbox items.
>> One of my favorites, Just Dance 2017.
>> I thought you might like that, actually, yeah. That seemed like it’s just right up your street. So the point here is that most e-commerce sites do this kinda stuff, anyway. But this API allows you to do it. If I also sign in to my Amazon account here. Now don’t look, I’m just gonna login here, this is my password.
>> I won’t look.
>> There you go, brilliant, so that’s top secret, top security. And if I go back to the home page now, you’ll see now I’ve logged in, it’s given me related to items I’ve viewed. So it’s gonna be personalized [CROSSTALK]
>> This could be interesting.
>> Yeah, so if we go to see more, Any second now. Amazon’s being unusually slow. It’s gonna basically, based on my sort of browsing history on Amazon, which-
>> They should get this on Azure.
>> They should, shouldn’t they? I wonder where they host it.
>> I’ve got no idea.
>> Let’s just try that again, just to make sure that. Okay, so now I’ve logged in to Amazon. We can see that I’ve got related to items I’ve viewed. If I see more here, it’s gonna look at the fact that I’ve just looked at Forza Horizon. I did clear my Amazon history before I did this. Cuz I thought nobody wants to see the sort of things I buy on Amazon. And it has given me that personalized recommendation. So if I view more things, so let’s say that I look for Bose headphones, for example.
>> We’re both big Bose fans.
>> Yeah, I love a bit of Bose, I do. Those ones are particularly good ones. I’m gonna look at that. That’s now added to my kind of browsing history on Amazon. If I go back to that same place that we just went to, it’s now going to show me a combination of things, based on both the headphones and the gamut of things that I might wanna buy. And actually I’m genuinely looking at SONOS speakers at the moment as well, so that’s pretty cool. It’s actually picked that up straightaway. So this is a personalized recommendation based on my personal information, not just the generic information. So those are the kind of three things that these things generally do. So let’s have a look at our actual service and see how that compares. If we go to Cognitive Services, You can just do a search for that, there’s no need to type in URLs. We can just search for it, we’ve got search engines these days. It’s
>> Yep, use the Internet like my dad, online.
>> Yeah, yeah, yeah.
>> Go with APIs into the knowledge section, we have recommendations. And you’ll see that this is the API, so you’ll have three main functions. Has frequently bought together recommendations, so that is basically things like, if you’re buying an Xbox, you might buy this game with it as well. If you’re buying an iPad, you might buy this case that goes with it. It’s items that are frequently bought together. Item to item recommendations. This is customers who like this product also like this product. So we saw that if I add Forza to my cart, it’s suggesting Minecraft as well and other things like that. And then the personalized use recommendations, which is what we just saw where it’s based on my browsing history, where you can get a bit more personal insight based on what they looked at last time they were here, that kind of thing.
>> Right, okay.
>> So that’s what the API basically does. So let’s get started with this. We need a key. The way we get a key is we click Get Start-
>> You mentioned the keys in the production meeting.
>> It’s not that sort key.
>> Okay, right.
>> It’s an API key, a way of actually logging into an API.
>> I’ve got an account on live.co.uk. I’ve had it for several years. It’s quite nice, I quite like using it. I’d recommend outlook.com, live.co.uk is so last decade.
>> Okay, well, thanks for that, but I’m still gonna use my live.co.uk., if that’s okay.
>> That’s what recommendations are for, right?
>> Yeah, just take them or leave them. You don’t have to follow the instructions there. Okay, so I’m logging in using my Microsoft account. Now I’ve actually already signed up to this so I can simply show you my API key, which is this guy here. I’m just gonna copy him and put him into Notepad for reference later on. But that’s the thing you need, with all of these APIs you need the API key as a starting point. That’s the main thing. Okay, so before we dive into the API tour, I’m gonna show you the data that I’ve got for this.
>> Yeah, okay.
>> So we’ve got some data files. If we go into here, we can go into here. And I’ve got some book information. So this is for novels, that kinda thing. If we look at catalog large, I’ll show you where we got this in a second. So this contains lots of information about books. So I think this site has 2,000 books or something like that in here. That basically contains an id, right? The title of the book, a category of it being book, and then some extra data as well.
>> This is just comma separated?
>> Just comma separated, it’s just a CSV file basically, yeah.
>> So that’s my catalog, as we call it. And I’ve also got a usage file here. So this is information about, in this case, people that have looked at these books or read these books. So this is, again, a CSV. It’s got this even bigger-
>> Huge, huge usage.
>> And huge usage, yeah. It’s almost like this is a demo dataset. And what it basically contains is the book id, and the id of the user that uses it.
>> The book id, user of the id.
>> Sorry, the user id first, and then book id.
>> Okay, okay, so that the user id is just in your system?
>> Yeah, it’s just a unique identifier for a user in your system.
>> That’s what’s great about it. Just as long as you say that’s the user id, it doesn’t matter what that actually is, as long as it’s unique. So this data, I got this from the website itself. So if you go to the Recommendations website, you go to documentation.
>> And in here there’s a Getting Started guide, if we can go to that. And then about halfway down, it says, did you bring your data? I didn’t. You can download data from here. There’s a nice, handy OneDrive link. And that has actually two data sets in there. One of them is the books data set I’ve just looked at. Another one is based on the Microsoft store, so it has all the Microsoft products and who’s bought what.
>> But books is a bit easier to work with.
>> But they’re both good data sets. You can have a look at both of those and play around with them. So we’re using books. So the next thing, just in terms of inside of the schema, if you want to actually bring your own data, if we just go back up again to the Cognitive Services web page and back again. If we go to the API Reference, we can actually look at the API cause, and it sees what’s required. So the first one around the catalog is a post request. Upload the catalog to a model. If you go in here, it’s gonna tell you what’s required. So it’s gonna say it needs an item Id and what type that needs to be. An item name, an item category, the description. And it’s got this thing called the Feature that switches where you have this extra data if you want to use that in some way. So that’s for the catalog. And then similarly for the usage file, the schema is in there as well. So in this case, usage file, it needs a user id, needs an item id, needs a time stamp as well.
And also you can have one of these five events. So that can be quite useful if you wanna change your recommendations based on different types of events. So people that looked at this versus people that added it to the cart or whatever it might be. The data we’ve got doesn’t have any of this stuff. But it’s there for you to use if you want to. So once you’ve got all of that stuff done, we can now create a recommendations project. So we go to the Recommendations UI.
>> It’s beta.
>> It’s beta, most of this is beta at the moment. But yep, it is beta. And we’re gonna just create a new project. I’m just gonna call this Books. A project is basically, one of the things that’s interesting with this is in a real life scenario, you’re gonna wanna continue to upload new usage information. So the catalog might change a little bit as time goes on. But your usage can change all the time.
>> So you’ll have noticed when we looked at the API there, there were loads of different functions. Most of those is the management of the build and management of the model, so that to do uploading new usage data, uploading new items to the catalog. There’s only a few of them that have to do with the actual API request of getting recommendations. We’re gonna kind of look a lot at those as we go along. So let’s set up the catalog file. I’m just gonna browse to where it is again. There it is, catalog file. And then we’ll add one, you can add a lot of different usage files, of course. And the more you add, the more accurate it gets.
>> And then we’ll add the usage file as well. And the next thing we’re gonna do once we’ve created that, is we’re going to create some builds. Now there’s two types of builds. So a build is where basically it will examine these data files and come up with an API. The first one is a recommendations, or an item-to-item build, which is where you’d say, people that like this item also like this item. And there’s another type of build called a frequently bought together build, and they’re slightly different models. They use slightly different approaches as to why they work. So you can have as many builds using this data set as you like.
>> Right, okay, so if you wanted to take advantage of both those features, you’d need the two models.
>> Yeah, well, two builds on the same model, right, yeah. So we’re just gonna grab this model ID as well. We’ll need that later on. I’m just gonna put that in my Notepad. Okay, there’s where they are for now. And so let’s do a new build. And so the first build type is recommendation. There’s advanced settings you can look at as well, but we’re not gonna worry too much about that. I’m just gonna call this Recommendation and do Build. So this will take a while, so that’s gonna basically look at the catalog, look at the usage files, and create a recommendations build. And while that’s doing that, they’re frequently bought together as well, FBT. And we’re gonna have two builds based on this data set. Okay, so those are gonna run away in the background. You can see that it’s only 10% through, and that one’s actually finished already. So while those are building, let’s start looking at the API and actually seeing how we can actually work with the API to make requests in here.
So once again, we can go back into the Cognitive Services website, and we go to API reference. So these are all of the API functions for managing the builds, uploading new builds, uploading new data files, that kind of thing. The one to actually get a recommendation is this one, get item to item recommendations.
>> It took me a while to find that cuz it’s kind of like, and even the sample code has all to do with managing it rather than actually using it. So this is what we’re interested in. And as with most things in the cognitive, we’ve got this nice API Testing Console-
>> That’s all right, it’s pretty cool.
>> Which will actually do a real world request. So what I’m gonna do here is I’m gonna add some manager data. So the first thing it needs is the model ID. Now we captured that just in our previous step. So I’m gonna copy that across from there. There’s the model ID. I’ll come back to items in a second. The number of results found. How many results do you want back? The minimum scoring set is 0. I asked for build ID as well, so this is where you can have different, you can use frequently bought together request versus an item-to-item request.
>> So the build ID that I wanted for the initial one is this guy here. It’s 1601293.
>> So this is, okay, right.
>> So in your application you might do multiple requests to the API for different types of information.
>> And you’d pass a different build ID.
>> When you update a build, a new build ID, right-
>> Yeah, yeah, yeah, okay.
>> So you can have different versions.
>> Well, what happens if you omit the build ID, it just defaults to the active one. That’s the concept of an active build.
>> It’ll default to that. But you can specify different types of builds as well.
>> Okay, cool.
>> So in a real world scenario, you might have a new build every day, cuz you might have new uses or information every day. Or you might have seasonal specials, that kind of thing.
>> But for this, it’s fine. So okay, so just before we try it, so I’m just going to go back to the website and check that they’ve both built. They have now both built which is good so that means that it’s ready to work. The API is ready to work. So I just now need an item id. Now, this is gona be based on my book, Carlo.
>> So I just need to get an id of a book to enter in here.
>> I’d recommend Watership Down. It’s a classic book about bunny rabbits and the great song that goes with it, Bright Eyes, burning like fire.
>> The book ID number is one, four-
>> One, four.
>> Zero, zero-
>> Zero, zero.
>> Three, nine-
>> Three, nine.
>> Five, eight, nine-
>> Five, eight, nine, thank you. This concierge is good.
>> [INAUDIBLE] [LAUGH]
>> How did she know the ID? It’s amazing. Okay, well, I’ve entered that into the itemIds section now. And the only other thing I need, that’s with any of the Cognitive APIs, is I need my Ocp-Apim-Subscription-Key.
>> I use it all the time, but, I’ve got no idea what Ocp-Apim-Subscription-Key is.
>> No, me neither. If anyone does, then just write in the, we could probably look it up.
>> But let’s stay in the dark.
>> So if we go back over to the screen now, we can see that I’ve just copied that from Notepad, that was a header. And now I’m just gonna do Send, and hopefully, it’s gonna give me a 200 OK Yes, it’s given me a 200 OK. And it’s given me a set of recommendations based on that particular title, so got Memories of Geisha, Bridget Jones’s Diary, Northern Lights, etc., etc. If I want to do a frequently bought together, I just change, get that build id. And just change the build id field there, and do the same request. All the other headers stay the same. And you can see it says things like, people who bought Watership Down also bought Memories of a Geisha. So Memories of a Geisha, Memoirs of a Geisha-
>> Geisha, I know, right.
>> That’s a strange combination of books.
>> It’s only sample data, though.
>> I don’t know if this is real. But you can see that because it’s frequently bought together, it’s only one recommendation’s come back, which is that one.
>> Well, this is the power of recommendations, right? Because I wouldn’t have assumed that-
>> Recommendation, but the data says it exists.
>> And the other interesting thing is it’s a very low scoring recommendation. So as with anything with the cognitive codes you get a score. This is only 16%. So it’s quite a low scoring recommendation.
>> So what I’ve done is I’ve taken all that stuff together and I’ve built a new application, which is on my GitHub. You can go to my GitHub. I’ll tweet about it. It’s important, I’m sure. And see this application works over an ASP.net core application, which basically uses all of this. It uses the same catalog and it gives you a little UI too. Okay, so just gonna load up Visual Studio, so we can actually take a look at the code of the project here. And I’ll get started.
>> I’d recommend you use Visual Studio Code or even Visual Studio 2017. Both these IDs will work.
>> Okay, well, that’s great. I mean, I could use those. I’m not going to. I’m gonna stick with what I know.
>> But if it’s a recommendation, why not?
>> So let’s just run the project up and just see what happens, and see if it starts working. Like I say, I mean, I’ve done this on ASP.NET. It could be anything, though. They’re just API calls. Just standard REST API calls. Takes a little while because I literally load that catalog into memory as I laid the application, but here we go. So we’ve got a web page here which has a very good UI with 1700 books on it.
>> Watch out, Amazon.
>> Yeah, watch out Amazon. This is the future of book UI. How about a search engine? Just use CTRL+F.
>> Yeah, exactly.
>> And I click into it, and when I click into it, in this case, The Piano Man’s Daughter, just a random book. It’s gone off to the API, and it’s brought me back all of the recommendations. There isn’t any frequently brought together ones for this one. If I click just a random other one, let us see. And then it goes, it’s brought the recommendations that are on this one does have Frequently Bought Together recommendations as well. So I normally go for the code of that, but you can look that up on GitHub if you’re interested, but there you go. That’s the Recommendations API in a nutshell.
>> Okay, so thank you very much for showing us the Recommendations API. So I just wanna try one last thing before we go.
>> No problem at all.
>> Concierge, please say goodbye.
>> I’m sorry. I didn’t understand that.
>> Never mind anyway [LAUGH]
>> You can’t have everything, can you?
>> See you next week.
Martin and Martin look at Recommendations API in Microsoft Cognitive Services and show how you can use it to give your website users useful product recommendations.