JavaScript中的tf.keras.preprocessing.sequence.pad_序列
如何在TensorFlow.js中实现tf.keras.preprocessing.sequence.pad_序列JavaScript中的tf.keras.preprocessing.sequence.pad_序列,javascript,tensorflow,keras,tensorflow.js,Javascript,Tensorflow,Keras,Tensorflow.js,如何在TensorFlow.js中实现tf.keras.preprocessing.sequence.pad_序列 encoded_text = tokenizer.texts_to_sequences([input_text])[0] pad_encoded = pad_sequences([encoded_text], maxlen=seq_len, truncating='pre') 可以使用将文本转换为张量 require('@tensorflow/tfjs'); const use
encoded_text = tokenizer.texts_to_sequences([input_text])[0]
pad_encoded = pad_sequences([encoded_text], maxlen=seq_len, truncating='pre')
可以使用将文本转换为张量
require('@tensorflow/tfjs');
const use = require('@tensorflow-models/universal-sentence-encoder');
use.load().then(model => {
// Embed an array of sentences.
const sentences = [
'Hello.',
'How are you?'
];
model.embed(sentences).then(embeddings => {
// `embeddings` is a 2D tensor consisting of the 512-dimensional embeddings for each sentence.
// So in this example `embeddings` has the shape [2, 512].
embeddings.print(true /* verbose */);
});
});
tf.pad
稍后可用于填充张量