TensorFlow中文官方网站离散和连续特征怎么喂入模型:https://tensorflow.google.cn/tutorials/structured_data/preprocessing_layers
Keras 和 TensorFlow 版本 匹配信息:https://docs.floydhub.com/guides/environments/
Keras Embedding 和W2V例子:https://zhuanlan.zhihu.com/p/279395289
Keras 自定义Embedding层(电影分类):https://lauzyhou.blog.csdn.net/article/details/89421674
Keras 加载 & 未加载 预训练模型例子:https://blog.csdn.net/weixin_42259192/article/details/99888561
Embedding 和 Word2Vec 实战 https://www.cnblogs.com/dogecheng/p/11565530.html
TensorFlow 中,Keras中Embedding:
Embedding 加入模型,有以下几种方式,
纯 Embedding方式
-
model.add(
Embedding(
input_dim, 词典 长度
output_dim,降到多少维
input_length,句子的长度
)
)
model.add( Flatten())
解释:将 3 维 的嵌入 张量展平成 形状 为 (samples ,input_length * output_dim)的 二维向量,
如果,后面接入 LSTM , 不用 flatten 展平。 -
Model.add(Dense(
Units = 32,
Input_dim = input_dim 词典 长度
)
)
解释:词袋模型,一个句子中,单词 所在词典中的位置 置为 1,剩下全0,k-hot 编码 -
接入 word2vec 3.1. 未加载 预训练 模型: from keras.layers import Embedding max_len = 20 句子的长度 vocab_size = 1000 词典的长度 vocab_dim = 300 词向量 维度 input_ = Input(shape = (max_len, )) emd = Embedding(input_dim = vocab_size , output_dim = 300, input_length = max_len)(input_) 3.2. 加载预训练模型 from keras.layers import Embedding max_len = 20 句子的长度 vocab_size = 1000 vocab_dim = 150 词向量 维度 #embedding_matri为预训练单词的权重矩阵 input_ = Input(shape = (max_len, )) emd = Embedding(input_dim=vocab_size , output_dim=150, input_length=max_len, weights=[embedding_matrix], trainable=False)(input_)