text: import torch
  from torch import nn
  from torch.nn import functional as F
  
  class SeparateAttention(nn.Module):
      def __init__(self, hidden_size, output_size, dropout_ratio):
          super(SeparateAttention, self).__init__()
          #self.opt = opt
          self.hidden_size = hidden_size
          self.dropout_ratio=dropout_ratio
          self.separate_attention = True
          if self.separate_attention:
              self.linear_att = nn.Linear(3*self.hidden_size, self.hidden_size)
          else:
              self.linear_att = nn.Linear(2*self.hidden_size, self.hidden_size)
  
          self.linear_out = nn.Linear(self.hidden_size, output_size)
          
          self.dropout = nn.Dropout(dropout_ratio)
  
          self.softmax = nn.Softmax(dim=1)
          self.logsoftmax = nn.LogSoftmax(dim=1)
  
      def forward(self, enc_s_top, dec_s_top, enc_2):
          dot = torch.bmm(enc_s_top, dec_s_top.unsqueeze(2))
          attention = self.softmax(dot.squeeze(2)).unsqueeze(2)
          enc_attention = torch.bmm(enc_s_top.permute(0,2,1), attention)
  
          if self.separate_attention:
              dot_2 = torch.bmm(enc_2, dec_s_top.unsqueeze(2))
              attention_2 = self.softmax(dot_2.squeeze(2)).unsqueeze(2)
              enc_attention_2 = torch.bmm(enc_2.permute(0,2,1), attention_2)
  
          if self.separate_attention:
              hid = torch.tanh(self.linear_att(torch.cat((enc_attention.squeeze(2), enc_attention_2.squeeze(2),dec_s_top), 1)))
          else:
              hid = torch.tanh(self.linear_att(torch.cat((enc_attention.squeeze(2),dec_s_top), 1)))
          h2y_in = hid
          
          h2y_in = self.dropout(h2y_in)
          h2y = self.linear_out(h2y_in)
          pred = self.logsoftmax(h2y)
  
          return pred