Exemple #1
0
    def test_entity_extractor_basic(self):
        x = ['what is the weather in tokyo', 'what is the weather', 'what is the weather like in kochi']
        y = [{'intent': 'weather', 'place': 'tokyo'}, {'intent': 'weather', 'place': 'here'}, {'intent': 'weather', 'place': 'kochi'}]

        ex = EntityExtractor()
        ex.fit(x, y)

        x_test = 'what is the weather in london like'
        assert ex.predict(x_test) == {'intent': 'weather', 'place': 'london'}
def test_entity_extractor_server_get():
    x = ['what is the weather in tokyo', 'what is the weather', 'what is the weather like in kochi']
    y = [{'intent': 'weather', 'place': 'tokyo'}, {'intent': 'weather', 'place': 'here'}, {'intent': 'weather', 'place': 'kochi'}]
    ex = EntityExtractor()
    ex.fit(x, y)
    ex_serialized = ex.serialize()
    server = NLUServer(ex).serve(test=True)
    r = server.requests.get("/models/entity_extractor/predict?input=what is the weather in london")
    assert r.json() == {'intent': 'weather', 'place': 'london'}
    r = server.requests.get("/models/entity_extractor/config")
    assert r.json() == json.loads(json.dumps(ex_serialized))
def test_entity_extractor_server_train_post():
    X = ['what is the weather in tokyo', 'what is the weather', 'what is the weather like in kochi']
    Y = [{'intent': 'weather', 'place': 'tokyo'}, {'intent': 'weather', 'place': 'here'}, {'intent': 'weather', 'place': 'kochi'}]
    server = NLUServer().serve(test=True)
    ex = EntityExtractor()
    ex.fit(X, Y)
    r = server.requests.get("/models/entity_extractor/train", json={"data":{"inputs":X, "targets":Y}})
    assert r.status_code == 200
    test_inp = 'what is the weather in london'
    time.sleep(2)
    r = server.requests.get("/models/entity_extractor/predict?input={}".format(test_inp))
    assert r.json() == ex.predict(test_inp)
def test_entity_extractor_server_train_get():
    X = ['what is the weather in tokyo', 'what is the weather', 'what is the weather like in kochi']
    Y = [{'intent': 'weather', 'place': 'tokyo'}, {'intent': 'weather', 'place': 'here'}, {'intent': 'weather', 'place': 'kochi'}]
    server = NLUServer().serve(test=True)
    ex = EntityExtractor()
    ex.fit(X, Y)
    for x, y in zip(X, Y):
        r = server.requests.get("/models/entity_extractor/train?input={}&target={}".format(x, urllib.parse.quote(json.dumps(y))))
        assert r.status_code == 200
    test_inp = 'what is the weather in london'
    time.sleep(2)
    r = server.requests.get("/models/entity_extractor/predict?input={}".format(test_inp))
    assert r.json() == ex.predict(test_inp)
Exemple #5
0
    def test_entity_extractor_serialization(self):
        x = [
            'what is the weather in tokyo', 'what is the weather',
            'what is the weather like in kochi'
        ]
        y = [{
            'intent': 'weather',
            'place': 'tokyo'
        }, {
            'intent': 'weather',
            'place': 'here'
        }, {
            'intent': 'weather',
            'place': 'kochi'
        }]

        ex1 = EntityExtractor()
        ex1.fit(x, y)

        config = ex1.serialize()
        ex2 = EntityExtractor.deserialize(config)

        test_inputs = ['what is the weather in london like']

        for test_input in test_inputs:
            ex1_out = ex1.predict(test_input)
            ex2_out = ex2.predict(test_input)
            ex2.predict(test_input, return_scores=True)  # TODO
            assert ex1_out == ex2_out
Exemple #6
0
    def test_entity_extractor_serialization(self):
        x = ['what is the weather in tokyo', 'what is the weather', 'what is the weather like in kochi']
        y = [{'intent': 'weather', 'place': 'tokyo'}, {'intent': 'weather', 'place': 'here'}, {'intent': 'weather', 'place': 'kochi'}]

        ex1 = EntityExtractor()
        ex1.fit(x, y)

        config = ex1.serialize()
        ex2 = EntityExtractor.deserialize(config)

        test_inputs = ['what is the weather in london like']

        for test_input in test_inputs:
            ex1_out = ex1.predict(test_input)
            ex2_out = ex2.predict(test_input)
            assert ex1_out == ex2_out
Exemple #7
0
X_WEATHER = [
    'what is the weather in tokyo', 'weather germany',
    'what is the weather like in kochi'
]
Y_WEATHER = [{
    'intent': 'weather',
    'place': 'tokyo'
}, {
    'intent': 'weather',
    'place': 'germany'
}, {
    'intent': 'weather',
    'place': 'kochi'
}]

EX_WEATHER = EntityExtractor()
EX_WEATHER.fit(X_WEATHER, Y_WEATHER)

X_TAXI = [
    'book a cab to kochi ', 'need a ride to delhi',
    'find me a cab for manhattan', 'call a taxi to calicut'
]
Y_TAXI = [{
    'service': 'cab',
    'destination': 'kochi'
}, {
    'service': 'ride',
    'destination': 'delhi'
}, {
    'service': 'cab',
    'destination': 'manhattan'