Local First AI
Libraries, Models, Algorithms and Tools
Over the last 10 years, there has been a huge expansion of javascript AI/ML libraries that enable embedding AI into client-side bundles and serverless functions and cater for various use cases. This article lists a few of the libraries I found most useful in the past and highlights their uses.
As I explored in my Minimal Viable Model piece, using the smallest, most appropriate model for the job unlocks better user experience, improves performance/cost, and provides privacy benefits. Check out that article to learn more about the higher-level benefits of this approach.
AI is not just ChatGPT & LLMs
The majority of AI that we interact with daily isn’t generative AI. It’s predictive AI & ML models that help you plan your next month’s budget, predict bus times, identify faces in an image or words in your speech, classify customer support tickets and calculate trends in seasonal data like your workout load. This kind of predictive AI is great at churning through tons of data at speed.
Predicting Numbers, Series or Trends
(Linear) Regression
Example: You’ve recorded your caffeine intake and the number of hours you slept the next night. You tracked this for 2 months.
Today, you had 2 coffees and want to predict how your sleep is going to be affected.
Javascript library: Regression-js
ARIMA (Autoregressive Integrated Moving Average)
Example: You’ve got a spreadsheet of your transactions over the last 3 years and want to predict your spending trends in the next few months.
Javascript Library: Arima
Classifying data
KNN Classifiers (Neural Networks)
Example: You want to be able to detect (and classify) what kind of workout a person is doing based on their motion, heart rate and speed/pace data. Another example could be detecting whether a person is on the tube or not – is this what Transit App uses?
Javascript Library: kNN
Sentiment analysis (Natural language processing)
Example: You want to quickly identify users’ sentiment towards your service. You’ve got a bunch of messages or comments. Using a sentiment analysis model you can quickly get values from -1 to +1 and then transform those into star ratings, etc – for example: “I loved your service”: 5, “I am so frustrated”: 1.
Javascript Library: Natural
Text Classification (Bayesian and Logistic Regression)
Example: You’ve got several emails from customers and want to quickly classify them into a set of categories you defined. For example, at Dogsnug they might want to quickly sort them into: “Sizing questions”, “Returns & Refunds”, and “General Enqury”.
Javascript Library: Natural
Image and Audio Recognition
Simple classification: Hot dog, not hot dog
Example: You want to point a camera at something and classify whatever it sees into distinct categories, like the example on the Silicon Valley episode of identifying hot dogs and non-hot dogs.
Libraries & Tools: Teachable Machine, Tensorflow, ML5 Image Classifier
Identify body pose
Example: You want to identify what the person in the image is doing.
Javascript Library: ML5 Body Pose
Recommendations (using embeddings)
Example: You’ve got a database of “things” you want to recommend, such as activities in the Lakes District. Your user has just completed a hike up Scafell Pike, and you want to recommend other similar ones. Another example might be a library of books.
Libraries & models: Transformers.js, Supabase GTE Small Embeddings Model
Outro
With the increased use of JavaScript on the back-end/API side of web services and apps, libraries and frameworks have come a long way. I am excited about all the cool stuff we can now build using the tools we use already.