Skip to content

rsbryan/ModelScript

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

1 Commit
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ModelScript

An interactive domain-specific language (DSL) for defining, training, and evaluating machine learning models with real neural network capabilities.

πŸš€ What's New - Interactive ML Environment

ModelScript now features a complete interactive development environment with:

  • πŸ”₯ Interactive REPL: Build and test models in real-time
  • 🧠 Neural Network Training: Actual TensorFlow models, not simulations
  • πŸ’¬ Text Classification: Language detection and sentiment analysis
  • πŸ“Š Live Predictions: Interactive prediction with confidence scores
  • 🎯 Multiple Model Types: MNIST, language detection, sentiment analysis

Quick Interactive Demo

./start-repl.sh

modelscript> load language_classifier
modelscript> predict
Enter text to classify> Bonjour comment allez vous
🎯 Prediction: French (87% confidence)

Enter text to classify> Hello how are you today  
🎯 Prediction: English (92% confidence)

πŸ—οΈ Project Structure

ModelScript/
β”œβ”€β”€ modelscript/          # Core language engine
β”œβ”€β”€ examples/             # Model definitions (.ms files)
β”‚   β”œβ”€β”€ language_classifier.ms
β”‚   β”œβ”€β”€ sentiment_classifier.ms
β”‚   └── mnist_classifier.ms
β”œβ”€β”€ data/                 # Training datasets
β”‚   β”œβ”€β”€ language_data.csv
β”‚   └── sentiment_data.csv
β”œβ”€β”€ generated/            # Generated Python code
β”œβ”€β”€ scripts/              # Utility scripts
β”œβ”€β”€ repl.py               # Interactive REPL launcher
└── start-repl.sh         # Easy startup script

πŸš€ Quick Start

1. Setup Environment

# Clone and navigate
git clone https://github.com/rsbryan/modelscript.git
cd modelscript

# Create virtual environment
python3 -m venv venv
source venv/bin/activate  # Windows: venv\Scripts\activate

# Install dependencies
pip install -r modelscript/requirements.txt

2. Launch Interactive REPL

./start-repl.sh

3. Try Interactive Examples

Language Detection:

modelscript> load language_classifier
modelscript> predict
# Test with French, Spanish, or English text!

Sentiment Analysis:

modelscript> load sentiment_classifier
modelscript> predict
# Test with positive or negative text!

View Model Structure:

modelscript> show
modelscript> generate  # See generated Python code

🧠 Interactive Features

Available Commands

Command Description
examples Show available model examples
load <model> Load a model definition
show Display current model structure
predict πŸ”₯ Interactive prediction with neural training
generate Show generated Python code
run Train and execute model
help Show all commands
quit Exit REPL

Model Types

1. Language Classifier (language_classifier)

  • Detects English, French, Spanish
  • Uses LSTM neural network
  • Trained on real multilingual data
  • Interactive text classification

2. Sentiment Analyzer (sentiment_classifier)

  • Positive/negative sentiment detection
  • LSTM-based architecture
  • Real-time confidence scoring
  • Interactive text analysis

3. MNIST Classifier (mnist_classifier)

  • Handwritten digit recognition
  • Dense neural network
  • Standard computer vision benchmark

πŸ’» Traditional Usage (Non-Interactive)

Generate Python Code

python3 modelscript/modelscript.py examples/language_classifier.ms -o my_model.py

Run Model Directly

python3 modelscript/modelscript.py examples/sentiment_classifier.ms --run

πŸ“ ModelScript Syntax

Basic Model Structure

model MyModel {
  dataset {
    source: "language"           // Built-in: "mnist", "language", "sentiment"
    max_sequence_length: 100
    vocab_size: 10000
    num_classes: 3
  }

  architecture {
    layer Embedding {
      input_dim: 10000
      output_dim: 128
      input_length: 100
    }
    
    layer LSTM {
      units: 64
    }
    
    layer Dense {
      units: 3
      activation: "softmax"
    }
  }

  training {
    batch_size: 32
    epochs: 5
    optimizer: "adam"
    loss: "sparse_categorical_crossentropy"
    metrics: ["accuracy"]
  }
}

