我正在尝试根据该图片构建LSTM模型。 我是使用RNN结构进行深度学习的初学者,所以我需要您的建议来引导我
因此,为此,我要处理70k用户和12k动漫的数据框,我的数据框包含:
用户ID
用户评分
动漫ID
genre:与动漫相关的标签列表,例如动作,喜剧,学校等。
users_tags:由于tfifd方法和一些与用户相关的文本数据,我为唯一用户创建了15个唯一标签的列表
我的数据框看起来像:
anime_id user_id user_rating name tags genre
0 1 234 9.0 Cowboy Bebop drama , fi , mal action , military , sci fi , ... Action, Adventure, Comedy, Drama, Sci-Fi, Space
1 1 382 10.0 Cowboy Bebop life , shiki , tv , thriller , movie short , c... Action, Adventure, Comedy, Drama, Sci-Fi, Space
2 1 160 9.0 Cowboy Bebop fantasy , action , supernatural , tv , mystery... Action, Adventure, Comedy, Drama, Sci-Fi, Space
3 1 341 8.0 Cowboy Bebop action , school , romance , new , short , mal ... Action, Adventure, Comedy, Drama, Sci-Fi, Space
4 1 490 9.0 Cowboy Bebop mal adventure , movie short , school , strange... Action, Adventure, Comedy, Drama, Sci-Fi,
这里是我用于模型的参数:
#parameters
users = interactions_full_df.user_id.unique()
animes = interactions_full_df.anime_id.unique()
animes_tags = " ".join(interactions_full_df["genre"].unique()).split(",")
n_animes_tags = len(animes_tags)
n_users = len(users)
n_animes = len(animes)
n_users_tags = 15
我将250用作嵌入层的“潜在暗淡”。
在这里,我尝试构建此模型
""" Users Tags : FIXED INPUT """
Users_Tags_input = Input(shape=[1],name='Users_tags')
Users_embedding_tags = Embedding(n_users + 1,
latent_dim,
name='Users-Embeddings-MLP')(Users_Tags_input)
Users_vec_TAGS = Flatten(name='FlattenUsers-TAGS')(Users_embedding_tags)
""" Users embedding"""
Users_input = Input(shape=[1],name='Users')
Users_embedding_mlp = Embedding(n_users + 1,
latent_dim,
name='Users-Embeddings-MLP')(Users_input)
Users_vec_mlp = Flatten(name='FlattenUsers-MLP')(Users_embedding_mlp)
""" Anime Embedding """
animes_input = Input(shape=[1],name='Anime')
animes_embedding_mlp = Embedding(n_animes + 1,
latent_dim,
name='Animes-Embedding-MLP')(animes_input)
animes_vec_mlp = Flatten(name='FlattenAnimes-MLP')(animes_embedding_mlp)
""" Anime Tags """
animes_tags_input = Input(shape=[1],name='anime_tags')
animes_embedding_tags = Embedding(n_animes_tags + 1,
latent_dim,
name='Animes-Tags-embedding')(animes_tags_input)
animes_vec_tags = Flatten(name='FlattenAnimes-Tags')(animes_embedding_tags)
""" Tags of future anime in a sequence ????"""
animes_vecs_tags = LSTM(latent_dim)(animes_embedding_tags)
FC_tags = Dense(200,name='FullyConnected')(animes_vecs_tags)
#---------------------------------------------
anime_with_tags = merge([animes_vec_mlp, animes_vec_tags], mode = "concat")
users_with_tags = merge([Users_vec_TAGS, Users_vec_mlp], mode = "concat")
#---------------------------------------------
interactions = merge([anime_with_tags, users_with_tags], mode = "concat")
lstm_cell = LSTM(latent_dim, return_sequences=True)(interactions)
FC_lstm = Dense(200,name='FullyConnected2')(lstm_cell)
""" preds tags"""
preds_tags = Dense(10, activation = "sigmoid")(FC_tags)
""" preds animes"""
preds_animes = dense(10, activation = "sigmoid")(FC_lstm)
combine_preds = concatenate([preds_tags, preds_animes])
combine_dropout = Dropout(0.2)(combine_preds)
result = Dense(10, activation='softmax', name = "Recommendation")(combine_dropout)
LSTM_MODEL = Model([animes_input, animes_tags_input, Users_input, Users_Tags_input], result)