Downloads · 30 days
7
12% of all-time downloads
whotao1766/bilstm-sentimen-kebijakan-publik
bilstm-sentimen-kebijakan-publik is a text classification model from whotao1766. Use it when you need a label for a piece of text. It is set up for keras.
A Bidirectional LSTM that classifies Indonesian public comments about a government policy (the Kopdes program) into three sentiment classes: Negatif, Netral, and Positif.
Downloads · 30 days
7
12% of all-time downloads
All-time downloads
57
Public
Repo size
4 MB
Likes
0
Public
Click a slice to open those files.
.keras4 MB · 97%
From the Hugging Face model README
A Bidirectional LSTM that classifies Indonesian public comments about a government policy (the Kopdes program) into three sentiment classes: Negatif, Netral, and Positif.
The model is trained from scratch (no pretrained embeddings) on a small dataset, so treat it as a course/research-level baseline rather than a production classifier.
| Architecture | Embedding (128) → Bi-LSTM (64, sequences) → Bi-LSTM (32) → Dropout (0.5) → Dense (64, ReLU) → Dense (3, softmax) |
| Input | Preprocessed text, tokenized and padded to 100 tokens (post-padding, post-truncation) |
| Vocabulary | Top 5,000 words + <OOV> |
| Output | Negatif, Netral, Positif |
| Optimizer / loss | Adam / sparse categorical cross-entropy |
| Training | Batch size 32, up to 30 epochs, early stopping on validation accuracy (patience 8) |
Because of this, the reported scores measure how well the model reproduces the lexicon rule, not how well it matches human judgement of sentiment.
The model expects text processed in exactly this order (the usage example below implements it):
nggak → tidak)tidak, bukan, belum, jangan, tanpaEvaluated on the held-out test set (170 comments).
| Class | Precision | Recall | F1 | Support |
|---|---|---|---|---|
| Negatif | 0.80 | 0.91 | 0.85 | 108 |
| Netral | 0.76 | 0.35 | 0.48 | 37 |
| Positif | 0.58 | 0.72 | 0.64 | 25 |
| Accuracy | 0.76 | 170 | ||
| Macro avg | 0.72 | 0.66 | 0.66 | 170 |
For reference, always predicting the majority class (Negatif) would score about 63.5% accuracy on this test set.
| File | Description |
|---|---|
model_bilstm.keras | Trained Keras model |
tokenizer.json | Keras tokenizer fitted on the training split |
labels.json | Class names in output order |
analisis-sentimen-bilstm.ipynb | Full training notebook |
requirements.txt | Python dependencies |
Install the dependencies:
pip install -r requirements.txt
Load the model, tokenizer, and labels:
import json
from huggingface_hub import hf_hub_download
from tensorflow.keras.models import load_model
from tensorflow.keras.preprocessing.text import tokenizer_from_json
REPO = "whotao1766/bilstm-sentimen-kebijakan-publik"
model = load_model(hf_hub_download(REPO, "model_bilstm.keras"))
with open(hf_hub_download(REPO, "tokenizer.json"), encoding="utf-8") as f:
tokenizer = tokenizer_from_json(f.read())
with open(hf_hub_download(REPO, "labels.json")) as f:
labels = json.load(f)
Preprocess and predict:
import re
import nltk
import pandas as pd
from nltk.corpus import stopwords
from Sastrawi.Stemmer.StemmerFactory import StemmerFactory
from tensorflow.keras.preprocessing.sequence import pad_sequences
nltk.download("stopwords", quiet=True)
stop_words = set(stopwords.words("indonesian")) - {"tidak", "bukan", "belum", "jangan", "tanpa"}
stemmer = StemmerFactory().create_stemmer()
url = ("https://raw.githubusercontent.com/okkyibrohim/"
"id-multi-label-hate-speech-and-abusive-language-detection/master/new_kamusalay.csv")
kamus = pd.read_csv(url, header=None, names=["slang", "formal"], encoding="latin-1").dropna()
kamus = dict(zip(kamus["slang"].str.lower(), kamus["formal"].str.lower()))
kamus["nggak"] = "tidak"
def preprocess(text):
text = re.sub(r"https?://\S+|www\.\S+", " ", text)
text = re.sub(r"@\w+", " ", text)
text = re.sub(r"[^a-zA-Z\s]", " ", text).lower()
text = " ".join(kamus.get(w, w) for w in text.split())
words = [w for w in text.split() if w not in stop_words]
return " ".join(stemmer.stem(w) for w in words)
def predict(texts):
seq = tokenizer.texts_to_sequences([preprocess(t) for t in texts])
padded = pad_sequences(seq, maxlen=100, padding="post", truncating="post")
probs = model.predict(padded, verbose=0)
return [(labels[i], float(p[i])) for i, p in zip(probs.argmax(axis=1), probs)]
print(predict(["Programnya bagus, semoga membantu warga desa"]))