layers.Embedding

mac2025-05-28  4

input:(input_dim,output_dim,input_length=None)

output:(input_length,output_dim)

 

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.

import numpy as np

input_array = np.random.randint(1000, size=(32, 10))

 

model.compile('rmsprop', 'mse')

output_array = model.predict(input_array)

assert output_array.shape == (32, 10, 64)

最新回复(0)