Downloads · 30 days
0
Akansha9821RPPS/basic-sentiment-model
basic-sentiment-model is a machine learning model from Akansha9821RPPS. Use it for the machine learning task on the model card, and read the license before you ship it in a product. The card lists the license as apache-2.0.
Downloads · 30 days
0
Access
Public
Updated Aug 11, 2026
Repo size
2.2 KB
Likes
0
Public
Click a slice to open those files.
.md8.4 KB · 70%
From the Hugging Face model README
library_name: scikit-learn tags:
A simple Sentiment Analysis machine learning model built using TF-IDF (Term Frequency-Inverse Document Frequency) and Logistic Regression.
The model classifies text into two sentiment categories:
This project is designed as a basic example for understanding the complete machine learning model lifecycle:
Dataset
↓
Text Preprocessing
↓
TF-IDF Vectorization
↓
Logistic Regression
↓
Model Evaluation
↓
Model Serialization
↓
Hugging Face Hub
↓
Inference
| Property | Description |
|---|---|
| Model Type | Text Classification |
| Task | Sentiment Analysis |
| Algorithm | Logistic Regression |
| Feature Extraction | TF-IDF |
| Library | Scikit-learn |
| Language | Python |
| Classes | Positive / Negative |
| Model Format | Pickle (.pkl) |
The model consists of two primary components:
The input text is converted into numerical features using TF-IDF.
Input Text
↓
TF-IDF Vectorizer
↓
Numerical Feature Vector
The numerical feature vector is passed to the Logistic Regression classifier.
TF-IDF Features
↓
Logistic Regression
↓
Sentiment Prediction
Complete pipeline:
Text
↓
Lowercase Conversion
↓
Tokenization
↓
Stop Word Removal
↓
TF-IDF
↓
Logistic Regression
↓
Prediction
The model uses the following labels:
| Label | Sentiment |
|---|---|
0 | Negative |
1 | Positive |
Example:
Input:
"I love this product"
Output:
1 → Positive
Another example:
Input:
"This product is terrible"
Output:
0 → Negative
Clone or download the project.
Install the required Python libraries:
pip install -r requirements.txt
Required packages:
scikit-learn
pandas
joblib
huggingface_hub
Run the training script:
python train.py
The training process performs the following steps:
1. Load training data
2. Split data into training and testing sets
3. Create TF-IDF vectorizer
4. Transform text into numerical features
5. Train Logistic Regression
6. Evaluate model
7. Save trained model
The trained model will be saved as:
model/sentiment_model.pkl
After training the model, run:
python predict.py
Example input:
I really love this product
Example output:
Prediction: positive
Confidence: 0.72
Another example:
This product is terrible
Output:
Prediction: negative
Confidence: 0.69
The saved model can be loaded using joblib.
import joblib
model = joblib.load(
"model/sentiment_model.pkl"
)
text = [
"I love this product"
]
prediction = model.predict(text)
if prediction[0] == 1:
print("Positive")
else:
print("Negative")
The model can also return prediction probabilities.
import joblib
model = joblib.load(
"model/sentiment_model.pkl"
)
text = [
"This is an amazing product"
]
prediction = model.predict(text)
probability = model.predict_proba(text)
label = "Positive" if prediction[0] == 1 else "Negative"
confidence = max(probability[0])
print("Sentiment:", label)
print("Confidence:", round(confidence, 4))
Install the Hugging Face Hub library:
pip install huggingface_hub
Download the model:
from huggingface_hub import hf_hub_download
import joblib
model_path = hf_hub_download(
repo_id="YOUR_USERNAME/basic-sentiment-model",
filename="sentiment_model.pkl"
)
model = joblib.load(model_path)
text = [
"This product is fantastic"
]
prediction = model.predict(text)
print(prediction)
Replace:
YOUR_USERNAME
with your Hugging Face username.
| Input | Prediction |
|---|---|
| I love this product | Positive |
| This product is excellent | Positive |
| Amazing experience | Positive |
| Very good service | Positive |
| I am very happy | Positive |
| I hate this product | Negative |
| This product is terrible | Negative |
| Very bad experience | Negative |
| Worst service | Negative |
| I am very disappointed | Negative |
basic-sentiment-model/
│
├── model/
│ └── sentiment_model.pkl
│
├── train.py
├── predict.py
├── upload.py
├── requirements.txt
├── README.md
└── .gitignore
The current model uses a small demonstration dataset containing positive and negative sentences.
Example positive samples:
I love this product
This product is excellent
Amazing experience
Very good service
I am very happy
Example negative samples:
I hate this product
This product is terrible
Very bad experience
Worst service
I am very disappointed
The dataset is intentionally small because this project is designed as an educational demonstration of model training and Hugging Face deployment.
The model is evaluated using classification accuracy.
from sklearn.metrics import accuracy_score
accuracy = accuracy_score(
y_test,
predictions
)
print("Accuracy:", accuracy)
Because the demonstration dataset is very small, the reported accuracy should not be interpreted as a measure of real-world performance.
This model has several limitations:
For production use, a significantly larger and more representative dataset should be used.
The model can be improved by:
Use a larger sentiment dataset containing thousands or millions of examples.
Experiment with:
TF-IDF
N-grams
Word Embeddings
Sentence Embeddings
Compare:
Logistic Regression
Naive Bayes
SVM
Random Forest
Gradient Boosting
The project can later be upgraded to:
Neural Network
↓
LSTM
↓
GRU
↓
Transformer
↓
BERT
A future version can use a pretrained Transformer model for improved NLP performance.
The trained model can be uploaded to the Hugging Face Hub.
Example:
hf auth login
Then:
hf upload YOUR_USERNAME/basic-sentiment-model ./model .
The model will be available at:
YOUR_USERNAME/basic-sentiment-model
This model is intended for:
This project is provided for educational and experimental purposes.
If you reuse or modify this project, add an appropriate license according to your intended use.
Basic Sentiment Analysis Model
Built with:
Python
Scikit-learn
TF-IDF
Logistic Regression
Hugging Face Hub
This project uses the open-source Python machine learning ecosystem, particularly: