Tutorial

How to Categorize Text Content With Custom Classes Using JavaScript?

This hands-on tutorial shows you how to create a custom text classification system using JavaScript. You'll learn to automate text categorization based on patterns, streamlining tasks like feedback organization and ticket tagging.

How to Categorize Text Content With Custom Classes Using JavaScript?

In today’s data-driven world, making sense of large volumes of text is essential—whether you're organizing user feedback, tagging support tickets, or filtering content. That’s where custom text classification comes in. It allows you to automatically assign categories or labels to text based on patterns you define.

In this tutorial, you’ll learn how to build a simple yet powerful custom text classification system using JavaScript.

What is Custom Text Classification?

Custom text classification is the process of automatically assigning predefined labels to text data based on user-defined categories. Unlike generic classification models, it’s tailored to specific needs by training on a small set of example texts provided by the user. These examples guide the system to recognize patterns and apply the correct labels to new, unseen text.

In essence, it allows you to:

  • Define your own categories (e.g., "Positive", "Negative", "Neutral" or "Invoice", "Contract", "Email").
  • Provide a few labeled examples for each category.
  • Use these examples to train a model that can generalize and classify similar texts accordingly.

It's especially useful when off-the-shelf classifiers don’t fit your context or when you're working with domain-specific language.

How to Categorize Text Content With Custom Classes

Get Access to Eden AI API

1. Sign up: You first need to sign up on Eden AI and obtain your API key. This key will give you access to a wide range of AI services including Custom Text Classification.

2. Access Text Processing: Once logged in, head to the Text section of the platform to access the available tools.

3. Choose Custom Text Classification: Click on the Custom Text Classification feature.

Install Required Python Module

To make HTTP requests, make sure you have the requests library installed:

    pip install requests
  

Prepare the Code

Here’s a complete Python example using Eden AI’s /text/custom_classification endpoint:


import requests

headers = {
    "Authorization": "Bearer YOUR_API_KEY"
}

url = "https://api.edenai.run/v2/text/custom_classification"
payload = {
    "providers": "openai",
    "labels": ['spam', 'not spam'],
    "texts": [
        "Confirm your email address",
        "hey i need u to send some $"
    ],
    "examples": [
        ["I need help please wire me $1000 right now", "spam"],
        ["Dermatologists dont like her!", "spam"],
        ["Pre-read for tomorrow", "not spam"],
        ["Your parcel will be delivered today", "not spam"]
    ]
}

response = requests.post(url, json=payload, headers=headers)
result = response.json()
print(result)

Explanation of Code Sections

  • labels: The target categories you want to classify texts into.
  • texts: The list of new texts to classify.
  • examples: Labeled training examples to help guide the model’s predictions.
  • providers: You can specify one or more providers (e.g., "openai").

This is zero-training classification, powered by large language models and guided by your custom examples.

Example Output

Here’s an example of what the API might return:


{
  "openai": {
    "items": [
      {
        "label": "not spam",
        "confidence": 0.93
      },
      {
        "label": "spam",
        "confidence": 0.89
      }
    ],
    "status": "success"
  }
}

Output Field Breakdown:

  • label: The predicted class.
  • confidence: The model’s confidence score.
  • status: Indicates whether the request was successful.

Benefits of using Custom Text Classification API with Eden AI

Using Custom Text Classification with Eden AI API is quick and easy.

 Multiple AI engines in one API
Multiple AI engines in one API

Save time and cost

We offer a unified API for all providers: simple and standard to use, with a quick switch between providers and an access to the specific features of each provider.

Easy to integrate

Eden AI ensures a unified JSON output format across all providers through its standardization efforts. The response elements are also harmonized using Eden AI’s advanced matching algorithms.

Customization

Eden AI allows you to integrate a third-party platform, with the ability to quickly develop connectors. This enables you to take your Document Translation requests further by customizing them with specific parameters, check out our documentation.

Conclusion

Custom text classification is now easier than ever with Eden AI. With just a few lines of Python, you can classify text with real-world accuracy using trusted AI providers. Whether you're filtering emails or tagging feedback, Eden AI offers a simple and scalable solution that grows with your needs.

Ready to build your own classifier? Get started on Eden AI.

Start Your AI Journey Today

  • Access 100+ AI APIs in a single platform.
  • Compare and deploy AI models effortlessly.
  • Pay-as-you-go with no upfront fees.
Start building FREE

Related Posts

Try Eden AI for free.

You can directly start building now. If you have any questions, feel free to chat with us!

Get startedContact sales
X

Start Your AI Journey Today

Sign up now with free credits to explore 100+ AI APIs.
Get my FREE credits now