Sentiment Analysis
Analyze the sentiment of any text using machine learning! The model classifies text as Positive, Negative, or Neutral with confidence scores.
Try These Examples:
How it works:
- The model uses TF-IDF (Term Frequency-Inverse Document Frequency) to convert text to numbers
- A Logistic Regression classifier predicts sentiment based on word patterns
- Trained on 45 example sentences (15 positive, 15 negative, 15 neutral)
- Shows confidence scores for all three sentiment categories
- All processing happens in your browser using PyScript!
π‘ Active Learning
After each prediction, you can provide feedback:
- Click YES if correct β Reinforces the model
- Click NO if wrong β Correct it and retrain with the right label
The model learns from your feedback and improves over time!
ποΈ Architecture
This example demonstrates proper separation of concerns:
- Python - Pure ML logic, no HTML. Uses to_js() to convert Python dicts to JavaScript objects before calling window callbacks.
- Controller - Business logic layer. Receives plain JS objects and delegates to UIHandler.
- Svelte UIHandler - Pure UI rendering with reactive state. Updates UI based on plain objects.
Key lesson: Python dicts must be explicitly converted using to_js(dict, dict_converter=Object.fromEntries) to work properly with JavaScript.
π Note
This is a simple demonstration model. For production use, you'd want to train on a much larger dataset (thousands of examples) for better accuracy and generalization.