コード例 #1
0
def train_intent_classifier(intents):
    """
    Train intent classifier model
    :param intents:
    :return:
    """
    X = []
    y = []
    for intent in intents:
        training_data = intent.trainingData
        for example in training_data:
            X.append(example.get("text"))
            y.append([str(intent.id)])

    PATH = "{}/{}".format(app.config["MODELS_DIR"],
                          app.config["INTENT_MODEL_NAME"])
    intent_classifier = IntentClassifier()
    intent_classifier.train(X, y, outpath=PATH, verbose=False)
コード例 #2
0
ファイル: tasks.py プロジェクト: nithesh1212/finalcbot
def train_intent_classifier(intents, botId):
    """
    Train intent classifier model
    :param intents:
    :return:
    """
    X = []
    y = []
    for intent in intents:
        training_data = intent.trainingData
        for example in training_data:
            if example.get("text").strip() == "":
                continue
            X.append(example.get("text"))
            y.append(str(intent.id))

    PATH = "{}/{}".format(app.config["MODELS_DIR"], botId + '.model')
    print(PATH)
    intent_classifier = IntentClassifier()
    intent_classifier.train(X, y, outpath=PATH, verbose=False)
コード例 #3
0
    elif "DELETE" in type:
        response = requests.delete(url)
    else:
        raise Exception("unsupported request method.")
    result = json.loads(response.text)
    print(result)
    return result


from app.nlu.intent_classifer import IntentClassifier

with app.app_context():
    PATH = "{}/{}".format(app.config["MODELS_DIR"],
                          app.config["INTENT_MODEL_NAME"])

    sentence_classifier = IntentClassifier()
    sentence_classifier.load(PATH)
    print("Intent Model loaded.")


def update_model(app, message, **extra):
    sentence_classifier.load(PATH)
    print("Intent Model updated")


from app.nlu.tasks import model_updated_signal
model_updated_signal.connect(update_model, app)

from app.agents.models import Bot

コード例 #4
0
# Loading ML Models at app startup
from app.nlu.intent_classifer import IntentClassifier

'''with app.app_context():
    PATH = "{}/{}".format(app.config["MODELS_DIR"],
                          app.config["INTENT_MODEL_NAME"])

    sentence_classifier = IntentClassifier()
    sentence_classifier.load(PATH)

    synonyms = get_synonyms()
    entity_extraction = EntityExtractor(synonyms)
    app.logger.info("Intent Model loaded.")'''

sentence_classifier = IntentClassifier()

# Request Handler
@endpoint.route('/v1', methods=['POST'])
def api():
    """
    Endpoint to converse with chatbot.
    Chat context is maintained by exchanging the payload between client and bot.

    sample input/output payload =>

    {
      "currentNode": "",
      "complete": false,
      "parameters": [],
      "extractedParameters": {},