text: # Standard PyTorch imports
  import numpy as np
  import torch
  import torch.nn as nn
  import torch.nn.functional as F
  import math, copy
  from torch.autograd import Variable
  import matplotlib.pyplot as plt
  
  from s2s.utils import clones, LayerNorm, SublayerConnection
  
  class Encoder(nn.Module):
      "Core encoder is a stack of N layers"
      def __init__(self, layer, N):
          super(Encoder, self).__init__()
          self.layers = clones(layer, N)
          self.norm = LayerNorm(layer.size)
          
      def forward(self, x, mask):
          "Pass the input (and mask) through each layer in turn."
          for layer in self.layers:
              x = layer(x, mask)
          return self.norm(x)
  
  class EncoderLayer(nn.Module):
      "Encoder is made up of two sublayers, self-attn and feed forward (defined below)"
      def __init__(self, size, self_attn, feed_forward, dropout):
          super(EncoderLayer, self).__init__()
          self.self_attn = self_attn
          self.feed_forward = feed_forward
          self.sublayer = clones(SublayerConnection(size, dropout), 2)
          self.size = size
  
      def forward(self, x, mask):
          "Follow Figure 1 (left) for connections."
          x = self.sublayer[0](x, lambda x: self.self_attn(x, x, x, mask))
          return self.sublayer[1](x, self.feed_forward)
  