seq2seqモデルを使用することができます。簡潔にするために、Tensorflowバックエンドを持つKerasでどのように実行できるかの例を書いてきました。私は例を実行していないので、調整が必要な場合があります。あなたのタグがホットな場合は、代わりにクロスエントロピー損失を使用する必要があります。
from keras.models import Model
from keras.layers import Input, LSTM, RepeatVector
# The input shape is your sequence length and your token embedding size
inputs = Input(shape=(seq_len, embedding_size))
# Build a RNN encoder
encoder = LSTM(128, return_sequences=False)(inputs)
# Repeat the encoding for every input to the decoder
encoding_repeat = RepeatVector(5)(encoder)
# Pass your (5, 128) encoding to the decoder
decoder = LSTM(128, return_sequences=True)(encoding_repeat)
# Output each timestep into a fully connected layer
sequence_prediction = TimeDistributed(Dense(1, activation='linear'))(decoder)
model = Model(inputs, sequence_prediction)
model.compile('adam', 'mse') # Or categorical_crossentropy
model.fit(X_train, y_train)
ありがとう、サイモン! 私はseq2seqのデモを実行しませんでした。私を混乱させる1つの点は埋め込みについてです。エンコーダとデコーダでは、埋め込みレイヤは必要ありません。入力(idsのリスト)を渡すだけです。 –
あなたのIDを埋め込むか、ワンホットエンコードしたいと思うかもしれません。それはあなたのidsの性質に依存しますが、非常に大量のidsがなければ、ワンホットエンコーディングが正しい選択だと思います。あなたのデータは、 '(num_samples、seq_len、one_hot_size)のサイズでなければなりません。そしてクロスエントロピー損失を使うべきです。 –
異なるサイズの入力と出力はできますか? –