-
Notifications
You must be signed in to change notification settings - Fork 394
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
64e83bc
commit 10c0a9d
Showing
21 changed files
with
175 additions
and
28 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+54 Bytes
(100%)
models/embedding/__pycache__/positional_encoding.cpython-36.pyc
Binary file not shown.
Binary file modified
BIN
-33 Bytes
(98%)
models/embedding/__pycache__/transformer_embedding.cpython-36.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file added
BIN
+939 Bytes
models/layers/__pycache__/position_wise_feed_forward.cpython-36.pyc
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
""" | ||
@author : Hyunwoong | ||
@when : 2019-12-18 | ||
@homepage : https://github.com/gusdnd852 | ||
""" | ||
import torch | ||
from torch import nn | ||
|
||
|
||
class LayerNorm(nn.Module): | ||
def __init__(self, d_model, eps=1e-12): | ||
super(LayerNorm, self).__init__() | ||
self.gamma = nn.Parameter(torch.ones(d_model)) | ||
self.beta = nn.Parameter(torch.zeros(d_model)) | ||
self.eps = eps | ||
|
||
def forward(self, x): | ||
mean = x.mean(-1, keepdim=True) | ||
std = x.std(-1, keepdim=True) | ||
|
||
out = self.gamma * (x - mean) | ||
out /= (std + self.eps) | ||
out += self.beta | ||
return out |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
""" | ||
@author : Hyunwoong | ||
@when : 2019-12-18 | ||
@homepage : https://github.com/gusdnd852 | ||
""" | ||
from torch import nn | ||
|
||
|
||
class PositionwiseFeedForward(nn.Module): | ||
|
||
def __init__(self, d_model, hidden): | ||
super(PositionwiseFeedForward, self).__init__() | ||
self.linear1 = nn.Linear(d_model, hidden) | ||
self.linear2 = nn.Linear(hidden, d_model) | ||
self.relu = nn.ReLU() | ||
|
||
def forward(self, x): | ||
x = self.linear1(x) | ||
x = self.relu(x) | ||
x = self.linear2(x) | ||
return x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters