npm init npm install @tensorflow/tfjs @tensorflow-models/universal-sentence-encoder
require('@tensorflow/tfjs'); const encoder = require('@tensorflow-models/universal-sentence-encoder');
const model = await encoder.loadQnA();
const input = { queries: \["I want some coffee"\], responses: \[ "I grab a ball", "I go to you", "I play with a ball", "I go to school.", "I go to the mug.", "I bring you the mug." \] }; const embeddings = await model.embed(input);
//zipWith :: (a -> b -> c) -> \[a\] -> \[b\] -> \[c\] const zipWith = (f, xs, ys) => { const ny = ys.length; return (xs.length <= ny ? xs : xs.slice(0, ny)) .map((x, i) => f(x, ys\[i\])); } // Calculate the dot product of two vector arrays. const dotProduct = (xs, ys) => { const sum = xs => xs ? xs.reduce((a, b) => a + b, 0) : undefined; return xs.length === ys.length ? sum(zipWith((a, b) => a * b, xs, ys)) : undefined; }
[ { response: 'I grab a ball', score: 10.788130270345432 }, { response: 'I go to you', score: 11.597091717283469 }, { response: 'I play with a ball', score: 9.346379028479209 }, { response: 'I go to school.', score: 10.130473646521292 }, { response: 'I go to the mug.', score: 12.475453722603106 }, { response: 'I bring you the mug.', score: 13.229019199245684 } ]
Postar um comentário
Nenhum comentário :
Postar um comentário