LSTM Text Generator
A web application for text generation using LSTM neural networks, built with Svelte 5 and TensorFlow.js.
Features
- š§ Train LSTM model on custom text input
- ⨠Generate text based on trained model
- š GPU acceleration support (WebGL) for faster training
- š» Simple and responsive user interface
- š Real-time training progress display
Technologies
- Svelte 5 - Reactive framework
- TypeScript - Type safety
- TensorFlow.js - Machine learning in the browser
- Vite - Fast build tool and dev server
Installation
# Install dependencies
npm install
# Run development server
npm run dev
# Build for production
npm run build
# Preview production build
npm run preview
Usage
- Enter your training text in the "Training Data" section (minimum 10 characters)
- Click "Train Model" and wait for training to complete
- Enter a seed text in the "Prediction" section
- Click "Generate Text" to generate new text
Project Structure
src/
āāā lib/
ā āāā modelService.ts # Training and generation logic
ā āāā modelUtils.ts # Utility functions
ā āāā tfConfig.ts # TensorFlow configuration
ā āāā TrainingSection.svelte
ā āāā PredictionSection.svelte
ā āāā OutputDisplay.svelte
āāā App.svelte # Main component
āāā main.ts # Entry point
Notes
- For better results, use longer training texts (multiple paragraphs)
- The model uses two LSTM layers with dropout to prevent overfitting
- GPU acceleration is automatically used if available