1
$\begingroup$

I'm developing a chatbot, and to get the answer I'm using the Naive Bayes classifier by sorting the questions and answers. For those who want to see the whole project code and more definitions follow the link of GitHub

To develop I am using the TextBlob library for python, the problem is that when training my classifier it is always returning the same message, regardless of the input I use. The message is:

"Tudo bom?"

I still can not identify the problem, I do not know if the problem is in the way my data is willing to perform the training or if it is the way I am training the classifier.

My class that performs the sorting process is this:

#encoding: utf-8
#!/usr/bin/env python
from textblob.classifiers import NaiveBayesClassifier
from textblob import TextBlob
import logging

class Talk(object):
    """The Talk class is responsible for returning the response
    Based on the information exported. Using the classification
    According to Bayes' theorem
    """
    def __init__(self):
        """
        Class builder

        Cl -> Stores the classifier
        Accuracy -> Stores the accuracy of the algorithm
        """
        self.__cl = None
        self.__accuracy = 0


    def train(self, train_set):
        """
        Train with the list of information consisting of phrases and their
        Respective classifications:
        """

        logging.debug('Inicia treinamento da previsão de intenção')
        self.__cl = NaiveBayesClassifier(train_set)
        logging.debug('Treinamento da previsão de intenção finalizado')

    def test(self, test_set):
        """
        Performs tests with the list of information formed
        Of sentences and their respective classification to obtain the accuracy:
        """

        logging.debug('Inicia teste da previsão de intenção')
        self.__accuracy = self.__cl.accuracy(test_set)
        logging.debug('Teste da previsão de intenção finalizado')
        logging.info('Precisão da previsão: {}'.format(self.__accuracy))

    def response(self, phrase):
        """
        Returns the phrase response according to the created classifier
        """
        logging.debug('Analisa a frase "{}"'.format(phrase))
        blob = TextBlob(phrase,classifier=self.__cl)
        result = blob.classify()
        logging.debug('Resposta: "{}"'.format(result))
        return result

Follow the link in my file with training information and test data

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.