File size: 3,414 Bytes
169dab9 161b93c 169dab9 161b93c 169dab9 161b93c 169dab9 161b93c |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 |
---
title: JSON Schema Generator for Text Classification
emoji: π·οΈ
colorFrom: blue
colorTo: purple
sdk: static
app_file: index.html
pinned: false
license: mit
---
# 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. **Select Classification Type**
- **Single**: For mutually exclusive categories (e.g., sentiment: positive OR negative)
- **Multi**: For multiple applicable labels (e.g., topics: can be both "sports" AND "politics")
2. **Add Your Labels**
- Enter the categories you want to classify text into
- Add optional descriptions for clarity
- Use the β button to add more labels
3. **Configure Options** (Optional)
- Change the field name (default: "classification")
- Set whether the field is required
- For multi-label: set min/max number of selections
4. **Get Your Schema**
- Copy the generated JSON schema
- Download as a .json file
- 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. Generate your schema using this tool
2. Copy the schema
3. In LM Studio, paste into the "Structured Output" field
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
- [JSON Schema Documentation](https://json-schema.org/)
- [OpenAI Structured Outputs](https://platform.openai.com/docs/guides/structured-outputs)
- [LM Studio Documentation](https://lmstudio.ai/docs)
## π οΈ 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!
|