Fognitive Services: F# and Azure Cognitive Services
Machine Learning is revolutionizing how we think about processing data. But machine learning algorithms can have a steep learning curve. Luckily, Microsoft has released an easy way to access very powerful machine learning models through Azure Cognitive Services. They expose the power of machine learning through the ease of calling a REST API.
With help from Reed and Ryan Riley, I created the start of this project. It is built on the existing NuGet package for Cognitive Services .NET SDK. We started with the C# sample code and did a basic translation of it into F#. Then we refactored it to be idiomatic F# code. For example, the API now takes an F# list of tuples instead of a C# list of a custom data structure. This means that the API integrates smoothly with the other F# language tools like piping and pattern matching. Ryan and I recorded a screencast while we did part of this refactoring.
The GitHub repo contains some sample apps for each API. But I also put together a slightly more interesting demo project. The Cognitive Services Text API has the ability to pick out key phrases from a block of text. There is a wrapper in Fognitive Services for this in FognitiveServices.Text and there is a NuGet package for it. I thought it would be interesting to use Canopy to screenscrape the session list from the StirTrek conference page and pick out the key phrases from each session. This turned out to be incredibly easy. The entire project is available on GitHub. Here is the meat of the code.
All of the real work is done in the analyzeStirTrekTags function. Lines 9 and 10 load up the page in the browser. Line 12 initializes the Cognitive Services client. Lines 15 and 16 scrape the session titles off of the web page. The list of titles is seamlessly piped into the FognitiveServices API call on line 17 which returns the results. Line 19 prints the results.
This easy integration between two F# libraries was one of the main goals behind Fognitivie services. It combines the ease and power of Cognitive Services with the power and elegance of F#.
Feel free to comment on the post but keep it clean and on topic.comments powered by Disqus
My name is Eric Potter. I have an amazing wife and 5 wonderful children. I am a Microsoft MVP for .Net. I am a software architect for Aptera Software in Ft. Wayne Indiana and an adjunct professor for Indiana Tech. I am a humble toolsmith.
Aptera Blog Posts
Posts I have written for the Aptera Blog: