[英]tf.keras.preprocessing.sequence.pad_sequences in JavaScript
我們如何在 TensorFlow.js 中實現 tf.keras.preprocessing.sequence.pad_sequences?
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
稍后可用於填充張量
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.