GithubHelp home page GithubHelp logo

demandforecastingtft's Introduction

Demand forecasting with Temporal Fusion Transformers


This repository contains a custom implementation of Temporal Fusion Transformers for Interpretable Multi-horizon Time Series Forecasting using Lightning and pytorch_forecasting for demand forecasting on the Stallion dataset.

Technical details

Enhancements compared to the original implementation in the Google Research repo:

  • capabilities added through pytorch_forecasting base model e.g. monotone constraints
  • static variables can be continuous
  • multiple categorical variables can be summarized with an EmbeddingBag
  • variable encoder and decoder length by sample
  • categorical embeddings are not transformed by variable selection network (because it is a redundant operation)
  • variable dimension in variable selection network are scaled up via linear interpolation to reduce number of parameters
  • non-linear variable processing in variable selection network can be shared among decoder and encoder (not shared by default)

Run locally

The dependency management system is poetry. Install poetry and run:

poetry install

to set up the environment.

Training

You can get the baseline performance in the dataset by training pytorch_forecasting's Baseline model:

cd src
poetry run python baseline.py

To train the full model and get the performance:

poetry run python train.py
poetry run python evaluate.py

Prediction & Inference

To run prediction on test data in the model, run:

poetry run python predict.py

To inference the model through an API, the api.py file sets up a simple Flask API with a '/predictions' GET endpoint.

poetry run python api.py

then you can access localhost:8501/docs to see a nice UI set up by FastAPI that allows easy inference, or use curl or any other tools to call the API directly.

References

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.