Skip to main content

· 3 min read
Jonathan Wilde

We're introducing EnergeticAI Classifiers, a new library for few-shot text classification.

What is few-shot text classification?

Few-shot text classification is the task of classifying text into a set of categories, given only a few examples of each category.

For example, you might want to classify support tickets into categories like "Billing", "Technical", and "Other". You could provide a few examples of each category, and then use the model to classify new tickets. Over time, you can adjust the categories, and the model will adapt without retraining.

This differs from traditional text classification, where you need hundreds or thousands of examples, and retrain the model every time you want to add a new category.

How do I use EnergeticAI Classifiers?

You can use EnergeticAI Classifiers in just a few lines of code.

First, install the library from npm:

npm install @energetic-ai/core @energetic-ai/classifiers

Then, you can create a model and use it to classify text:

import { initClassifier } from "@energetic-ai/classifiers";

(async () => {
// Initialize with training examples
const classifier = await initClassifier([
["The world is happy", "Positive"],
["Work is so fun", "Positive"],
["I had a great day", "Positive"],
["I had a bad day", "Negative"],
["I am frustrated", "Negative"],
["I am depressed", "Negative"],
]);

// Classify a single string
const single = await classifier.classify("The weather is so nice today");
// { "label": "Positive" ... }

// Classify multiple strings in a batch
const multiple = await classifier.classify([
"What is this? I am so angry!",
"I am so excited!",
]);
// [{ "label": "Negative" ... }, { "label": "Positive" ... }]
})();

Each label result contains confidence values, which you can use to filter out low-confidence labels if you want.

How does it work?

EnergeticAI Classifiers builds on top of the Embeddings to convert embeddings for the examples of each category. During classification, it uses a KNN lookup to find the buckets with the closest embeddings, and then returns the most common label from those buckets.

Acknowledgements

This project is standing on the shoulder of giants, derived from the KNN Classifier in TensorFlow.js KNN Classifier library.

Get involved

We'd love to have you involved in the project! Here's some ways you can help:

  • Try it out. We'd love to hear your feedback on the project. If you have any questions or comments, please open an issue.
  • Spread the word. Please star the project on GitHub and share it with your friends and colleagues!
  • Contribute. We'd love to have you contribute to the project. If you're interested in contributing, please open an issue and we'll help you get started.

· 3 min read
Jonathan Wilde

We're excited to introduce EnergeticAI, a Node.js library that makes it easy to build apps with open-source AI models.

The norm in the AI space is to send massive amounts of data to prioprietary foundation model providers. This is creates significant risk to any company doing this:

  • Privacy & security. You're sending data to a third party, making the foundation model provider a single point of failure for your business, and creating a privacy risk for your customers.
  • Financial. Your product unit economics depend on the foundation model provider's rates and they can change their pricing at any time.
  • Vendor lock-in. You're building your business on top of the foundation model provider's platform idiosyncracies, and it's not always easy to switch to another provider if you need to in a hurry.

Ideally, you'd able to npm install an AI model and use it to build your app.

There's a few existing open-source AI models that you can find on NPM, but they're frequently packaged in ways that make them large and slow in serverless functions, require a surprising amount of configuration to get working, or not have appropriate licensing for commercial use.

Enter, EnergeticAI

EnergeticAI solves this, with a distribution of TensorFlow.js optimized for serverless functions:

  • Small module size (~3 MB vs. 146 MB - 513 MB for stock TensorFlow.js)
  • Fast cold-start inference (~50 ms vs. 2000+ ms for stock TensorFlow.js)
  • Incredible ease-of-use (pre-trained models for common cases)

It's intended to be a condensed replacement for TensorFlow.js, so you can use it with much existing code and models, and it's licensed as Apache 2.0 for commercial use. Dependencies may have different licenses, though on principle we leverage models with permissive licenses.

We're starting with a single pre-trained model, embeddings, and plan to add more soon.

We have a comprehensive tutorial to show how to use embeddings to power product recommendations for an e-commerce site:

Tutorial

Getting started

EnergeticAI is as easy as npm install:

npm install @energetic-ai/core @energetic-ai/embeddings @energetic-ai/model-embeddings-en

Then, you can import the model library and use it:

import { initModel, distance } from "@energetic-ai/embeddings";
import { modelSource } from "@energetic-ai/model-embeddings-en";

(async () => {
const model = await initModel(modelSource);
const embeddings = await model.embed(["hello", "world"]);
console.log(distance(embeddings[0], embeddings[1])));
})();

What's next

We're just getting started with EnergeticAI, and we have a lot of exciting things planned:

  • More libraries. We're exploring libraries to make it easy to leverage the embeddings model for more use-cases, such as few-shot classification.
  • More models. We're exploring importing more models, such as a multilingual embeddigns model, as well as models like BERT to enable use-cases like question-answering.
  • More integrations. We're exploring more ready-to-use options, such as a library for semantic search that can be dropped into libraries such as Docasaurus.

Acknowledgements

This project is standing on the shoulder of giants, derived from TensorFlow.js, and leveraging Universal Sentence Encoder from TensorFlow Hub. This project would not have been possible without the foundational work of these projects.

Get involved

We'd love to have you involved in the project! Here's some ways you can help:

  • Try it out. We'd love to hear your feedback on the project. If you have any questions or comments, please open an issue.
  • Spread the word. Please star the project on GitHub and share it with your friends and colleagues!
  • Contribute. We'd love to have you contribute to the project. If you're interested in contributing, please open an issue and we'll help you get started.