MCPcopy Index your code
hub / github.com/tensorflow/tfjs-examples / getClassificationMessage

Function getClassificationMessage

intent-classifier/app/index.js:71–97  ·  view source on GitHub ↗
(softmaxArr)

Source from the content-addressed store, hash-verified

69
70const THRESHOLD = 0.90;
71async function getClassificationMessage(softmaxArr) {
72 const {labels} = await loadMetadata();
73 const max = Math.max(...softmaxArr);
74 const maxIndex = softmaxArr.indexOf(max);
75 const intentLabel = labels[maxIndex];
76
77 if (max < THRESHOLD) {
78 return '¯\\_(ツ)_/¯';
79 } else {
80 let response;
81 switch (intentLabel) {
82 case 'AddToPlaylist':
83 response = '💿➡️📇';
84 break;
85 case 'GetWeather':
86 response = '⛅';
87 break;
88 case 'PlayMusic':
89 response = '🎵🎺🎵';
90 break;
91 default:
92 response = '?';
93 break;
94 }
95 return response;
96 }
97}
98
99async function onSendMessage(inputText) {
100 if (inputText != null && inputText.length > 0) {

Callers 1

onSendMessageFunction · 0.85

Calls 1

loadMetadataFunction · 0.70

Tested by

no test coverage detected