File size: 2,926 Bytes
59fa95d
 
5291d1e
 
 
 
 
 
59fa95d
5291d1e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
---

license: mit
language: en
tags:
- text-classification
- sentiment-analysis
- scikit-learn
pipeline_tag: text-classification
---


# Sentiment Analysis Model

A simple sentiment analysis model that classifies text as positive, negative, or neutral using TF-IDF vectorization and Multinomial Naive Bayes.

## Model Details

- **Model Type**: Sentiment Classifier
- **Algorithm**: TF-IDF + Multinomial Naive Bayes
- **Classes**: Positive, Negative, Neutral
- **Framework**: Scikit-learn

## Usage

### Using Hugging Face Inference API

```python

import requests



API_URL = "https://api-inference.huggingface.co/models/GunjanSingh/sentiment-analysis-model"

headers = {"Authorization": f"Bearer {YOUR_TOKEN}"}



def query(payload):

    response = requests.post(API_URL, headers=headers, json=payload)

    return response.json()



output = query({

    "inputs": "I love this product!"

})

```

### Using Transformers Pipeline

```python

from transformers import pipeline



classifier = pipeline("text-classification", model="GunjanSingh/sentiment-analysis-model")

result = classifier("I love this product!")

```

### Using Direct API Call

```bash

curl -X POST "https://api-inference.huggingface.co/models/GunjanSingh/sentiment-analysis-model" \

     -H "Authorization: Bearer YOUR_TOKEN" \

     -H "Content-Type: application/json" \

     -d '{"inputs": "I love this product!"}'

```

## Example Output

```json

{

    "text": "I love this product!",

    "prediction": "positive",

    "confidence": 0.85,

    "probabilities": {

        "negative": 0.05,

        "neutral": 0.10,

        "positive": 0.85

    }

}

```

## Training

This model is trained on sample data using:
- TF-IDF vectorization with 1000 features
- English stop words removal
- 1-2 gram combinations
- Multinomial Naive Bayes classifier

## Performance

- **Training Time**: < 1 second
- **Inference Time**: < 10ms per prediction
- **Memory Usage**: ~10MB
- **Accuracy**: ~85% on sample data

## Alternative: Custom Space API

For more advanced features, you can also use the custom Space API:

```python

import requests



# Custom Space API (with more features)

space_url = "https://GunjanSingh-sentiment-analysis-demo.hf.space"



response = requests.post(f"{space_url}/predict", 

                        json={"text": "I love this product!"})

result = response.json()

```

## Model Files

- `model.pkl`: Trained scikit-learn model
- `config.json`: Model configuration
- `model.py`: Inference pipeline
- `requirements.txt`: Dependencies

## Testing

You can test the model locally:

```python

from model import pipeline



# Create pipeline

classifier = pipeline("text-classification")



# Test prediction

result = classifier("I love this product!")

print(result)

```

## License

MIT License - feel free to use this model for your projects!