Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Skip connection in encoder and decoder #7

Open
Xiaohan-Chen opened this issue Aug 7, 2023 · 0 comments
Open

Skip connection in encoder and decoder #7

Xiaohan-Chen opened this issue Aug 7, 2023 · 0 comments

Comments

@Xiaohan-Chen
Copy link

Xiaohan-Chen commented Aug 7, 2023

Hi, thanks for sharing this wonderful project. I notice that in the transformer encoder, there is a skip connection between the encoder output and input, i.e. src = self.encoder(src) + src_start.
It seem different from the original transformer model? Decoder also has the same connection.

def encode_src(self, src):
    src_start = self.input_projection(src).permute(1, 0, 2)

    in_sequence_len, batch_size = src_start.size(0), src_start.size(1)
    pos_encoder = (
        torch.arange(0, in_sequence_len, device=src.device)
        .unsqueeze(0)
        .repeat(batch_size, 1)
    )

    pos_encoder = self.input_pos_embedding(pos_encoder).permute(1, 0, 2)

    src = src_start + pos_encoder

    src = self.encoder(src) + src_start

    return src
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant