[英]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.