2020-06-04-tensorlfow2-layers.Em
2020-06-08 本文已影响0人
logi
以layers.Embedding(1000, 64, input_length=10)
为例
将输入的shape为(None, input_length) 值为映射到id(0-999)的数据,转换为(None, 10, 64)的embedding数据。
import tensorflow as tf
from tensorflow.keras import layers
model = tf.keras.Sequential()
model.add(layers.Embedding(1000, 64, input_length=10))
# the model will take as input an integer matrix of size (batch,
# input_length).
# the largest integer (i.e. word index) in the input should be no larger
# than 999 (vocabulary size).
# now model.output_shape == (None, 10, 64), where None is the batch
# dimension.