args=config, use_cuda=torch.cuda.is_available()) train_df, eval_df = train_test_split(full, test_size=0.1, random_state=SEED * i) model.train_model(train_df, eval_df=eval_df, precision=precision, recall=recall, f1=f1) model = ClassificationModel(MODEL_TYPE, config["best_model_dir"], args=config, use_cuda=torch.cuda.is_available()) predictions, raw_outputs = model.predict(dev_sentences) dev_preds[:, i] = predictions print("Completed Fold {}".format(i)) # select majority class of each instance (row) dev_predictions = [] for row in dev_preds: row = row.tolist() dev_predictions.append(int(max(set(row), key=row.count))) dev["predictions"] = dev_predictions print("Precision: ", precision(dev['labels'].tolist(), dev['predictions'].tolist())) print("Recall: ", recall(dev['labels'].tolist(), dev['predictions'].tolist()))
num_labels=1, use_cuda=torch.cuda.is_available()) train_df, eval_df = train_test_split(train, test_size=0.2, random_state=SEED * i) model.train_model(train_df, eval_df=eval_df, mae=mean_absolute_error) model = ClassificationModel(MODEL_TYPE, config["best_model_dir"], args=config, num_labels=1, use_cuda=torch.cuda.is_available()) for dev_sentences, test_sentences, dev_preds, test_preds in zip( dev_sentences_list, test_sentences_list, dev_preds_list, test_preds_list): dev_predictions, dev_raw_outputs = model.predict(dev_sentences) test_predictions, test_raw_outputs = model.predict(test_sentences) dev_preds[:, i] = dev_predictions test_preds[:, i] = test_predictions for dev, dev_preds, test, test_preds in zip(dev_list, dev_preds_list, test_list, test_preds_list): dev['predictions'] = dev_preds.mean(axis=1) test['predictions'] = test_preds.mean(axis=1) for dev, test, language in zip(dev_list, test_list, [*languages]): dev["run_id"] = MODEL_NAME test["run_id"] = MODEL_NAME dev = dev[['topic_id', 'tweet_id', "predictions", "run_id"]] test = test[['topic_id', 'tweet_id', "predictions", "run_id"]]
use_cuda=torch.cuda.is_available()) train_df, eval_df = train_test_split(train, test_size=0.1, random_state=SEED * i) model.train_model(train_df, eval_df=eval_df, precision=precision, recall=recall, f1=f1) model = ClassificationModel(MODEL_TYPE, config["best_model_dir"], args=config, use_cuda=torch.cuda.is_available()) # predict Arabic dev ara_test_final_predictions, raw_outputs = model.predict( dev_sentences_list[0]) ara_dev_preds[:, i] = ara_test_final_predictions # predict Bulgarian dev bul_test_final_predictions, raw_outputs = model.predict( dev_sentences_list[1]) bul_dev_preds[:, i] = bul_test_final_predictions # predict English dev eng_test_final_predictions, raw_outputs = model.predict( dev_sentences_list[2]) eng_dev_preds[:, i] = eng_test_final_predictions # predict Arabic test ara_test_predictions, raw_outputs = model.predict(test_sentences_list[0]) ara_test_preds[:, i] = ara_test_predictions