[英]Is texts_to_sequences, pad_sequences available in TensorFlow.js or is there any other alternative for this?
I have build a Keras model for next word prediction and I am trying to use my model in front-end for predicting next word based on input from the text field, I have to convert the following code from Python to JavaScript but did not find any合適的選擇。 有沒有辦法解決這個問題?
from keras.preprocessing.sequence import pad_sequences
input_text = input().strip().lower()
encoded_text = tokenizer.texts_to_sequences([input_text])[0]
pad_encoded = pad_sequences([encoded_text], maxlen=seq_len, truncating='pre')
for i in (model.predict(pad_encoded)[0]).argsort()[-10:][::-1]:
pred_word = tokenizer.index_word[i]
print("Next word suggestion:",pred_word)
我在Python中得到以下 I 的預測:
我剛剛在 node.js 中寫了一個替代方案,也許它可以幫助你
回購: https://github.com/Shadowhusky/node_tokenizer
你可以安裝它
npm install --save tf_node_tokenizer
例子:
const { Tokenizer } = require("tf_node_tokenizer");
const tokenizer = new Tokenizer({ num_words: 5, oov_token = "<unk>", });
const text = [
"<start> Cake and frosting all over a face and hands tells a happy story. <end>",
"<start> A baby is feeding himself with his hands and is smeared with food. <end>",
"<start> A baby eating pink dessert in a highchair <end>"
];
tokenizer.fitOnTexts(text);
tokenizer.texts_to_sequences(text);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.