File size: 3,491 Bytes
779419d
79a3e7e
 
779419d
79a3e7e
779419d
79a3e7e
779419d
 
 
 
79a3e7e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
---
title: Zero-Shot Text Classification
emoji: 🎯
colorFrom: blue
colorTo: purple
sdk: gradio
sdk_version: 4.44.0
app_file: app.py
pinned: false
---

# 🎯 Zero-Shot Text Classification API

A powerful text classification API using **microsoft/deberta-v3-large-mnli** model. Classify any text into custom categories without training!

## Features

- πŸš€ **Zero-shot classification** - No training data needed
- 🎨 **Interactive Gradio UI** - Easy-to-use web interface
- πŸ”Œ **RESTful API** - Programmatic access
- πŸ“Š **DeBERTa-v3-large** - State-of-the-art NLI model
- πŸ”’ **Private Space Support** - Can be deployed as private

## Usage

### Web Interface

Simply enter your text and comma-separated labels, then click "Classify"!

### API Usage

#### Python

```python
import requests

response = requests.post(
    "https://YOUR-USERNAME-YOUR-SPACE-NAME.hf.space/api/predict",
    json={
        "data": [
            "I absolutely love this product!",
            "positive, negative, neutral",
            true
        ]
    }
)

result = response.json()
print(result)
```

#### cURL

```bash
curl -X POST "https://YOUR-USERNAME-YOUR-SPACE-NAME.hf.space/api/predict" \
  -H "Content-Type: application/json" \
  -d '{"data": ["I love this product!", "positive, negative, neutral", true]}'
```

#### JavaScript/Node.js

```javascript
const response = await fetch("https://YOUR-USERNAME-YOUR-SPACE-NAME.hf.space/api/predict", {
  method: "POST",
  headers: {
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    data: [
      "I love this product!",
      "positive, negative, neutral",
      true
    ]
  })
});

const result = await response.json();
console.log(result);
```

## Response Format

```json
{
  "text": "I absolutely love this product!",
  "prediction": "positive",
  "confidence": "0.9876",
  "all_scores": {
    "positive": "0.9876",
    "neutral": "0.0098",
    "negative": "0.0026"
  },
  "model": "microsoft/deberta-v3-large-mnli"
}
```

## Model Information

- **Model:** microsoft/deberta-v3-large-mnli
- **Architecture:** DeBERTa (Decoding-enhanced BERT with disentangled attention)
- **Task:** Zero-Shot Classification / Natural Language Inference
- **Training Data:** MultiNLI dataset
- **License:** MIT

## Use Cases

- **Sentiment Analysis** - Classify text as positive, negative, or neutral
- **Topic Classification** - Categorize content into custom topics
- **Intent Detection** - Determine user intent in chatbots
- **Content Moderation** - Flag inappropriate content
- **Custom Categories** - Any classification task with your own labels!

## Examples

### Sentiment Analysis
```
Text: "This movie was amazing! I loved every minute."
Labels: positive, negative, neutral
Result: positive (0.9821)
```

### Topic Classification
```
Text: "The new AI model achieves state-of-the-art results."
Labels: technology, politics, sports, entertainment
Result: technology (0.9654)
```

### Intent Detection
```
Text: "I want to cancel my subscription"
Labels: inquiry, complaint, cancellation, purchase
Result: cancellation (0.9432)
```

## Local Development

1. Install dependencies:
```bash
pip install -r requirements.txt
```

2. Run the app:
```bash
python app.py
```

3. Open http://localhost:7860 in your browser

## Deployment on Hugging Face Spaces

See DEPLOYMENT.md for detailed instructions.

## License

MIT License - Feel free to use this in your projects!

---

Built with ❀️ using Hugging Face Transformers and Gradio