-
Notifications
You must be signed in to change notification settings - Fork 0
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
andyj29
committed
Apr 11, 2023
1 parent
f78d36b
commit a87eb00
Showing
5 changed files
with
58 additions
and
19 deletions.
There are no files selected for viewing
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 |
---|---|---|
@@ -1,4 +1,5 @@ | ||
from .attention import MultiHeadAttention | ||
from .ffn import FeedForwardNetwork | ||
from .embedding import Embeddings | ||
from .position import PositionalEncoding | ||
from .position import PositionalEncoding | ||
from .residual import ResidualConnection |
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
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 |
---|---|---|
@@ -1,10 +1,47 @@ | ||
import torch.nn as nn | ||
import torch.nn.functional as F | ||
from transformer.common import MultiHeadAttention, FeedForwardNetwork | ||
|
||
from transformer.common import \ | ||
( | ||
MultiHeadAttention, | ||
FeedForwardNetwork, | ||
ResidualConnection, | ||
Embeddings, | ||
PositionalEncoding | ||
) | ||
|
||
|
||
class EncoderLayer(nn.Module): | ||
def __init__(self, attn, ffn, dropout): | ||
def __init__(self, d_model, n_head, d_ffn_hidden, dropout=0.1): | ||
super(EncoderLayer, self).__init__() | ||
self.attn = MultiHeadAttention(n_head, dropout) | ||
self.ffn = FeedForwardNetwork(d_model, d_ffn_hidden) | ||
self.residual = nn.ModuleList([ | ||
ResidualConnection(self.attn), | ||
ResidualConnection(self.ffn), | ||
]) | ||
|
||
def forward(self, x): | ||
for layer in self.residual: | ||
x = layer(x) | ||
|
||
return x | ||
|
||
|
||
|
||
class Encoder(nn.Module): | ||
def __init__(self, d_model, n_stack, n_head, d_ffn_hidden, corpus_len, dropout): | ||
self.layers = nn.ModuleList([ | ||
EncoderLayer(d_model, n_head, d_ffn_hidden, dropout) | ||
for _ in range(n_stack) | ||
] | ||
) | ||
self.emb = Embeddings(d_model) | ||
self.pos = PositionalEncoding(d_model, dropout, max_len=corpus_len) | ||
self.dropout = nn.Dropout(dropout) | ||
self.d_model = d_model | ||
|
||
|
||
def forward(self, x): | ||
pass | ||
|
||
|