tf.keras.preprocessing.sequence.JavaScript中的pad_s



如何实现tf.keras.preprocessing.sequence。pad_sequences在TensorFlow.js?

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以后可以用来填充张量

相关内容

  • 没有找到相关文章

最新更新