Transformer model Args: src_n_token: the size of source vocab tgt_n_token: the size of target vocab d_model: the number of expected features in the encoder/decoder inputs (default=512) n_head: the number of heads in the multi head atte
(self, src_n_token, tgt_n_token, d_model=512, n_head=8, dim_feedforward=2048, n_layers=6)
| 28 | |
| 29 | class Transformer(model.Model): |
| 30 | def __init__(self, src_n_token, tgt_n_token, d_model=512, n_head=8, dim_feedforward=2048, n_layers=6): |
| 31 | """ |
| 32 | Transformer model |
| 33 | Args: |
| 34 | src_n_token: the size of source vocab |
| 35 | tgt_n_token: the size of target vocab |
| 36 | d_model: the number of expected features in the encoder/decoder inputs (default=512) |
| 37 | n_head: the number of heads in the multi head attention models (default=8) |
| 38 | dim_feedforward: the dimension of the feedforward network model (default=2048) |
| 39 | n_layers: the number of sub-en(de)coder-layers in the en(de)coder (default=6) |
| 40 | """ |
| 41 | super(Transformer, self).__init__() |
| 42 | |
| 43 | self.opt = None |
| 44 | self.src_n_token = src_n_token |
| 45 | self.tgt_n_token = tgt_n_token |
| 46 | self.d_model = d_model |
| 47 | self.n_head = n_head |
| 48 | self.dim_feedforward = dim_feedforward |
| 49 | self.n_layers = n_layers |
| 50 | |
| 51 | # encoder / decoder / linear |
| 52 | self.encoder = TransformerEncoder(src_n_token=src_n_token, d_model=d_model, n_head=n_head, |
| 53 | dim_feedforward=dim_feedforward, n_layers=n_layers) |
| 54 | self.decoder = TransformerDecoder(tgt_n_token=tgt_n_token, d_model=d_model, n_head=n_head, |
| 55 | dim_feedforward=dim_feedforward, n_layers=n_layers) |
| 56 | |
| 57 | self.linear3d = Linear3D(in_features=d_model, out_features=tgt_n_token, bias=False) |
| 58 | |
| 59 | self.soft_cross_entropy = layer.SoftMaxCrossEntropy() |
| 60 | |
| 61 | def forward(self, enc_inputs, dec_inputs): |
| 62 | """ |
nothing calls this directly
no test coverage detected