Cognitive Services APIs: Knowledge
“Ipsa scientia potestas est.” – Sir Francis Bacon
In the last two posts in this series, we covered the Speech APIs and the Language Understanding APIs. In the current post, we’ll go over the Knowledge APIs. There is a natural progression to this since from speech, we derive meaning, and with meaning we obtain knowledge. The Knowledge APIs provide ways to link our collective knowledge and to access that knowledge in more effective ways.
Academic Knowledge API
Sometimes we want to find out what our social networks are saying about a given topic, like a recent wardrobe malfunction at a star-studded celebrity event. The Academic Knowledge API isn’t for that and would return terrible results if we tried.
The Academic Knowledge API, as you might guess from the name, acts as a computer librarian for retrieving the best academic research on topics you are interested in. It uses its knowledge of natural language semantics (how we speak), along with its understanding of what the papers it has indexed in the Microsoft Academic Graph are about, in order to track down the entities that are most relevant to your request.
There are five REST endpoints in the Academic Knowledge API…
- https://westus.api.cognitive.microsoft.com/academic/v1.0/interpret – The Interpret method takes a natural language query and transforms it into a structured query that can be used by the Evaluate method.
- https://westus.api.cognitive.microsoft.com/academic/v1.0/evaluate – The Evaluate method takes a structured query and returns references to the entities you are looking for. By entity we mean metadata about academic papers such as the title, paper year, estimated citations, field of study, journal or conference id, etc. If you search the academic graph for prominent articles on wardrobe meltdowns, this the response you get back:
{ "expr": "composite(AA.AuN==’wardrobe malfunction’)", "entities": [] }
And here are the entities you get back if you search for Francis Bacon:
{
"expr": "composite(AA.AuN==’francis bacon’)",
"entities": [{
"logprob": -18.364,
"Id": 567362522,
"Ti": "the new organon"
}, {
"logprob": -20.279,
"Id": 2414579677,
"Ti": "novum organum 1620"
}, {
"logprob": -20.32,
"Id": 2493700514,
"Ti": "confession of faith"
}, {
"logprob": -20.726,
"Id": 1487541657,
"Ti": "the instauratio magna part ii novum organum and associated texts"
}, {
"logprob": -20.984,
"Id": 1905465919,
"Ti": "la nouvelle atlantide"
}]
}
- https://westus.api.cognitive.microsoft.com/academic/graph/v1.0/search? The Graph Search method returns entities based on a graph pattern instead of an expression.
- https://westus.api.cognitive.microsoft.com/academic/v1.0/similarity? Similarity compares two text strings (for instance, two paper abstracts) and returns a similarity score after assessing the academic concepts contained in the two texts.
- https://westus.api.cognitive.microsoft.com/academic/v1.0/calchistogram? CalcHistogram calculates the distribution of attribute values for a set of paper entities.
Knowledge Exploration Service
KES takes data and grammar that you provide and creates a service that enables interactive search with autocompletion. It basically lets you build something equivalent to the Academic Knowledge API with your own documents, whether you are dealing with cookbooks, medical data, D&D manuals or galactic star charts. Refer to the Getting Started guide to discover all that it offers.
Entity Linking Intelligent Service
ELIS searches a paragraph of text you send to it and identifies entities suitable for linking. It also returns links to Wikipedia for the entities it identifies. It’s the sort of thing that would work great as plugin for a blog engine or reading app.
What makes the service particularly clever is that it disambiguates words based on context. For instance, “Mars” can mean either the war god of the Roman pantheon or the fourth planet from the Sun. Elis can figure out which is which. This is a sample of returned results for the paragraph above (filtered to show Mars related entries only):
{
"entities":[{
"matches":[{
"text":"Mars",
"entries":[{
"offset":0
}]
},
{
"text":"Red Planet",
"entries":[{
"offset":172
}]
}],
"name":"Mars",
"wikipediaId":"Mars",
"score":0.993
},
{
"matches":[{
"text":"Roman god of war",
"entries":[{
"offset":122
}]
}],
"name":"Mars",
"wikipediaId":"Mars (mythology)",
"score":0.007
}]
}
ELIS found two entities that match the Wikipedia entry “Mars” and one entity that matches the disambiguated Wikipedia entry “Mars (mythology).”
QnA Maker
Most websites these days include a Frequently Asked Questions section. The QnA Maker is a free service that lets you take one of these FAQs and turn it into an intelligent service that understands natural language and can interact with people in a conversational way over email, Facebook and chat. QnA Maker is both a REST API and a web-based user interface.
To get started, go to the QnA Maker website, create a new service and upload or link to your FAQ. You can also enter your question and answer pairs manually.
Once the FAQ is ingested, the QnA Maker will walk you through training and testing your service until you are ready to publish.
After publishing your QnA service, you will be provided with the REST endpoint to call your service, which you can incorporate into a bot if you’d like to.
To learn more about using the QnA Maker to build an intelligent service out of your FAQ, refer to the QnA Maker FAQ (someone clearly had a lot of fun with this).
Recommendations API
The Recommendations API supports the sort of smarts you see on shopping websites, music sharing services and web streaming services. It handles three types of recommendations:
- Frequently bought together recommendations—people who buy this right-handed glove often also by this matching left-handed glove with it.
- Item to item recommendations—if you are looking at this item, may we suggest you also look at this other item that we sell?
- Personalized user recommendations—we’ve noticed that you listen to this sort of music X a lot, so we think you would like this new album Y.
Like the QnA Maker, the Recommendations API is both a REST service and a web-based UI for creating, training and publishing functionality.
Sign up for an account key and head over to the Recommendations UI page in order to create a new project. You will then upload your product catalog and usage data and use this to train your recommendation model.
To learn more about developing recommendations for your website, read this Quick Start guide.
Wrapping Up
If, as Francis Bacon believed, knowledge is power, then Cognitive Services is its engine. The Cognitive Services Knowledge API helps you find information you need and also makes it easier for others to access the information you already have. It harkens back to the original purpose of the internet, sharing knowledge and reinvigorates it with machine learning. The following links will help you to further explore the capabilities of the Knowledge APIs.