-
Notifications
You must be signed in to change notification settings - Fork 415
Open
Description
class TextCNN(nn.Module):
def __init__(self, nb_words, embed_dim, embedding_matrix, max_seq_len, num_filters, num_classes):
super(TextCNN, self).__init__()
self.num_filters=num_filters
self.embed = nn.Embedding(nb_words, embed_dim)
self.dropout = nn.Dropout(0.3)
self.conv = nn.Conv1d(embed_dim, num_filters, kernel_size=2, stride=1)
self.fc1 = nn.Linear(num_filters, 32)
self.fc2 = nn.Linear(32, num_classes)
self.logsigmoid = nn.Sigmoid()
def forward(self, x):
x = self.embed(x)
x = x.permute(0, 2, 1)
x = self.dropout(x)
x = self.conv(x).permute(0, 2, 1).max(1)[0]
x = self.fc1(x)
x = F.relu(x)
x = self.dropout(x)
x = self.fc2(x)
return self.logsigmoid(x)
model = TextCNN(1000, 100, [], 10, 20, 3)
data = torch.from_numpy(np.array([[1,4,5], [7,7,9]]))
output = model(data)
print(output)
print(model)
print(data[0].shape)
print(summary(model, (1, 10)))
Gives error:
RuntimeError: Expected tensor for argument #1 'indices' to have scalar type Long; but got CPUFloatTensor instead (while checking arguments for embedding)
MattScicluna, cwellszhang, lazarotm, BerenLuthien, vmichals and 11 more
Metadata
Metadata
Assignees
Labels
No labels