問題
LSTM を使用してテキスト分類ネットワークを構築しようとしています。私が得ているエラーは次のとおりです。
RuntimeError: Expected hidden[0] size (4, 600, 256), got (4, 64, 256)
詳細
データはjsonで、次のようになります。
{"cat": "music", "desc": "I'm in love with the song's intro!", "sent": "h"}
私はtorchtext
データをロードするために使用しています。
from torchtext import data
from torchtext import datasets
TEXT = data.Field(fix_length = 600)
LABEL = data.Field(fix_length = 10)
BATCH_SIZE = 64
fields = {
'cat': ('c', LABEL),
'desc': ('d', TEXT),
'sent': ('s', LABEL),
}
私のLSTMは次のようになります
EMBEDDING_DIM = 64
HIDDEN_DIM = 256
N_LAYERS = 4
MyLSTM(
(embedding): Embedding(11967, 64)
(lstm): LSTM(64, 256, num_layers=4, batch_first=True, dropout=0.5)
(dropout): Dropout(p=0.3, inplace=False)
(fc): Linear(in_features=256, out_features=8, bias=True)
(sig): Sigmoid()
)
と の次の寸法にinputs
なりますlabels
batch = list(train_iterator)[0]
inputs, labels = batch
print(inputs.shape) # torch.Size([600, 64])
print(labels.shape) # torch.Size([100, 2, 64])
そして、初期化された隠しテンソルは次のようになります。
hidden # [torch.Size([4, 64, 256]), torch.Size([4, 64, 256])]
質問
各ステップの寸法がどうあるべきかを理解しようとしています。非表示の次元を (4, 600, 256) または (4, 64, 256) に初期化する必要がありますか?