{"id":13526504,"url":"https://github.com/maxjcohen/transformer","last_synced_at":"2025-04-01T07:32:56.640Z","repository":{"id":39376447,"uuid":"223378676","full_name":"maxjcohen/transformer","owner":"maxjcohen","description":"Implementation of Transformer model (originally from Attention is All You Need) applied to Time Series.","archived":false,"fork":false,"pushed_at":"2023-06-02T07:47:50.000Z","size":68330,"stargazers_count":831,"open_issues_count":6,"forks_count":165,"subscribers_count":15,"default_branch":"master","last_synced_at":"2024-08-02T06:21:26.034Z","etag":null,"topics":["metamodel","timeseries","transformer"],"latest_commit_sha":null,"homepage":"https://timeseriestransformer.readthedocs.io/en/latest/","language":"Jupyter Notebook","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/maxjcohen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null}},"created_at":"2019-11-22T10:19:35.000Z","updated_at":"2024-07-20T17:20:29.000Z","dependencies_parsed_at":"2024-01-12T17:44:55.531Z","dependency_job_id":null,"html_url":"https://github.com/maxjcohen/transformer","commit_stats":null,"previous_names":[],"tags_count":4,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxjcohen%2Ftransformer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxjcohen%2Ftransformer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxjcohen%2Ftransformer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/maxjcohen%2Ftransformer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/maxjcohen","download_url":"https://codeload.github.com/maxjcohen/transformer/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":222709759,"owners_count":17026763,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["metamodel","timeseries","transformer"],"created_at":"2024-08-01T06:01:30.729Z","updated_at":"2024-11-02T11:31:19.711Z","avatar_url":"https://github.com/maxjcohen.png","language":"Jupyter Notebook","funding_links":[],"categories":["Code-Resource"],"sub_categories":["2020"],"readme":"# Transformers for Time Series\n\n[![Documentation Status](https://readthedocs.org/projects/timeseriestransformer/badge/?version=latest)](https://timeseriestransformer.readthedocs.io/en/latest/?badge=latest) [![License: GPL v3](https://img.shields.io/badge/License-GPLv3-blue.svg)](https://www.gnu.org/licenses/gpl-3.0) [![Latest release](https://img.shields.io/github/release/maxjcohen/transformer.svg)](https://github.com/maxjcohen/transformer/releases/latest)\n\nImplementation of Transformer model (originally from [Attention is All You Need](https://arxiv.org/abs/1706.03762)) applied to Time Series (Powered by [PyTorch](https://pytorch.org/)).\n\n## Transformer model\n\nTransformer are attention based neural networks designed to solve NLP tasks. Their key features are:\n\n- linear complexity in the dimension of the feature vector ;\n- paralellisation of computing of a sequence, as opposed to sequential computing ;\n- long term memory, as we can look at any input time sequence step directly.\n\nThis repo will focus on their application to times series.\n\n## Dataset and application as metamodel\n\nOur use-case is modeling a numerical simulator for building consumption prediction. To this end, we created a dataset by sampling random inputs (building characteristics and usage, weather, ...) and got simulated outputs. We then convert these variables in time series format, and feed it to the transformer.\n\n## Adaptations for time series\n\nIn order to perform well on time series, a few adjustments had to be made:\n\n- The embedding layer is replaced by a generic linear layer ;\n- Original positional encoding are removed. A \"regular\" version, better matching the input sequence day/night patterns, can be used instead ;\n- A window is applied on the attention map to limit backward attention, and focus on short term patterns.\n\n## Installation\n\nAll required packages can be found in `requirements.txt`, and expect to be run with `python3.7`. Note that you may have to install pytorch manually if you are not using pip with a Debian distribution : head on to [PyTorch installation page](https://pytorch.org/get-started/locally/). Here are a few lines to get started with pip and virtualenv:\n\n```bash\n$ apt-get install python3.7\n$ pip3 install --upgrade --user pip virtualenv\n$ virtualenv -p python3.7 .env\n$ . .env/bin/activate\n(.env) $ pip install -r requirements.txt\n```\n\n## Usage\n\n### Downloading the dataset\n\nThe dataset is not included in this repo, and must be downloaded manually. It is comprised of two files, `dataset.npz` contains all input and outputs value, `labels.json` is a detailed list of the variables. Please refer to [#2](https://github.com/maxjcohen/transformer/issues/2) for more information.\n\n### Running training script\n\nUsing jupyter, run the default `training.ipynb` notebook. All adjustable parameters can be found in the second cell. Careful with the `BATCH_SIZE`, as we are using it to parallelize head and time chunk calculations.\n\n### Outside usage\n\nThe `Transformer` class can be used out of the box, see the [docs](https://timeseriestransformer.readthedocs.io/en/latest/?badge=latest) for more info.\n\n```python\nfrom tst import Transformer\n\nnet = Transformer(d_input, d_model, d_output, q, v, h, N, TIME_CHUNK, pe)\n```\n\n### Building the docs\n\nTo build the doc:\n\n```bash\n(.env) $ cd docs \u0026\u0026 make html\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxjcohen%2Ftransformer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmaxjcohen%2Ftransformer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmaxjcohen%2Ftransformer/lists"}