Microsoft Cognitive Services, the machine-intelligence service formerly known as Project Oxford, provides a suite of cloud-based APIs useful for any developer that wants to include vision, face-recognition, speech recognition, or any of a raft of "AI"-like capabilities into software. With just an API key (you can sign up for a free key to try out any of the services in a rate-limited mode), you can call any of the services via a simple HTTP POST call, passing in parameters (and receiving results) as JSON.
While this is easy enough to do using R using the POST function in the httr package, Software developer Phil Ferriere has wrapped several of the Cognitive Services APIs related to text analysis into simple R function in his mscsweblm4r package. The functions provided include:
- weblmBreakIntoWords: Breaks a string of concatenated words into individual words
- weblmGenerateNextWords: Predict the words most likely to follow a sequence of words
- weblmCalculateJointProbability: Estimate the probability a sequence of words will appear together
- weblmCalculateConditionalProbability: Estimate the probability that a sequence of words appear together, following a specified sequence of words
Each function can generate words or probabilities based on a "model" of the type of text you are working with: web page titles, webpage text, search query text, or webpage anchor text (all based on data analyzed from the Bing services).
You can try out these services without even needing to call the functions yourself, thanks to a Shiny app created and published by Phil. His MS Cognitive Services Shiny Test App will let you pass words into any of the functions and see the results. Click on "Web Language Model API" in the left column to see the functions, and try them out:
If you find the app doesn't give you any results, it's because too many people are using it at once and hitting the rate-limiters of the free service, but you can always use Phil's source code for the app with your own key to run it (or just wait a little while).
Fore more on the mscsweblm4r package, check out Phil's blog post linked below, or check out the package vignette.
Phil Ferriere's OSS Work: Using the Microsoft Cognitive Services Web Language Model REST API from R