Giter Club home page Giter Club logo

typhoon's Introduction

Typhoon

Transformer based neural network model for time series tasks.

Structure

.
├── Dockerfile
├── LICENSE
├── Pipfile
├── Pipfile.lock
├── README.md
├── docker-compose.yml
│
├── Typhoon
│   ├── __init__.py
│   ├── core
│   │   ├── __init__.py
│   │   ├── model.py
│   │   └── modules.py
│   │
│   └── utils
│       ├── __init__.py
│       ├── dataset.py
│       ├── functions.py
│       └── trainer.py
│
└── experiments
    ├── README.md
    ├── check.py
    ├── train_har.py
    └── train_mhealth.py

  • utils/ ... This directory contain training script and sub functions.

System Requirements

  • OS: Unix-like

    • macOS Mojave 10.14.6
    • Debian 9.9 (GCP Deep Learning Image: PyTorch 1.1.0 and fastai m32)
    • Ubuntu 16.04 or Ubuntu 18.04
  • Python 3.5 or later

  • PyTorch 1.1.0

  • (optional) NVIDIA GPU

References

typhoon's People

Contributors

khirotaka avatar

Stargazers

 avatar

Watchers

James Cloos avatar  avatar

typhoon's Issues

Google Analytics予測

公開されているGAのデータを使ってなんらかの予測。

TransformerのEncoder-Docoderモデルがいいのか、Encoderで特徴抽出して、全結合層で数ステップ先を予測する方がいいのか…

部分時系列によるEmbedding

[batch, seq_len, features]で構成されるデータから一定ウィンドウで部分データを抽出、そこからnn.Linear に与えてベクトルを生成する。

for epoch in range(num_epochs):
    for data, target in data_loader:
        # data.shape == [batch, seq_len, features]
        sub_data = data[:, window_start:window_end, :]
        
        out = nn.Linear(sub_data) # [batch, sub_seq_len, emb_dim, features]

異常検知アイデア

Encoder-Decoderモデルで学習させ、Encoder or DecoderのAttention Weightを元に比較する案

Network構造についてのアイディア

前提

入力が [batch, seq_len, features] として features が複数。つまりセンサーがたくさんあるとする。

Input Embedding

各 feature 毎に Embedding(みたいなもの)を行う。
具体的には、値を nn.Linear() に通してベクトルにする。

X, y = next(iter(train_loader))

X.shape # [batch, seq_len, features]

emb1 = nn.Linear(input_size, output_size)
emb2 = nn.Linear(input_size, output_size)
emb3 = nn.Linear(input_size, output_size)

...

embed_1 = [emb1(X[:, i, 0]) for i in range(X.shape[1])] # [batch, seq_len, output_size]
embed_2 = [emb2(X[:, i, 1]) for i in range(X.shape[1])]
embed_3 = [emb3(X[:, i, 2]) for i in range(X.shape[1])]
...

embed = torch.cat([embed_1, embed_2, ... ]) # [batch, seq_len, output_size, features]

作成した embed に Positional Encoding を行う。

PE = positional_encording()
input_tensor = embed + PE

各featureを別々に MultiHeadAttention に与える。

class Typhoon(nn.Module):
    def __init__(self):
        super(Typhoon, self).__init__()
        self.attentions = nn.ModuleList([
            MultiHeadAttentionANDFeedForward, 
            MultiHeadAttentionANDFeedForward,
            MultiHeadAttentionANDFeedForward,
            ...
        ])
        self.selector = MultiHeadAttention() # or Attention
        self.classification = ClassificationModule()
    
    def forward(self, x):
        output = self.attentio(x)
        output = torch.cat( ... ) # con cat したり色々
        output = self.selector(output)
        output = self.classification(output)
        return output

流れは、

  1. センサーの次元毎に MultiHeadAttention を行う
  2. 1 を複数回行う。
  3. どのセンサーの情報に注目すべきかを指定するために、2 の出力にSelf-Attention or MultiHeadAttention を行う。
  4. 3 の結果を元に分類を行う。

Note,
MultiHeadAttention はHeadをたくさん切れば長期間の依存性を学習しやすくなるはずなので、ハイパーパラメータは

  • input embedding の次元数
  • MultiHeadAttention の頭の数

が重要になってくるはず。

Validation

Validation用のメソッドの実装

save_weights -> save_checkpoint

save_weightssave_checkpoint に変更して、訓練終了時のEpoch数、optimizer、lossを保存する。

https://pytorch.org/tutorials/beginner/saving_loading_models.html#saving-loading-a-general-checkpoint-for-inference-and-or-resuming-training

を参照。

https://github.com/KawashimaHirotaka/Typhoon/blob/9ed2826ae21a6a6caaafdab501456daec9dc3d1a/utils/trainer.py#L229-L257

これと同時に、load_weightload_checkpoint に修正して、コードに変更を加える。
https://github.com/KawashimaHirotaka/Typhoon/blob/9ed2826ae21a6a6caaafdab501456daec9dc3d1a/utils/trainer.py#L259-L275

追加学習出来るように訓練ループの所も修正

Motifアイデア

ランダムである時刻のデータを削除する。
削除したデータを前後から予想するように学習させる。
BERT的な、AutoEncoder的な。


AutoEncoderに未知のデータを突っ込むと変な値を吐くので、それを元に異常検知をするように、motif一つない綺麗なデータで学習させAutoEncoder風。

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.