Пример #1
0
def test_entity_train(name):
    chubot = ChuBotBrain(name, language='vi')
    chubot.load_data(
        "/media/nvidia/ssd/catkin_ws/src/chu_bot_source/chubot/usingdata/full_train.json"
    )
    # chubot.load_data("usingdata/vi_nlu_ask_way.json")
    meta = chubot.train_nercrf()
Пример #2
0
def test_train_models():
    botname = "greet_en"
    nludatafile = "/media/nvidia/ssd/catkin_ws/src/chu_bot_source/chubot/data/nlu_greet.json"

    chubot = ChuBotBrain(botname, language='en')
    chubot.load_data(nludatafile)
    meta = chubot.train()
    print(meta)
Пример #3
0
def test_intent_classification():
    nludatafile = "/media/nvidia/ssd/catkin_ws/src/chu_bot_source/chubot/data/nlu_greet.json"

    chubot = ChuBotBrain("greet_en", language='en')
    chubot.load_data(nludatafile)
    meta = chubot.train_intent_classification()
    print(meta)

    inmessage = "sad but great. want a dog picture"
    intent_probs = chubot.predict_intent(inmessage)
    print(intent_probs)
Пример #4
0
def test_nercrf():
    nludatafile = "/media/nvidia/ssd/catkin_ws/src/chu_bot_source/chubot/data/nlu_greet.json"

    chubot = ChuBotBrain("greet_en", language='en')
    chubot.load_data(nludatafile)

    meta = chubot.train_nercrf()
    print(meta)

    inmessage = "a bird and a dog"

    tagged_entities = chubot.predict_entity(inmessage)

    print(tagged_entities)
Пример #5
0
def test_intent_train(name):
    chubot = ChuBotBrain(name, language='vi')
    chubot.load_data("data/train.json")
    # chubot.load_data("data/vi_nlu_ask_way.json")
    meta = chubot.train_intent_classification()
    test_link = "data/test.txt"
    with open(test_link,'r',encoding='utf=8') as f:
        rows = f.readlines()
    intent_list_test = []
    intent_list_result = []
    data_list_test = []
    for row in rows:
        parts = row.split(',')
        intent_list_test.append(encode_intent(parts[0]))
        data_list_test.append(parts[1])
    for data in data_list_test:
        responses = chubot.predict_intent(data)
        (prob, intent) = responses[0]
        intent_list_result.append(encode_intent(intent))
    print("accuracy",accuracy_score(intent_list_test,intent_list_result))
Пример #6
0
def retrieve_image_deplicated(action_args, **kwargs):

    #TODO make a synonym mapper class

    def get_default_synonym(entity, value, entity_ldict):
        for ent in entity_ldict:
            if entity == ent['entity']:
                if value in ent['synonyms']:
                    return ent['default_value']

    nludatafile = "data/nlu_greet.json"

    chubot = ChuBotBrain("greet_en", language='en')
    chubot.load_data(nludatafile)
    entity_synonyms = chubot.entity_synonyms

    #handle arguments
    arg_entity = action_args["entity"]
    arg_value_type = action_args["value"]

    active_entities = kwargs["active_entities"]

    for ent in active_entities:
        if ent['entity'] == arg_entity:
            if arg_value_type == "value":
                arg_value = ent['value']
            elif arg_value_type == "default_value":
                arg_value = get_default_synonym(ent['entity'], ent['value'], entity_synonyms)

    print(arg_value)
    # print('http://shibe.online/api/{}?count=1&urls=true&httpsUrls=true'.format(arg_value))
    r = requests.get('http://shibe.online/api/{}?count=1&urls=true&httpsUrls=true'.format(arg_value))

    response = r.content.decode()
    response = response.replace('["', '')
    response = response.replace('"]', '')

    return response
Пример #7
0
def test_entity_train(name):
    chubot = ChuBotBrain(name, language='vi')
    chubot.load_data("usingdata/full_train.json")
    # chubot.load_data("usingdata/vi_nlu_ask_way.json")
    meta = chubot.train_nercrf()
Пример #8
0
def create_model(name):
    chubot = ChuBotBrain(name, language='vi')
    chubot.load_data("usingdata/full_train.json")
    # chubot.load_data("usingdata/vi_nlu_ask_way.json")
    meta = chubot.train()