Прогнозы тензорного потока одинаковы для каждого намерения

#javascript #tensorflow #chatbot #tflearn

Вопрос:

Мой чат-бот javascript использует tflearn, чтобы предсказать, к какому намерению он относится для данного предложения. Однако функция model.predict() выводит почти такое же число. Я новичок в tflearn/tensorflow, поэтому не знаю, как это решить или что попробовать.

Вот мой код:

намерения:

 {"intents": [
    {"tag": "greeting",
     "patterns": ["Hey", "Hi", "Hello", "Good evening", "Good afternoon"],
     "responses": ["Hello, how are you?", "Hello, how could I help you?"],
     "context_set": ""
    },
    {"tag": "feelings",
     "patterns": ["How are you?", "How are you feeling?"],
     "responses": ["I don't have feelings."]
    }
    etc. (There are more intents)
]
}
 

создание модели:

       //train_x[0] example: [Array(139), Array(139), Array(139), ... Array(139), Array(139)]
      //Array(139) example: [0,0,0,0,0,1,0 ... 0,0,0]

      // Build neural network:
      const model = tf.sequential();
      model.add(tf.layers.dense({ units: 256, activation: 'relu', inputShape: [train_x[0].length] }));
      model.add(tf.layers.dropout({ rate: 0.25 }));
      model.add(tf.layers.dense({ units: 128, activation: 'relu' }));
      model.add(tf.layers.dropout({ rate: 0.25 }));
      model.add(tf.layers.dense({ units: train_y[0].length, activation: 'softmax' }));
      model.compile({ optimizer: 'adam', loss: 'categoricalCrossentropy', metrics: ['accuracy'] });

      //create tensors
      const xs = tf.tensor(train_x);
      const ys = tf.tensor(train_y);
      
      //train model
      model.fit(xs, ys, {
        epochs: 50,
        batchSize: 8,
        shuffle: true,
        // verbose: 1,
        callbacks: {
          onEpochEnd: async (epoch, log) => {
          console.log("Epoch "   epoch   ": loss = "   log.loss);
        }
      }
 

прогнозирование модели:

 await tf.tidy(() => {
        const bowData = bag_of_words(sentence, words);
        //bowData example: [0,0,1, ... 0,0,0]
        var data = tf.tensor2d(bowData, [1, bowData.length]);
        let predictions = model.predict(data).dataSync();
        
        const confidenceLevel = 0.6;
        var results = [];
        var guesses = [];
        predictions.map((prediction, index) => {
        //This is the prediction output
        console.log(prediction)
          if (prediction > confidenceLevel) {
            results.push([index, prediction]);
          } else {
            if (prediction > (confidenceLevel / 2)) { //to be a guesses should be half of the current confidence
              guesses.push([index, prediction]);
            }
          }
        });
 

Prediction output (see: code above):

 0.10040047764778137
0.10005078464746475
0.10017916560173035
0.1002182886004448
0.09945645183324814
0.10054658353328705
0.09996658563613892
0.0999939814209938
0.09980299323797226
0.09938466548919678
 

These are the predictions for all 10 intents. They are nearly the same value. How do I get real predictions? What did I do wrong?

Please let me know if I need to deliver more context or information. Thanks a lot in advance for your help.