A small Python example for classifying Indonesian text sentiment with a Hugging Face Transformers pipeline.
The script uses mdhugol/indonesia-bert-sentiment-classification, a sentiment classification model fine-tuned from IndoBERT.
python -m venv .venv
source .venv/bin/activate
pip install -r requirements.txtpython app.pyThe first run downloads the model from Hugging Face.
The model returns generic classifier labels, so app.py maps them to readable sentiment labels:
| Model label | Sentiment |
|---|---|
LABEL_0 |
positive |
LABEL_1 |
neutral |
LABEL_2 |
negative |
from app import classify_sentiment
result = classify_sentiment("Pelayanannya sangat baik dan prosesnya cepat.")
print(result)Example output:
{
"text": "Pelayanannya sangat baik dan prosesnya cepat.",
"label": "positive",
"score": 0.99,
}