def start_predict(self): # get predicting parameters model_name = str(self.ui.combobox_model.currentText()) tweets_file = self.ui.textbox_tweets_file.text() header_included = self.ui.checkbox_header.isChecked() random_tweets = self.ui.spinbox_rand_tweets.value() # check for file validity try: Utils.file_validation(tweets_file, 'Tweet') except Exception as ex: Utils.show_msg(text=ex.args[0], title="Input Error") return # reset values of widgets self.reset_form() # disable all widgets self.disable_widgets(True) self.model_callback = CallBackMultiPredictNNet( self.update_batch_progress, self.update_tweet_progress, random_tweets) self.predictor = MultiPredictor(model_name, self.model_callback, tweets_file, header_included, random_tweets) # create a thread for predictor self.pred_thread = ModelPredictorThread(self.predictor) self.pred_thread.finished.connect(self.on_predict_finished) self.pred_thread.start()
def start_predict(self): # get predicting parameters model_name = str(self.ui.combobox_model.currentText()) bot_file = self.ui.textbox_bot_file.text() human_file = self.ui.textbox_human_file.text() bot_tweets = self.ui.spinbox_bot_tweets.value() human_tweets = self.ui.spinbox_human_tweets.value() total_tweets = bot_tweets + human_tweets # check for file validity try: Utils.file_validation(bot_file, 'Tweet') Utils.file_validation(human_file, 'Tweet') except Exception as ex: Utils.show_msg(text=ex.args[0], title="Input Error") return # reset values of widgets self.reset_form() # disable all widgets self.disable_widgets(True) self.model_callback = CallBackMultiPredictNNet( self.update_batch_progress, self.update_tweet_progress, total_tweets) self.predictor = ModelTestPredictor(model_name, self.model_callback, bot_file, human_file, bot_tweets, human_tweets) # create a thread for predictor self.pred_thread = ModelPredictorThread(self.predictor) self.pred_thread.finished.connect(self.on_predict_finished) self.pred_thread.start()
def export_finished(self): if self.export_thread.is_success(): Utils.show_msg(text="Exporting Complete!", title="Successful", msg_type=QMessageBox.Information) os.startfile(self.export_thread.excel_path) else: Utils.show_msg(text=self.export_thread.error, title="Error", msg_type=QMessageBox.Critical)
def on_train_finished(self): if self.model_thread.is_success(): if self.stop_requested: self.log.enable_log() self.log.write_log('Stopped Process Done Successfully!') else: self.ui.btn_save.setDisabled(False) self.log.write_log('Training Process Completed Successfully!') else: Utils.show_msg(text=self.model_thread.error, title="Error") self.change_widgets_disabled(False)
def on_predict_finished(self): self.disable_widgets(False) if not self.need_stop: if self.pred_thread.is_success(): self.classify_tweets() else: Utils.show_msg(text=self.pred_thread.error, title="Error") self.ui.btn_save.setDisabled(True) self.ui.groupbox_threshold.setDisabled(True) else: self.reset_form() self.ui.btn_save.setDisabled(True) self.ui.groupbox_threshold.setDisabled(True)
def on_predict_finished(self): if self.pred_thread.is_success(): bot_sim_score = self.predictor.get_similarity_score() bot_percentage = int(round(bot_sim_score * 100)) human_percentage = 100 - bot_percentage # calculate the max value for ui scores_arr = [bot_percentage, human_percentage] group_boxes_arr = [self.ui.groupbox_bot, self.ui.groupbox_human] max_element = np.argmax(scores_arr) min_element = 1-max_element self.update_ui_scores(bot_percentage, human_percentage) group_boxes_arr[max_element].setDisabled(False) group_boxes_arr[min_element].setDisabled(True) else: Utils.show_msg(text=self.pred_thread.error, title="Error") self.ui.btn_start.setDisabled(False) self.ui.textbox_tweet.setReadOnly(False) self.ui.combobox_model.setDisabled(False)
def start_train(self): # get training parameters embedding_file = self.ui.textbox_embed.text() bot_file = self.ui.textbox_bot.text() human_file = self.ui.textbox_human.text() train_split = self.ui.slider_train.value() / 100.0 test_split = 1 - train_split val_split = self.ui.slider_val.value() / 100.0 epoches = self.ui.spinbox_epoches.value() batch_size = self.ui.spinbox_batch.value() addit_feat_enabled = self.ui.checkbox_additional_feats.isChecked() early_stop = self.ui.spinbox_earlystop.value() # get dataset config from combobox gen_method = str(self.ui.combobox_gen_method.currentText()) if gen_method == "User Grouping": dataset_config = DatasetConfig.USER_STATE elif gen_method == "Random Pairing": dataset_config = DatasetConfig.RANDOM_STATE # Check for early stop validity if early_stop > epoches: Utils.show_msg( text= "Can not Insert Early Stop Epochs\nThat Bigger Than Training Epochs Number!", title="Input Error") return # check for files validity try: Utils.file_validation(embedding_file, 'Embedding') Utils.file_validation(bot_file, 'Bot') Utils.file_validation(human_file, 'Human') except Exception as ex: Utils.show_msg(text=ex.args[0], title="Input Error") return # reset progressbars self.ui.progressbar_epoches.setValue(0) self.ui.progressbar_batch.setValue(0) # reset graphs self.reset_graphs() # disable unnecessery widgets when starting training self.change_widgets_disabled(True) self.ui.btn_save.setDisabled(True) self.log.write_log("Start pre-training phase...") # create model instance with all parameters self.custom_callback = CallBackTrainNNet(self.log, self.draw_graphs, self.batch_graphs_clear, self.update_progressbars, self.get_status_stopped, self.MAX_BATCH, self.update_batch_range) self.model = ModelTrainer(logger=self.log, embedding_file=embedding_file, bots_file=bot_file, human_file=human_file, validation_split=val_split, test_split=test_split, batch_size=batch_size, epochs=epoches, additional_feats_enabled=addit_feat_enabled, early_stopping=early_stop, dataset_config=dataset_config, custom_callback=self.custom_callback) # create a thread for training phase self.model_thread = ModelTrainerThread(self.model) self.model_thread.finished.connect(self.on_train_finished) self.model_thread.start() # run the thread to start training