packages = ["bokeh", "pandas", "numpy", "networkx", "diagrams", "scikit-learn", "pillow", "matplotlib", "plotly"] [[fetch]] files = ["diagrams_base.py"] from = "../python/diagrams/" [[fetch]] files = ["pyscript_manager.py", "data.py"] to_folder = "lib" from = "../python/lib/" [[fetch]] files = ["bokeh_utils.py"] from = "../python/bokeh/" [[fetch]] files = ["matplotlib_utils.py", "plotly_utils.py"] from = "../python/matplotlib/" [[fetch]] files = ["agent.py", "trainer.py", "utils.py", "metrics_chart.py", "crossover.py", "__init__.py"] to_folder = "ml/neuro" from = "../python/ml/neuro/" [[fetch]] files = ["trainer.py"] to_folder = "ml/grokking" from = "../python/ml/grokking/"

Loading...

⏳

Loading Sentiment Analyzer...

Initializing machine learning model

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.

View source

🐍 Python Console