How to use from the
Use from the
Transformers library
# Use a pipeline as a high-level helper
from transformers import pipeline

pipe = pipeline("text-classification", model="CobuildX-AI/cbx-indim-sentiment-classifier-32M")
# pip install -U transformers accelerate
# Load model directly
from transformers import AutoModel
model = AutoModel.from_pretrained("CobuildX-AI/cbx-indim-sentiment-classifier-32M", device_map="auto")
Quick Links

cbx-indim-sentiment-classifier-32M

A sentiment classifier for 12 Indian languages and English: Hindi, Bengali, Marathi, Tamil, Telugu, Kannada, Malayalam, Gujarati, Punjabi, Odia, Assamese, Urdu and English, in native script, romanized or code-mixed. Give it a comment, review, post or sentence and it returns positive, negative or neutral: the writer's own sentiment. It is InDIM-small (32M) fine-tuned for sentiment, and runs in a few milliseconds on a CPU.

Usage

from cbx_sentiment import SentimentClassifier      # cbx_sentiment.py is in this repository

clf = SentimentClassifier(".")                      # folder with the model files; CPU or GPU
clf.classify("Bahut badhiya phone hai, battery poora din chalti hai.")
# {"label": "positive", "scores": {"positive": 0.97, "negative": 0.02, "neutral": 0.01}, "truncated": False}

python example.py runs six examples; python onnx_example.py runs the same model with ONNX Runtime (onnx/model.onnx, fp32, same decisions as PyTorch on 1,000 of 1,000 test texts).

positive  0.97  Bahut badhiya phone hai, battery poora din chalti hai.
negative  1.00  ডেলিভারি তিন দিন দেরিতে এসেছে, খুবই হতাশ।
neutral   1.00  நாளை காலை பத்து மணிக்கு கூட்டம் தொடங்கும்.
positive  1.00  ಈ ಸಿನಿಮಾ ತುಂಬಾ ಚೆನ್ನಾಗಿದೆ, ಎಲ್ಲರೂ ನೋಡಿ!
negative  1.00  yaar kya bakwaas movie thi, paisa barbaad
negative  0.98  Service was okay but the food was cold and overpriced.

Labels

Label Meaning
positive the writer expresses a favourable opinion or feeling: praise, liking, satisfaction, thanks, good wishes, excitement
negative the writer expresses an unfavourable opinion or feeling: complaint, dislike, anger, sadness, disappointment, criticism, mockery
neutral no opinion or feeling from the writer: facts, news reporting, announcements, questions, requests, instructions, ads without evaluation

Sentiment is the writer's own stance, not the event: news that only reports a crime or good news is neutral. Sarcasm takes its intended meaning, and a text with both polarities gets the one that dominates or is the writer's conclusion, otherwise neutral.

Results

Two test sets labelled by people (not used in training). Every model was fine-tuned with the same recipe and data (plain fine-tuning, learning rate picked on validation); mean of 3 training runs ± SD unless marked.

  • IndicSentiment (AI4Bharat, CC0): 12,946 product reviews in 13 languages, each positive or negative. Scored by comparing the positive and negative scores only (two-way accuracy).
  • Source-labelled test: 8,712 texts with their datasets' own labels: Telugu sentences (6,796), English tweets (870) and romanized Hindi YouTube comments (1,046). Their labelling rules differ from ours, so every model scores near 0.5 macro F1; read it for the order between models.
Model Parameters IndicSentiment accuracy Source-labelled macro F1 English tweets Romanized Hindi Telugu
InDIM-small (this model's base) 32M 0.822 ± 0.016 0.512 ± 0.005 0.640 0.560 0.443
mmBERT-small 140M 0.839 ± 0.004 0.508 ± 0.015 0.706 0.565 0.415
mmBERT-base (1 run) 307M 0.901 0.524 0.716 0.601 0.421
IndicBERT v2 278M 0.944 ± 0.003 0.547 ± 0.002 0.713 0.577 0.475

(The last three columns are macro F1 within each source.)

  • This repository holds the training run with the best validation score: IndicSentiment 0.811, source-labelled 0.518.
  • InDIM-small is level with mmBERT-small at a quarter of its size and better on Telugu; the larger models, especially IndicBERT v2, are clearly better on IndicSentiment. Its weakest languages there are English, Hindi and Urdu.

CPU latency (Intel i7-10700, 8 threads, one text at a time, PyTorch fp32): 5.7 ms for a 15-token sentence, 22.8 ms for a long (about 200-word) input.

Precision: fp16 gives the same labels as fp32 on both test sets. PyTorch dynamic int8 (per-channel) keeps 95–97% of labels unchanged; ONNX int8 changed 4% of decisions in our test, so only the fp32 ONNX file is provided.

Input

  • One comment, review, post or sentence. The model reads at most 256 tokens; longer text is cut ("truncated": True).
  • Native script, romanized and code-mixed text are all supported. The model judges the text alone: it does not see the conversation or the post a comment replies to.
  • If every text you score carries an opinion (for example product reviews with a star rating), compare only the positive and negative scores, as in the IndicSentiment accuracy above.

Limitations

  • Too many opinions are called neutral. On IndicSentiment, where every review is positive or negative, a three-way decision often says neutral. Compare positive and negative only if your texts always carry an opinion.
  • Training labels come from LLMs, following a written guide, not from people; data labelled under different rules (for example, reported news as negative) will score lower.
  • Context: sarcasm, irony, quotes and replies to content the model cannot see are often misread.
  • Bias: errors are not spread evenly across languages, scripts, dialects or topics; political, religious and community-related text may be judged less accurately.

Intended use and disclaimer

Intended use: measuring and routing sentiment in text at scale, for example customer feedback, reviews, support messages and social-media posts, where results are read in aggregate or checked by people. Not intended for decisions about individual people (hiring, credit, moderation penalties, surveillance) without a person reviewing each case. The model makes mistakes, more in some languages than others. It is provided "as is", without warranties of any kind; Cobuild Tech Private Limited is not liable for its use. You are responsible for checking that it suits your data and for complying with the laws that apply to your use.

Training

InDIM-small (32M) fine-tuned on about 63,000 texts in 13 languages (social-media comments, tweets, reviews and web text, about 15% written by LLMs to fill gaps), labelled to the guide above by LLMs (plain fine-tuning, learning rate 4e-4). The source datasets are credited in NOTICE.

Citation

If you use this model, please cite InDIM-small (32M).

Licence

Apache-2.0 (see LICENSE). Dataset credits and licences: see NOTICE.

Questions: hello@cobuildx.ai.

Downloads last month
-
Safetensors
Model size
31.5M params
Tensor type
F32
·
Inference Providers NEW
This model isn't deployed by any Inference Provider. 🙋 Ask for provider support

Model tree for CobuildX-AI/cbx-indim-sentiment-classifier-32M

Quantized
(4)
this model

Collection including CobuildX-AI/cbx-indim-sentiment-classifier-32M