Example #1
0
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


def predict(sentence):
    """
    Predict Intent using Intent classifier
    :param sentence:
    :return:
    """
    bot = Bot.objects.get(name="default")
    predicted = sentence_classifier.predict(sentence)
    print(predicted)
    if predicted["confidence"] < bot.config.get("confidence_threshold", .90):
        return Intent.objects(
    :param extra:
    :return:
    """
    global sentence_classifier

    sentence_classifier = EmbeddingIntentClassifier.load(app.config["MODELS_DIR"])
    synonyms = get_synonyms()
    global entity_extraction
    entity_extraction = EntityExtractor(synonyms)
    app.logger.info("Intent Model updated")

with app.app_context():
    update_model(app,"Modles updated")

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

from app.agents.models import Bot
def predict(sentence):
    """
    Predict Intent using Intent classifier
    :param sentence:
    :return:
    """
    bot = Bot.objects.get(name="default")
    predicted,intents = sentence_classifier.process(sentence)
    app.logger.info("predicted intent %s", predicted)
    if predicted["confidence"] < bot.config.get("confidence_threshold", .90):
        return Intent.objects(intentId=app.config["DEFAULT_FALLBACK_INTENT_NAME"]).first().intentId, 1.0,[]
    else:
        return predicted["intent"], predicted["confidence"],intents[1:]