Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 6d15200

Browse files
committedFeb 24, 2022
model updates to reflect ICLR 2022 revisions
1 parent 01e0080 commit 6d15200

File tree

11 files changed

+260
-150
lines changed

11 files changed

+260
-150
lines changed
 

‎README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
# Anomaly Transformer in PyTorch
22

3-
This is an implementation of [Anomaly Transformer: Time Series Anomaly Detection with Association Discrepancy](https://arxiv.org/abs/2110.02642). This paper is currently [under review](https://openreview.net/forum?id=LzQQ89U1qm_) and in need of some clarification around the attention mechanism. This repo will be updated as more information is provided.
3+
This is an implementation of [Anomaly Transformer: Time Series Anomaly Detection with Association Discrepancy](https://arxiv.org/abs/2110.02642). This paper has been accepted as a [Spotlight Paper at ICLR 2022](https://openreview.net/forum?id=LzQQ89U1qm_).
4+
5+
Repository currently a work in progress.
46

57
## Usage
68

@@ -14,6 +16,8 @@ $ source env/bin/activate
1416
(env) $ pip install -r requirements.txt
1517
```
1618

19+
Written with python version `3.8.11`
20+
1721
### Data and Configuration
1822

1923
Custom datasets can be placed in the `data/` dir. Edits should be made to the `conf/data/default.yaml` file to reflect the correct properties of the data. All other configuration hyperparameters can be set in the hydra configs.

‎archive/exploration.ipynb

Lines changed: 132 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,14 @@
22
"cells": [
33
{
44
"cell_type": "code",
5-
"execution_count": 5,
5+
"execution_count": null,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": []
9+
},
10+
{
11+
"cell_type": "code",
12+
"execution_count": 1,
613
"metadata": {},
714
"outputs": [],
815
"source": [
@@ -29,7 +36,7 @@
2936
},
3037
{
3138
"cell_type": "code",
32-
"execution_count": 16,
39+
"execution_count": 2,
3340
"metadata": {},
3441
"outputs": [],
3542
"source": [
@@ -40,7 +47,92 @@
4047
},
4148
{
4249
"cell_type": "code",
43-
"execution_count": 50,
50+
"execution_count": 10,
51+
"metadata": {},
52+
"outputs": [],
53+
"source": [
54+
"p = torch.from_numpy(np.abs(np.indices((100,100))[0] - np.indices((100,100))[1]))\n",
55+
"sigma = torch.ones(100).view(100, 1) * 2"
56+
]
57+
},
58+
{
59+
"cell_type": "code",
60+
"execution_count": 12,
61+
"metadata": {},
62+
"outputs": [],
63+
"source": [
64+
"P = torch.ones(10,10) * torch.arange(10).view(10,1)"
65+
]
66+
},
67+
{
68+
"cell_type": "code",
69+
"execution_count": 14,
70+
"metadata": {},
71+
"outputs": [],
72+
"source": [
73+
"S = torch.ones(10,10) * torch.arange(10).view(1,10)"
74+
]
75+
},
76+
{
77+
"cell_type": "code",
78+
"execution_count": 18,
79+
"metadata": {},
80+
"outputs": [
81+
{
82+
"name": "stderr",
83+
"output_type": "stream",
84+
"text": [
85+
"/Users/spencerbraun/.pyenv/versions/3.8.11/envs/dl/lib/python3.8/site-packages/torch/nn/functional.py:2747: UserWarning: reduction: 'mean' divides the total loss by both the batch size and the support size.'batchmean' divides only by the batch size, and aligns with the KL div math definition.'mean' will be changed to behave the same as 'batchmean' in the next major release.\n",
86+
" warnings.warn(\n"
87+
]
88+
},
89+
{
90+
"data": {
91+
"text/plain": [
92+
"tensor(3.4057)"
93+
]
94+
},
95+
"execution_count": 18,
96+
"metadata": {},
97+
"output_type": "execute_result"
98+
}
99+
],
100+
"source": [
101+
"lambda row: F.kl_div(P[row,:], S[row,:]) + F.kl_div(S[row,:], P[row,:])"
102+
]
103+
},
104+
{
105+
"cell_type": "code",
106+
"execution_count": 20,
107+
"metadata": {},
108+
"outputs": [
109+
{
110+
"data": {
111+
"text/plain": [
112+
"tensor([[0., 0., 0., 0., 0., 0., 0., 0., 0., 0.],\n",
113+
" [1., 1., 1., 1., 1., 1., 1., 1., 1., 1.],\n",
114+
" [2., 2., 2., 2., 2., 2., 2., 2., 2., 2.],\n",
115+
" [3., 3., 3., 3., 3., 3., 3., 3., 3., 3.],\n",
116+
" [4., 4., 4., 4., 4., 4., 4., 4., 4., 4.],\n",
117+
" [5., 5., 5., 5., 5., 5., 5., 5., 5., 5.],\n",
118+
" [6., 6., 6., 6., 6., 6., 6., 6., 6., 6.],\n",
119+
" [7., 7., 7., 7., 7., 7., 7., 7., 7., 7.],\n",
120+
" [8., 8., 8., 8., 8., 8., 8., 8., 8., 8.],\n",
121+
" [9., 9., 9., 9., 9., 9., 9., 9., 9., 9.]])"
122+
]
123+
},
124+
"execution_count": 20,
125+
"metadata": {},
126+
"output_type": "execute_result"
127+
}
128+
],
129+
"source": [
130+
"P"
131+
]
132+
},
133+
{
134+
"cell_type": "code",
135+
"execution_count": 3,
44136
"metadata": {},
45137
"outputs": [
46138
{
@@ -60,7 +152,7 @@
60152
" 9.9000])"
61153
]
62154
},
63-
"execution_count": 50,
155+
"execution_count": 3,
64156
"metadata": {},
65157
"output_type": "execute_result"
66158
}
@@ -71,18 +163,19 @@
71163
},
72164
{
73165
"cell_type": "code",
74-
"execution_count": 75,
166+
"execution_count": 9,
75167
"metadata": {},
76168
"outputs": [
77169
{
78-
"data": {
79-
"text/plain": [
80-
"torch.Size([100, 100])"
81-
]
82-
},
83-
"execution_count": 75,
84-
"metadata": {},
85-
"output_type": "execute_result"
170+
"ename": "NameError",
171+
"evalue": "name 'sigma' is not defined",
172+
"output_type": "error",
173+
"traceback": [
174+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
175+
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
176+
"\u001b[0;32m/var/folders/8w/r6kg1v9x7bbfzf9dw9gjslc80000gn/T/ipykernel_95641/3924366364.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mtorch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mexp\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mpow\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;36m2\u001b[0m\u001b[0;34m)\u001b[0m \u001b[0;34m/\u001b[0m \u001b[0;34m(\u001b[0m\u001b[0msigma\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
177+
"\u001b[0;31mNameError\u001b[0m: name 'sigma' is not defined"
178+
]
86179
}
87180
],
88181
"source": [
@@ -91,28 +184,41 @@
91184
},
92185
{
93186
"cell_type": "code",
94-
"execution_count": 99,
187+
"execution_count": 6,
95188
"metadata": {},
96-
"outputs": [],
189+
"outputs": [
190+
{
191+
"ename": "NameError",
192+
"evalue": "name 'p' is not defined",
193+
"output_type": "error",
194+
"traceback": [
195+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
196+
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
197+
"\u001b[0;32m/var/folders/8w/r6kg1v9x7bbfzf9dw9gjslc80000gn/T/ipykernel_95641/3546984218.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mgaussian\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mtorch\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mnormal\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mp\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mfloat\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0msigma\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 2\u001b[0m \u001b[0mgaussian\u001b[0m \u001b[0;34m/=\u001b[0m \u001b[0mgaussian\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msum\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0mdim\u001b[0m\u001b[0;34m=\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mview\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m-\u001b[0m\u001b[0;36m1\u001b[0m\u001b[0;34m,\u001b[0m \u001b[0;36m1\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
198+
"\u001b[0;31mNameError\u001b[0m: name 'p' is not defined"
199+
]
200+
}
201+
],
97202
"source": [
98203
"gaussian = torch.normal(p.float(), sigma)\n",
99204
"gaussian /= gaussian.sum(dim=-1).view(-1, 1)"
100205
]
101206
},
102207
{
103208
"cell_type": "code",
104-
"execution_count": 101,
209+
"execution_count": 5,
105210
"metadata": {},
106211
"outputs": [
107212
{
108-
"data": {
109-
"text/plain": [
110-
"tensor(1.)"
111-
]
112-
},
113-
"execution_count": 101,
114-
"metadata": {},
115-
"output_type": "execute_result"
213+
"ename": "NameError",
214+
"evalue": "name 'gaussian' is not defined",
215+
"output_type": "error",
216+
"traceback": [
217+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
218+
"\u001b[0;31mNameError\u001b[0m Traceback (most recent call last)",
219+
"\u001b[0;32m/var/folders/8w/r6kg1v9x7bbfzf9dw9gjslc80000gn/T/ipykernel_95641/494294515.py\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[0;32m----> 1\u001b[0;31m \u001b[0mgaussian\u001b[0m\u001b[0;34m[\u001b[0m\u001b[0;36m0\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;34m:\u001b[0m\u001b[0;34m]\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msum\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m",
220+
"\u001b[0;31mNameError\u001b[0m: name 'gaussian' is not defined"
221+
]
116222
}
117223
],
118224
"source": [
@@ -173,18 +279,14 @@
173279
"execution_count": 67,
174280
"metadata": {},
175281
"outputs": [],
176-
"source": [
177-
"p = torch.from_numpy(np.abs(np.indices((100,100))[0] - np.indices((100,100))[1]))"
178-
]
282+
"source": []
179283
},
180284
{
181285
"cell_type": "code",
182286
"execution_count": 72,
183287
"metadata": {},
184288
"outputs": [],
185-
"source": [
186-
"sigma = torch.ones(100).view(100, 1) * 2"
187-
]
289+
"source": []
188290
},
189291
{
190292
"cell_type": "code",

‎conf/config.yaml

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,3 @@
1-
defaults:
2-
- model: default
3-
- data: default
4-
- evaluate: default
5-
- train: default
61

72
seed: 0
83
debug: False
@@ -32,11 +27,6 @@ model:
3227

3328
data:
3429
path: null
35-
rephrase: true
36-
zsre_nq: true
37-
nq_path: ${hydra:runtime.cwd}/data/nq
38-
wiki_webtext: true
39-
n_edits: 1
4030

4131
eval:
4232
verbose: True

‎conf/evaluate/default.yaml

Lines changed: 0 additions & 5 deletions
This file was deleted.

‎conf/model/default.yaml

Lines changed: 0 additions & 2 deletions
This file was deleted.

‎conf/model/transformers.yaml

Lines changed: 0 additions & 4 deletions
This file was deleted.

‎conf/train/default.yaml

Lines changed: 0 additions & 23 deletions
This file was deleted.

‎conf/train/lightning.yaml

Lines changed: 0 additions & 24 deletions
This file was deleted.
There was a problem loading the remainder of the diff.

0 commit comments

Comments
 (0)
Failed to load comments.