How rupak-raut/nepse-lstm-gru works
1. Repository purpose
- This is a stock-prediction application for NEPSE securities, centered on pre-trained sequence models rather than live model training.
2. Runtime shape
- The repo appears to be a small, self-contained Python application with one backend entrypoint: nepse/app.py.
- There is no visible service decomposition; the likely architecture is a single-process server plus a static HTML frontend.
3. User interface layer
- nepse/frontend.html is the client-facing page.
- It likely provides the stock selection and displays prediction output, while delegating prediction requests to the Python backend over HTTP.
4. Backend / API layer
- app.py is the orchestration point.
- Its responsibilities are likely:
- load the requested stock’s model and scaler,
- accept input from the UI,
- run inference,
- return the predicted result to the frontend.
5. Model inference subsystem
- nepse/trained_models/ contains one model bundle per stock symbol.
- Each stock has two artifacts:
- *_model_state_dict.pth for the trained neural network weights,
- *_scaler.pkl for feature normalization / inverse transformation.
- This strongly suggests the prediction pipeline is stock-specific and depends on matching the correct scaler with the correct model.
6. Model portfolio
- The included symbols show the app supports multiple NEPSE instruments, including banks, insurers, and other listed companies such as ADBL, NABIL, NLIC, SCB, SBL, NTC, and others.
- Architecture-wise, this is not a single generic model; it is a collection of separate per-ticker models.
7. Data dependency
- nepse/NEPSE_STOCKS_DATASETS.csv is the primary dataset artifact in the repo.
- It is likely used for historical training, preprocessing, or validation, and not necessarily loaded at runtime except for analytics or feature preparation.
8. Offline training vs. online prediction boundary
- The presence of the CSV plus many persisted model/scaler files indicates a clear split:
- offline: data preparation and model training,
- online: loading saved artifacts and generating predictions.
- The runtime app depends on these precomputed artifacts and does not need to retrain models on each request.
9. ML framework boundary
- The .pth files indicate PyTorch-based model storage.
- The .pkl scalers suggest scikit-learn or compatible preprocessing objects.
- In the architecture diagram, this is the core ML stack boundary between raw market data and predicted output.
10. Packaging / distribution
- nepse/trained_models.zip is a bundled copy of the model artifacts, likely for easier distribution or deployment.
- The repo already contains the extracted trained_models/ directory, so deployment can use either the archive or the expanded folder.
11. Dependencies
- requirements.txt defines the Python runtime dependencies needed by the app and model inference pipeline.
- Those dependencies likely include the web framework and ML libraries required to deserialize scalers and run the neural network models.
12. What is missing from the repo
- There is no separate database, message queue, or external API integration visible in the tree.
- The architecture therefore looks local-file driven: static frontend + Python backend + model artifacts on disk.
13. Diagram-ready summary
- A useful architecture diagram would show:
- browser/user -> frontend.html,
- frontend -> app.py,
- app.py -> stock-specific model/scaler files in trained_models/,
- optional offline arrow from NEPSE_STOCKS_DATASETS.csv to the model-training step that produced those artifacts.
14. Primary architectural characteristic
- The key design choice is per-stock persisted ML inference inside a lightweight Python web app, with all prediction intelligence stored as local artifacts rather than in an external service.
Main entry points: app.py App · frontend.html Frontend · trained_models Trained Models · trained_models.zip Model Bundle
Components 12
Interface
Client-facing presentation layer
- User · Person using the prediction interface
- Frontend · Static page for symbol selection and prediction display
nepse/frontend.html
Backend
Single-process Python server and request handling
- App · Backend entrypoint that orchestrates prediction requests
nepse/app.py - Request API · HTTP boundary between the page and the Python backend
- Input Prep · Turns UI input into model-ready features
- Model Loader · Selects the correct stock model and scaler bundle
- Inference · Runs the stored sequence model and returns the forecast
Artifacts
Persisted ML bundles used for inference
- Trained Models · Per-ticker PyTorch weights plus matching scalers
nepse/trained_models - Model Bundle · Packaged copy of the trained model artifacts
nepse/trained_models.zip - Ticker Bundles · Individual model/scaler pairs for symbols such as ADBL, NABIL, NLIC, SCB, SBL, NTC, and others
Data
Historical market data and packaging
- Market Data · Historical NEPSE dataset used for training and preparation
nepse/NEPSE_STOCKS_DATASETS.csv - Dependencies · Runtime and ML library requirements
nepse/requirements.txt
Connections 13
- User → Frontend: uses · User interacts with the stock prediction page
- Frontend → Request API: requests · Page sends prediction requests to the backend
- Request API → App: handled by · HTTP requests are served by the Python application
- App → Input Prep: prepares · Backend shapes submitted inputs for inference
- Input Prep → Model Loader: selects · Prepared inputs determine which stock bundle to load
- Model Loader → Trained Models: loads · Model and scaler artifacts are read from disk
- Trained Models → Ticker Bundles: contains · Repository stores one bundle per supported ticker
- Model Loader → Inference: supplies · Loaded artifacts are passed into the prediction path
- Inference → App: returns · Predicted output is sent back to the application layer
- App → Frontend: responds · Backend returns prediction results for display
- Market Data → Ticker Bundles: feeds offline · Historical data is the source for training the persisted bundles
- Model Bundle → Trained Models: packages · Archive mirrors the extracted trained model directory
- Dependencies → App: supports · Dependencies enable the server and ML runtime