CoolFace
Modelpublic

sanjaydubey733/bert-base-uncased-sentiment-model

sourceHugging Faceupdated 16d agoView on Hugging Face
1likes53downloads
Model Card

BERT Sentiment Classification Model

This model is a fine-tuned version of bert-base-uncased for multi-class sentiment classification of English text, including tweets, customer reviews, comments, and other short text.

Model Details

Model Description

  • Developed by: Sanjay Dubey
  • Model type: BERT-based Transformer Encoder
  • Task: Multi-class sentiment classification
  • Language: English
  • Base model: bert-base-uncased
  • Framework: Hugging Face Transformers
  • Architecture: BERT Encoder with a Sequence Classification Head

Model Architecture

text
Input Text
    ↓
BERT Tokenizer
    ↓
Token IDs + Attention Mask
    ↓
BERT Encoder
    ↓
Classification Head
    ↓
Logits
    ↓
Softmax
    ↓
Sentiment Prediction

The model is based on the BERT-base architecture and uses a sequence classification head to predict sentiment classes.

Intended Use

This model can be used for:

  • Sentiment analysis
  • Twitter/X sentiment classification
  • Customer feedback analysis
  • Product review classification
  • Social media monitoring
  • Text classification
  • Opinion analysis

Direct Use

The model accepts English text as input and predicts a sentiment category.

Example:

text
I absolutely love this product!

The model processes the text using the BERT tokenizer and returns the predicted sentiment label along with a confidence score.

How to Use

Using the Hugging Face Pipeline

python
from transformers import pipeline

MODEL_NAME = "sanjaydubey733/bert-base-uncased-sentiment-model-dubey"

classifier = pipeline(
    "text-classification",
    model=MODEL_NAME,
    tokenizer=MODEL_NAME
)

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

print(result)

Example output:

text
[{'label': 'LABEL_NAME', 'score': 0.98}]

The actual label returned depends on the label mapping defined in the model's config.json.

Loading the Model and Tokenizer Directly

python
from transformers import AutoTokenizer
from transformers import AutoModelForSequenceClassification

MODEL_NAME = "sanjaydubey733/bert-base-uncased-sentiment-model-dubey"

tokenizer = AutoTokenizer.from_pretrained(MODEL_NAME)

model = AutoModelForSequenceClassification.from_pretrained(
    MODEL_NAME
)

text = "I absolutely love this product!"

inputs = tokenizer(
    text,
    return_tensors="pt",
    truncation=True,
    padding=True
)

outputs = model(**inputs)

print(outputs.logits)

Tokenizer

This model uses the tokenizer associated with the fine-tuned BERT model.

The tokenizer files should be included in this repository, such as:

text
tokenizer_config.json
special_tokens_map.json
vocab.txt
tokenizer.json

The tokenizer converts input text into token IDs and creates an attention mask before the data is passed to the BERT model.

Training Details

Base Model

This model was fine-tuned from:

text
bert-base-uncased

BERT is a Transformer encoder model designed to learn contextual representations of text.

Training Task

The model was fine-tuned for multi-class sentiment classification.

During fine-tuning:

text
Training Text
     ↓
BERT Tokenizer
     ↓
BERT Encoder
     ↓
Classification Head
     ↓
Predicted Sentiment
     ↓
Compare with Actual Label
     ↓
Calculate Loss
     ↓
Update Model Parameters

Preprocessing

Input text is processed using the BERT tokenizer.

The tokenizer performs the following operations:

  • Splits text into tokens
  • Converts tokens into token IDs
  • Adds special tokens such as [CLS] and [SEP]
  • Creates an attention mask
  • Truncates text when necessary
  • Pads sequences when necessary

Example:

text
Input:
I love this product!

        ↓

Tokens:
[CLS] I love this product ! [SEP]

        ↓

Token IDs:
[101, ..., 102]

Labels

This is a multi-class sentiment classification model.

The exact mapping between class IDs and sentiment labels is defined in the model's config.json.

Example structure:

text
Class ID
   ↓
0 → Sentiment Class 1
1 → Sentiment Class 2
2 → Sentiment Class 3

Please refer to the id2label and label2id fields in config.json for the exact label mapping.

Evaluation

The model can be evaluated using common classification metrics such as:

  • Accuracy
  • Precision
  • Recall
  • F1 Score
  • Confusion Matrix

For multi-class classification, precision, recall, and F1 score can help evaluate performance across the different sentiment classes.

Limitations

The model may have difficulty with:

  • Sarcasm
  • Irony
  • Ambiguous text
  • Spelling mistakes
  • New or uncommon slang
  • Context-dependent statements
  • Complex or very long text
  • Languages other than English

The model's predictions should be treated as estimates and not as guaranteed facts.

Bias and Risks

The model may inherit biases from the original pretrained model and the data used during fine-tuning.

Performance may vary depending on:

  • Writing style
  • Vocabulary
  • Social media language
  • Domain
  • Type of text
  • Class distribution

Users should test the model on data similar to their intended use case before using it in production.

Recommendations

For production use:

  1. 1.Evaluate the model using a separate test dataset.
  2. 2.Verify the label mapping in config.json.
  3. 3.Use the same tokenizer that was used during training.
  4. 4.Test the model with real-world examples.
  5. 5.Monitor model performance after deployment.
  6. 6.Consider human review for important decisions.

Technical Specifications

Architecture

text
BERT-base-uncased
        ↓
Transformer Encoder
        ↓
Contextual Token Representations
        ↓
Classification Head
        ↓
Logits
        ↓
Softmax
        ↓
Sentiment Probabilities

The model uses the BERT-base architecture, which contains:

  • 12 Transformer encoder layers
  • Hidden size of 768
  • 12 attention heads
  • Approximately 110 million parameters in the base architecture

A sequence classification head is used for the downstream sentiment classification task.

Software

The model was developed using:

  • Python
  • PyTorch
  • Hugging Face Transformers
  • Hugging Face Hub
  • scikit-learn

Deployment

This model can be deployed using:

  • Hugging Face Spaces
  • Gradio
  • Streamlit
  • FastAPI
  • Docker
  • Cloud platforms

A Hugging Face Space can load the model directly from this repository using:

python
MODEL_NAME = "sanjaydubey733/bert-base-uncased-sentiment-model-dubey"

Citation

This model is based on the BERT architecture.

If you use or reference the original BERT architecture, please cite:

bibtex
@inproceedings{devlin2019bert,
  title={BERT: Pre-training of Deep Bidirectional Transformers for Language Understanding},
  author={Devlin, Jacob and Chang, Ming-Wei and Lee, Kenton and Toutanova, Kristina},
  booktitle={Proceedings of the 2019 Conference of the North American Chapter of the Association for Computational Linguistics},
  year={2019}
}

Author

Sanjay Dubey

Model Repository

This model is available on Hugging Face:

sanjaydubey733/bert-base-uncased-sentiment-model-dubey

Contact

For questions, suggestions, or feedback, please use the Discussions section of this Hugging Face model repository.