MCPcopy
hub / github.com/tensorflow/tfjs-examples / predict

Method predict

sentiment/index.js:60–83  ·  view source on GitHub ↗
(text)

Source from the content-addressed store, hash-verified

58 }
59
60 predict(text) {
61 // Convert to lower case and remove all punctuations.
62 const inputText =
63 text.trim().toLowerCase().replace(/(\.|\,|\!)/g, '').split(' ');
64 // Convert the words to a sequence of word indices.
65 const sequence = inputText.map(word => {
66 let wordIndex = this.wordIndex[word] + this.indexFrom;
67 if (wordIndex > this.vocabularySize) {
68 wordIndex = OOV_INDEX;
69 }
70 return wordIndex;
71 });
72 // Perform truncation and padding.
73 const paddedSequence = padSequences([sequence], this.maxLen);
74 const input = tf.tensor2d(paddedSequence, [1, this.maxLen]);
75
76 const beginMs = performance.now();
77 const predictOut = this.model.predict(input);
78 const score = predictOut.dataSync()[0];
79 predictOut.dispose();
80 const endMs = performance.now();
81
82 return {score: score, elapsed: (endMs - beginMs)};
83 }
84};
85
86/**

Callers 15

calcQValuesAndBestActionFunction · 0.45
initGameFunction · 0.45
playStepMethod · 0.45
lossFunctionMethod · 0.45
renderModelPredictionsFunction · 0.45
getLogitsAndActionsMethod · 0.45
classifyMethod · 0.45
mainFunction · 0.45
generateTextFunction · 0.45
index.jsFile · 0.45
predictFunction · 0.45
initFunction · 0.45

Calls 1

padSequencesFunction · 0.90

Tested by

no test coverage detected