Javascript TensorFlow.js中是否有文本到顺序、填充顺序,或者是否有其他替代方法?
我已经为下一个单词的预测建立了一个Keras模型,我正试图在前端使用我的模型根据文本字段的输入预测下一个单词,我必须将以下代码从Python转换为JavaScript,但没有找到任何合适的选项。 有办法解决这个问题吗Javascript TensorFlow.js中是否有文本到顺序、填充顺序,或者是否有其他替代方法?,javascript,python,keras,deep-learning,tensorflow.js,Javascript,Python,Keras,Deep Learning,Tensorflow.js,我已经为下一个单词的预测建立了一个Keras模型,我正试图在前端使用我的模型根据文本字段的输入预测下一个单词,我必须将以下代码从Python转换为JavaScript,但没有找到任何合适的选项。 有办法解决这个问题吗 from keras.preprocessing.sequence import pad_sequences input_text = input().strip().lower() encoded_text = tokenizer.texts_to_sequences([inp
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的以下预测:
- 下一个词建议:拥有
- 下一个单词建议:am
- 下一个词建议:知道
- 下一个词建议:思考
- 下一句话建议:永远不要
- 下一个词建议:做
- 建议:想要
- 下一个词建议:永远
- 下一个词建议:威尔
- 建议:见
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);
const{Tokenizer}=require(“tf_节点_Tokenizer”);
const tokenizer=new tokenizer({num_words:5,oov_token=“”,});
常量文本=[
“脸上和手上的蛋糕和糖霜讲述了一个快乐的故事。”,
“一个婴儿正在用手喂食,身上沾满了食物。”,
“坐在高脚椅上吃粉红色甜点的婴儿”
];
fiontexts(文本);
标记器。文本\u到\u序列(文本);