def load(cls, data_store): if type(data_store) is LocalFileSystem: matrix = data_store.read_pickle_file( filename=SIMILARITY_MATRIX_FILENAME) movie_names = data_store.read_pickle_file( filename=MOVIE_LIST_FILENAME) if type(data_store) is S3DataStore: data_store.download_file(SIMILARITY_MATRIX_FILENAME, "/tmp/" + SIMILARITY_MATRIX_FILENAME) data_store.download_file(MOVIE_LIST_FILENAME, "/tmp/" + MOVIE_LIST_FILENAME) temp_data_store = LocalFileSystem("/tmp/") matrix = temp_data_store.read_pickle_file( filename=SIMILARITY_MATRIX_FILENAME) movie_names = temp_data_store.read_pickle_file( filename=MOVIE_LIST_FILENAME) return ImdbRecSys(matrix=matrix, movie_names=movie_names)
def load(cls, data_store): if type(data_store) is LocalFileSystem: word_class_dict = data_store.read_pickle_file( filename=WORD_CLASS_DICT_FILENAME) net = tflearn.input_data( shape=[None, int(word_class_dict["num_input"])]) net = tflearn.fully_connected(net, 8) net = tflearn.fully_connected(net, 8) net = tflearn.fully_connected(net, int(word_class_dict["num_output"]), activation='softmax') net = tflearn.regression(net) model = tflearn.DNN(net) dl_model = data_store.read_dl_model(data=model, filename=MODEL_FILENAME) if type(data_store) is S3DataStore: data_store.download_file(MODEL_FILENAME + ".index", "/tmp/" + MODEL_FILENAME + ".index") data_store.download_file(MODEL_FILENAME + ".meta", "/tmp/" + MODEL_FILENAME + ".meta") data_store.download_file( MODEL_FILENAME + ".data-00000-of-00001", "/tmp/" + MODEL_FILENAME + ".data-00000-of-00001") data_store.download_file(WORD_CLASS_DICT_FILENAME, "/tmp/" + WORD_CLASS_DICT_FILENAME) temp_data_store = LocalFileSystem("/tmp/") word_class_dict = temp_data_store.read_pickle_file( filename=WORD_CLASS_DICT_FILENAME) net = tflearn.input_data( shape=[None, int(word_class_dict["num_input"])]) net = tflearn.fully_connected(net, 8) net = tflearn.fully_connected(net, 8) net = tflearn.fully_connected(net, int(word_class_dict["num_output"]), activation='softmax') net = tflearn.regression(net) model = tflearn.DNN(net) dl_model = temp_data_store.read_dl_model(data=model, filename=MODEL_FILENAME) return ChatbotModel(words=word_class_dict["words"], classes=word_class_dict["classes"], num_input=word_class_dict["num_input"], num_output=word_class_dict["num_output"], dl_model=dl_model, response=word_class_dict["response"])