Last week at its annual Build conference, Microsoft announced ML.NET, an "open source and cross-platform machine learning framework" that runs in .NET Core. I took a look at the getting started samples and realized ML.NET would be a great tool to use in OpenFaas functions.
I decided to write a proof-of-concept function based on the ML.NET sentiment analysis sample. Because the function needs a trained model before it can run, you actually need to use a separate application to generate the model and save it as a file. Then you can include the model as part of your function deployment.
Here's a screenshot of my function in action.
You can get the code for my OpenFaas sentiment analysis function here, and the code for the application that generates the model is available here.