MagicText-1.3-WMHA / class_ai.py
BIGAI-models's picture
Create class_ai.py
f25fa82 verified
Raw
History Blame Contribute Delete
651 Bytes
class AI(nn.Module):
def __init__(self):
super().__init__()
self.embed = nn.Embedding(len(wti), 128)
self.lstm = nn.LSTM(128, 128, batch_first=True)
self.attention = nn.MultiheadAttention(embed_dim=128, num_heads=4, batch_first=True)
self.layernorm_after = nn.LayerNorm(128)
self.linear = nn.Linear(128, len(itw))
def forward(self, x):
x = self.embed(x)
x_origin = x
x, _ = self.lstm(x)
x_origin = x
x, _ = self.attention(x, x, x)
x+= x_origin
x = self.layernorm_after(x)
x = self.linear(x)
x = x[:, -1, :]
return x