Supported Datasets

Dataset Description Use Case
"mnist" Handwritten digits Image classification
"language" Multilingual text samples Language detection
"sentiment" Positive/negative text Sentiment analysis
"custom" Your own data Custom classification

Supported Layers

  • Text Processing: Embedding, LSTM, Bidirectional
  • Core Layers: Dense, Dropout, Flatten
  • CNN Layers: Conv2D, MaxPooling2D
  • Activation: "relu", "softmax", "sigmoid"

πŸ”₯ Neural Network Features

Real Training Capabilities

  • Actual TensorFlow Models: Not simulations - real neural networks
  • Live Data Processing: Tokenization, preprocessing, training
  • Model Persistence: Trained models saved for reuse
  • Confidence Scoring: Prediction probabilities
  • Fallback Systems: Rule-based backup if training fails

Training Data

Language Detection (data/language_data.csv):

  • 30 text samples in English, French, Spanish
  • Labeled for supervised learning
  • Preprocessed automatically

Sentiment Analysis (data/sentiment_data.csv):

  • 30 positive and negative text samples
  • Binary classification dataset
  • Real-world sentiment examples

πŸ§ͺ Testing & Validation

Run Integration Test

python3 integration_test.py

Expected output:

πŸš€ ModelScript Integration Test
πŸ“Š Results: 5/5 tests passed
πŸŽ‰ All tests passed! ModelScript upgrade successful!

Manual Testing

# Test basic functionality
python3 test_interactive.py

# Test model parsing
python3 modelscript/modelscript/modelscript.py examples/language_classifier.ms

πŸ› οΈ Development

Adding New Models

  1. Create a .ms file in examples/
  2. Add training data to data/ (if needed)
  3. Test with load <your_model> in REPL

Extending Datasets

Add new dataset support in modelscript/modelscript.py:

  • Update generate_python_code() function
  • Add data loading logic
  • Update REPL prediction methods

🎯 Examples Gallery

Language Detection Example

modelscript> load language_classifier
modelscript> predict

Enter text to classify> Hola como estas
🎯 Prediction: Spanish (78% confidence)

Enter text to classify> Je suis très heureux
🎯 Prediction: French (91% confidence)

Sentiment Analysis Example

modelscript> load sentiment_classifier  
modelscript> predict

Enter text to analyze> This movie is absolutely amazing!
🎯 Prediction: 😊 Positive (94% confidence)

Enter text to analyze> This is the worst experience ever
🎯 Prediction: 😞 Negative (89% confidence)

πŸ“š Advanced Usage

Custom Training Data

Replace data files with your own:

  • data/language_data.csv - For language models
  • data/sentiment_data.csv - For sentiment models

Format: text,label with proper headers

Generated Code Output

View the generated TensorFlow code:

modelscript> generate

This shows the actual Python/TensorFlow code that ModelScript creates from your .ms definition.


πŸ”§ Troubleshooting

Virtual Environment Issues

# Recreate virtual environment
rm -rf venv
python3 -m venv venv
source venv/bin/activate
pip install -r modelscript/requirements.txt

Permission Issues

chmod +x start-repl.sh

Import Errors

Ensure you're in the correct directory and virtual environment is activated.


πŸ“„ License

MIT License - see LICENSE file for details.


πŸš€ What You Built

This is now a complete interactive ML development platform that:

βœ… Parses declarative model definitions
βœ… Generates executable TensorFlow/Keras code
βœ… Trains real neural networks interactively
βœ… Provides live text classification with confidence
βœ… Supports multiple model types and datasets
βœ… Includes comprehensive examples and testing

From simple DSL to production-ready interactive ML environment!

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published