CoolFace
Apppublic

davanstrien/json-schema-text-classifier

sourceHugging Facemitupdated 1y agoView on Hugging Face
1likes
App README

JSON Schema Generator for Text Classification

A simple, user-friendly tool to generate JSON schemas for text classification tasks. Perfect for structured generation with Large Language Models (LLMs).

๐ŸŽฏ Purpose

This tool helps you create properly formatted JSON schemas that can be used with:

  • โ€”LM Studio - Structured Output field
  • โ€”OpenAI API - response_format parameter
  • โ€”llama.cpp - Grammar constraints
  • โ€”Any LLM API supporting JSON schema validation

๐Ÿš€ Features

  • โ€”Single-label classification - Choose one category from a list
  • โ€”Multi-label classification - Select multiple applicable categories
  • โ€”Live preview - See your schema and example outputs in real-time
  • โ€”Copy & Download - Easy export options for your schemas
  • โ€”Beginner-friendly - No JSON knowledge required

๐Ÿ“– How to Use

  1. 1.Select Classification Type
  2. 2.Single: For mutually exclusive categories (e.g., sentiment: positive OR negative)
  3. 3.Multi: For multiple applicable labels (e.g., topics: can be both "sports" AND "politics")
  1. 1.Add Your Labels
  2. 2.Enter the categories you want to classify text into
  3. 3.Add optional descriptions for clarity
  4. 4.Use the โž• button to add more labels
  1. 1.Configure Options (Optional)
  2. 2.Change the field name (default: "classification")
  3. 3.Set whether the field is required
  4. 4.For multi-label: set min/max number of selections
  1. 1.Get Your Schema
  2. 2.Copy the generated JSON schema
  3. 3.Download as a .json file
  4. 4.See example outputs

๐Ÿ”ง Example Use Cases

Sentiment Analysis

json
{
  "type": "object",
  "properties": {
    "sentiment": {
      "type": "string",
      "enum": ["positive", "negative", "neutral"]
    }
  },
  "required": ["sentiment"]
}

Topic Classification (Multi-label)

json
{
  "type": "object",
  "properties": {
    "topics": {
      "type": "array",
      "items": {
        "type": "string",
        "enum": ["technology", "health", "finance", "education", "entertainment"]
      },
      "uniqueItems": true
    }
  }
}

๐Ÿค Integration Examples

LM Studio

  1. 1.Generate your schema using this tool
  2. 2.Copy the schema
  3. 3.In LM Studio, paste into the "Structured Output" field
  4. 4.The model will only generate JSON matching your schema

OpenAI API (Python)

python
import openai

# Your generated schema
response_format = {
    "type": "json_schema",
    "json_schema": {
        "name": "classification",
        "schema": { ... }  # Paste your schema here
    }
}

response = openai.chat.completions.create(
    model="gpt-4",
    messages=[...],
    response_format=response_format
)

๐Ÿ“š Resources

๐Ÿ› ๏ธ Technical Details

This tool generates JSON Schema Draft 7 compatible schemas that enforce:

  • โ€”Valid JSON structure
  • โ€”Type constraints (string, array)
  • โ€”Enum restrictions for valid label values
  • โ€”Array uniqueness for multi-label classification
  • โ€”Optional min/max constraints for array lengths

๐Ÿ“ License

MIT License - Feel free to use and modify!