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
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_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