Spaces:
Sleeping
Sleeping
Commit ·
79e7953
1
Parent(s): 0c0e4d5
Improve IndoHoaxDetector Space docs, UI, and evaluation
Browse files- README.md +71 -0
- app.py +10 -7
- evaluation.md +26 -0
- modelcard.md +53 -0
README.md
CHANGED
|
@@ -9,6 +9,77 @@ app_file: app.py
|
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
| 11 |
short_description: Indonesian News Detector
|
|
|
|
| 12 |
---
|
| 13 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 14 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
|
|
|
| 9 |
pinned: false
|
| 10 |
license: mit
|
| 11 |
short_description: Indonesian News Detector
|
| 12 |
+
tags: ["nlp", "text-classification", "indonesian", "hoax-detection", "fact-checking", "logistic-regression"]
|
| 13 |
---
|
| 14 |
|
| 15 |
+
# IndoHoaxDetector Space
|
| 16 |
+
|
| 17 |
+
IndoHoaxDetector is a Gradio space that analyzes the writing style of Indonesian news articles to identify hoax-like storytelling patterns. It is _not_ a fact checker; instead, it highlights sensational language, over-promising claims, and other linguistic features that frequently appear in hoaxes.
|
| 18 |
+
|
| 19 |
+
## Features
|
| 20 |
+
|
| 21 |
+
- **Stylistic Hoax Detection**: Predicts whether a news article is written like a hoax (sensational, emotionally charged, or structurally suspicious) using logistic regression over TF-IDF features.
|
| 22 |
+
- **Interactive Web UI**: Enter article text directly, preview predictions with confidence scores, and understand whether the writing style matches known hoax patterns.
|
| 23 |
+
- **Production-Ready Preprocessing**: Cleans text, removes URLs/symbols, stems using Sastrawi, and excludes Indonesian stop words before vectorization.
|
| 24 |
+
- **Model + Vectorizer File**: The space loads both the `logreg_model.pkl` and `tfidf_vectorizer.pkl` to ensure deterministic inference.
|
| 25 |
+
|
| 26 |
+
## Usage
|
| 27 |
+
|
| 28 |
+
### Web Interface
|
| 29 |
+
1. Enter the Indonesian news text (title, body, or snippet) you want to analyze.
|
| 30 |
+
2. The space returns two probabilities labeled `FAKTA` and `HOAX`, showing how confidently the model thinks the writing resembles each class.
|
| 31 |
+
3. Use the confidence scores as a writing-style signal; always verify facts with external sources before action.
|
| 32 |
+
|
| 33 |
+
### Local Usage
|
| 34 |
+
|
| 35 |
+
```bash
|
| 36 |
+
pip install -r requirements.txt
|
| 37 |
+
python app.py
|
| 38 |
+
```
|
| 39 |
+
|
| 40 |
+
### Programmatic API
|
| 41 |
+
|
| 42 |
+
The underlying inference function is `predict_news`. You can import it like this:
|
| 43 |
+
|
| 44 |
+
```python
|
| 45 |
+
from app import predict_news
|
| 46 |
+
|
| 47 |
+
result = predict_news("Isi berita Indonesia di sini")
|
| 48 |
+
print(result) # {'FAKTA': 0.32, 'HOAX': 0.68}
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
> **Tip**: The predictions reflect style, not truthfulness. A legitimate article with dramatic phrasing may show elevated HOAX probability.
|
| 52 |
+
|
| 53 |
+
## Preprocessing
|
| 54 |
+
|
| 55 |
+
- Casefolding + URL stripping
|
| 56 |
+
- Non-letter removal
|
| 57 |
+
- Indonesian stop word trimming
|
| 58 |
+
- Sastrawi stemming
|
| 59 |
+
- TF-IDF vectorization using the shipped `tfidf_vectorizer.pkl`
|
| 60 |
+
|
| 61 |
+
Ensure your custom text is preprocessed identically for consistent results.
|
| 62 |
+
|
| 63 |
+
## Evaluation
|
| 64 |
+
|
| 65 |
+
- **Model**: Logistic Regression (scikit-learn)
|
| 66 |
+
- **Accuracy**: ~97.83% on the internal validation set used during training
|
| 67 |
+
- **Metric focus**: Accuracy reflects how often the model matches the hoax vs legitimate labels provided during training; it does _not_ measure truthfulness.
|
| 68 |
+
- **Additional metrics**: Precision and recall support the labeled stylistic vocabulary distinctions. Confusion matrix is saved internally.
|
| 69 |
+
- **Limitation**: Performance depends on text quality, novelty of topics, and writing style variations.
|
| 70 |
+
|
| 71 |
+
## Limitations
|
| 72 |
+
|
| 73 |
+
- Detects hoax **style** only and cannot confirm if reported claims are factually true or false.
|
| 74 |
+
- Trained on Indonesian political news; other genres may degrade accuracy.
|
| 75 |
+
- Not suitable for legal or journalistic conclusions without human review.
|
| 76 |
+
|
| 77 |
+
## Contribution
|
| 78 |
+
|
| 79 |
+
Want to improve the tokenizer, add new examples, or migrate to another model? Fork the repo, open a draft PR, and document your changes.
|
| 80 |
+
|
| 81 |
+
## License
|
| 82 |
+
|
| 83 |
+
MIT License — see the LICENSE file for full text.
|
| 84 |
+
|
| 85 |
Check out the configuration reference at https://huggingface.co/docs/hub/spaces-config-reference
|
app.py
CHANGED
|
@@ -71,26 +71,29 @@ def predict_news(text):
|
|
| 71 |
# --- 5. Create and Launch the Gradio Interface ---
|
| 72 |
title = "Detektor Berita Hoax Indonesia"
|
| 73 |
description = """
|
| 74 |
-
|
| 75 |
-
|
| 76 |
-
|
| 77 |
"""
|
| 78 |
demo = gr.Interface(
|
| 79 |
fn=predict_news,
|
| 80 |
inputs=gr.Textbox(
|
| 81 |
-
lines=10,
|
| 82 |
-
placeholder="Masukkan teks berita (judul dan isi) untuk dianalisis...",
|
| 83 |
label="Teks Berita"
|
| 84 |
),
|
| 85 |
outputs=gr.Label(
|
| 86 |
-
num_top_classes=2,
|
| 87 |
label="Prediksi"
|
| 88 |
),
|
| 89 |
title=title,
|
| 90 |
description=description,
|
| 91 |
examples=[
|
| 92 |
["Presiden umumkan libur panjang baru untuk seluruh warga"],
|
| 93 |
-
["Beredar foto ular raksasa di Kalimantan hasil editan"]
|
|
|
|
|
|
|
|
|
|
| 94 |
]
|
| 95 |
)
|
| 96 |
|
|
|
|
| 71 |
# --- 5. Create and Launch the Gradio Interface ---
|
| 72 |
title = "Detektor Berita Hoax Indonesia"
|
| 73 |
description = """
|
| 74 |
+
Detektor ini melihat gaya penulisan dan struktur teks untuk menilai apakah artikel
|
| 75 |
+
bernada hoax atau legit. Hasilnya menganalisis pola linguistik, bukan memeriksa fakta.
|
| 76 |
+
Masukkan teks berita dalam Bahasa Indonesia untuk mendapatkan probabilitas HOAX vs FAKTA.
|
| 77 |
"""
|
| 78 |
demo = gr.Interface(
|
| 79 |
fn=predict_news,
|
| 80 |
inputs=gr.Textbox(
|
| 81 |
+
lines=10,
|
| 82 |
+
placeholder="Masukkan teks berita (judul dan isi) untuk dianalisis...",
|
| 83 |
label="Teks Berita"
|
| 84 |
),
|
| 85 |
outputs=gr.Label(
|
| 86 |
+
num_top_classes=2,
|
| 87 |
label="Prediksi"
|
| 88 |
),
|
| 89 |
title=title,
|
| 90 |
description=description,
|
| 91 |
examples=[
|
| 92 |
["Presiden umumkan libur panjang baru untuk seluruh warga"],
|
| 93 |
+
["Beredar foto ular raksasa di Kalimantan hasil editan"],
|
| 94 |
+
["Peneliti temukan vaksin alami yang menyembuhkan kanker dalam 3 hari"],
|
| 95 |
+
["Bank Indonesia mempertahankan suku bunga stabil bulan ini"],
|
| 96 |
+
["Kabar viral: rasi bintang terbaru bisa mengendalikan hujan"]
|
| 97 |
]
|
| 98 |
)
|
| 99 |
|
evaluation.md
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Evaluation Summary for IndoHoaxDetector Space
|
| 2 |
+
|
| 3 |
+
## Metrics Overview
|
| 4 |
+
|
| 5 |
+
- **Model Architecture**: Logistic Regression trained on Indonesian news labeled as HOAX vs FAKTA.
|
| 6 |
+
- **Vectorizer**: TF-IDF transform created with `tfidf_vectorizer.pkl` after applying Indonesian-specific preprocessing.
|
| 7 |
+
- **Accuracy**: ~97.83% on the held-out validation split used during training (metadata stored in `model_metadata.txt`).
|
| 8 |
+
- **Precision & Recall**: Balanced on the styled labels. Precision indicates how often the model flags hoax-style text correctly; recall shows how many hoax-like examples are captured.
|
| 9 |
+
- **Confidence Scores**: The Gradio app exposes probability values for both labels. Use the HOAX probability as a stylistic warning, not a verdict.
|
| 10 |
+
|
| 11 |
+
## Testing Guidelines
|
| 12 |
+
|
| 13 |
+
1. Prepare a set of Indonesian news snippets (title + body) with known labels.
|
| 14 |
+
2. Run the preprocessing steps defined in `app.py` (lowercasing, URL stripping, non-letter removal, stop word removal, Sastrawi stemming, TF-IDF transform).
|
| 15 |
+
3. Use the loaded model to infer probabilities via `predict_news`.
|
| 16 |
+
4. Compare predictions with labels and compute metrics with any evaluation script (e.g., run the repository-level `evaluate.py` if you copy it inside this folder).
|
| 17 |
+
|
| 18 |
+
## Reporting
|
| 19 |
+
|
| 20 |
+
- Document any changes to the dataset or vectorizer.
|
| 21 |
+
- If you retrain the model, update this file with the new accuracy, precision, recall, and dataset description to keep the Space trustworthy.
|
| 22 |
+
|
| 23 |
+
## Caveats
|
| 24 |
+
|
| 25 |
+
- Metrics refer only to stylistic label consistency, not factual verification.
|
| 26 |
+
- The evaluation set may not include every possible writing style; monitor drift over time and retrain as needed.
|
modelcard.md
ADDED
|
@@ -0,0 +1,53 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Model Card for IndoHoaxDetector Space
|
| 2 |
+
|
| 3 |
+
## Model Details
|
| 4 |
+
|
| 5 |
+
### Purpose
|
| 6 |
+
IndoHoaxDetector flags Indonesian news that are written in a hoax-like style. It measures sensational tone, repetition, and other stylistic cues instead of verifying factual claims.
|
| 7 |
+
|
| 8 |
+
### Model Type
|
| 9 |
+
- **Architecture**: Logistic Regression (scikit-learn)
|
| 10 |
+
- **Features**: TF-IDF vectors over Indonesian text after token cleanup, stop-word removal, and Sastrawi stemming
|
| 11 |
+
- **Language**: Bahasa Indonesia
|
| 12 |
+
|
| 13 |
+
### Training Data
|
| 14 |
+
- **Source**: Indonesian political news dataset labeled as Hoax or Fakta
|
| 15 |
+
- **Balance**: Approximately equal representation of each class
|
| 16 |
+
- **Preprocessing**: Lowercasing, URL removal, punctuation stripping, stop-word filtering (nltk stopwords indonesian), and stemming via Sastrawi
|
| 17 |
+
- **Vectorizer**: TF-IDF (stored in `tfidf_vectorizer.pkl`)
|
| 18 |
+
|
| 19 |
+
### Evaluation Results
|
| 20 |
+
- **Accuracy**: 97.83% on the held-out validation set
|
| 21 |
+
- **Confusion Matrix (approximate)**:
|
| 22 |
+
- True Legitimate vs False Hoax
|
| 23 |
+
- False Legitimate vs True Hoax
|
| 24 |
+
- **Evaluation focus**: Predictive alignment with human-labeled writing style, not factual verification
|
| 25 |
+
|
| 26 |
+
## Usage
|
| 27 |
+
|
| 28 |
+
### Web Space
|
| 29 |
+
- Load the Gradio interface (`app.py`)
|
| 30 |
+
- Paste Indonesian news text (title, body, or excerpt)
|
| 31 |
+
- Review two probability scores labeled FAKTA and HOAX
|
| 32 |
+
- Use the HOAX score purely as a stylistic alert; verify any concerning news through reliable fact-checkers
|
| 33 |
+
|
| 34 |
+
### Programmatic
|
| 35 |
+
```python
|
| 36 |
+
from app import predict_news
|
| 37 |
+
|
| 38 |
+
result = predict_news("Contoh berita Indonesia")
|
| 39 |
+
print(result) # {'FAKTA': 0.26, 'HOAX': 0.74}
|
| 40 |
+
```
|
| 41 |
+
|
| 42 |
+
### Limitations
|
| 43 |
+
- **Stylistic detection only** – legitimate but dramatic news may still look like hoax; factual hoaxes written professionally may slip through.
|
| 44 |
+
- **Data bias** – trained on political news; other domains (health, entertainment) may degrade performance.
|
| 45 |
+
- **Temporal drift** – writing styles evolve, so retraining is needed for new eras.
|
| 46 |
+
|
| 47 |
+
## Ethical Considerations
|
| 48 |
+
- Use results as a signal, not a verdict. Always pair the space output with human judgment.
|
| 49 |
+
- Avoid automatic blocking or censorship based solely on these predictions.
|
| 50 |
+
- Be transparent that the model does not verify truthfulness.
|
| 51 |
+
|
| 52 |
+
## Model Card Author
|
| 53 |
+
Gareth Aurelius Harrison
|