def main(): # create instance of config config = Config() dev = CoNLLDataset(config.filename_dev, config.processing_word, config.processing_tag, config.max_iter) train = CoNLLDataset(config.filename_train, config.processing_word, config.processing_tag, config.max_iter) test = CoNLLDataset(config.filename_test, config.processing_word, config.processing_tag, config.max_iter) predict = CoNLLDataset("data/source_data.txt", config.processing_word, config.max_iter) max_sequence_length = max(max([len(seq[0]) for seq in train]), max([len(seq[0]) for seq in dev]), max([len(seq[0]) for seq in test]), max([len(seq[0]) for seq in predict])) max_word_length = max( max([len(word[0]) for seq in train for word in seq[0]]), max([len(word[0]) for seq in test for word in seq[0]]), max([len(word[0]) for seq in dev for word in seq[0]])) print(max_word_length, max_sequence_length) model = NERModel(config, max_word_length, max_sequence_length) model.build() model.restore_session(config.dir_model) model.run_predict(predict)
def main(predict_file,save_file): # create instance of config config = Config() predict=CoNLLDataset(predict_file, config.processing_word, config.max_iter) max_sequence_length = max([len(seq[0]) for seq in predict]) max_word_length = max([len(word[0]) for seq in predict for word in seq[0]]) print(max_word_length, max_sequence_length) model = NERModel(config, max_word_length, max_sequence_length) model.build() model.restore_session(config.dir_model) model.run_predict(predict,save_file)
def BacNer(dir_path,save_file_path): if os.path.exists(save_file_path): pass else: os.mkdir(save_file_path) file_list=os.listdir(dir_path) for file in file_list: file_path=os.path.join(dir_path,file) save_file=os.path.join(save_file_path,file) config = Config() predict = CoNLLDataset(file_path, config.processing_word, config.max_iter) max_sequence_length = max([len(seq[0]) for seq in predict]) max_word_length = max([len(word[0]) for seq in predict for word in seq[0]]) model = NERModel(config, max_word_length, max_sequence_length) model.build() model.restore_session(config.dir_model) model.run_predict(predict, save_file) tf.reset_default_graph()