Kaggle competition: Ghouls, Goblins, and Ghosts... Boo!
<SOS> metric: categorizationaccuracy Kaggle data source: ghouls,-goblins,-and-ghosts...-boo!<define_variables>
warnings.filterwarnings('ignore' )
pretrain_weighted_1 = glob.glob('.. /input/d-large-roberta-b32-steplr3-drop-tb-rmf-h56-1/*.pt')
 pretrain_weighted_2 = glob.glob('.. /input/d-large-roberta-b32-steplr3-drop-tb-rmf-h56-2/*.pt')
 pretrain_weighted = pretrain_weighted_1 + pretrain_weighted_2<install_modules>
zipfile.ZipFile('/kaggle/input/ghouls-goblins-and-ghosts-boo/train.csv.zip' ).extractall()
zipfile.ZipFile('/kaggle/input/ghouls-goblins-and-ghosts-boo/test.csv.zip' ).extractall()
!nvidia-smi 
<install_modules>
train = pd.read_csv('./train.csv')
 test = pd.read_csv('./test.csv')
!nvidia-smi<create_dataframe>
train2 = pd.get_dummies(train['type'])
 del train['type']
COLOR = pd.get_dummies(train['color'])
 del train['color']
del train['id']
target = pd.DataFrame(train2['Ghost']* 0 + train2['Ghoul'] * 2 + train2['Goblin'] * 1)
 target_GOB = pd.DataFrame(train2['Ghost']* 0 + train2['Ghoul'] * 0 + train2['Goblin'] * 1)
 target = target.rename(columns={'0': 'target'})
 COLOR2 = pd.get_dummies(test['color'])
 del test['color']
ID = test["id"]
del test['id']
test_set = QuestDataset_test(test_tokens, test_masks, test_segments,
test_df['host'].values,
test_df['category'].values,
train_handmade_features)
 test_loader = DataLoader(test_set, batch_size=batch_size, shuffle=False )<choose_model_class>
%matplotlib inline
model = QuestModel6(n_cat, cat_emb, n_host, host_emb, num_labels=30)
 model.cuda()<predict_on_test>
train_c = train.join(COLOR)
 test_c = test.join(COLOR2)
for i, weight in tqdm(enumerate(pretrain_weighted)) :
model.load_state_dict(torch.load(weight))
results.append(predict_result(model, test_loader))<define_variables>
def GOB() :
global y_pred_c
global train
global test
hidden_layer_sizes=(100,)
 activation = 'relu'
solver = 'adam'
batch_size = 'auto'
alpha = 0.0001
random_state = 0
max_iter = 10000
early_stopping = True
train_X = train_c
train_y1 = target_GOB
clf = MLPRegressor(
 hidden_layer_sizes=hidden_layer_sizes,
activation=activation,
solver=solver,
batch_size=batch_size,
alpha=alpha,
random_state=random_state,
max_iter=max_iter, 
)
 clf.fit(train_X, train_y1)
 SAVE_TRAINED_DATA_PATH = 'train1.learn'
joblib.dump(clf, SAVE_TRAINED_DATA_PATH)
 clf1 = joblib.load(SAVE_TRAINED_DATA_PATH)
 test_X1 = test_c
predict_Y1 = clf1.predict(train_X)
 print(predict_Y1)
 y_pred_c = pd.DataFrame(predict_Y1)
 train = train.join(y_pred_c)
 predict_Y1 = clf1.predict(test_X1)
 print(predict_Y1)
 y_pred_c = pd.DataFrame(predict_Y1)
 test = test.join(y_pred_c )
output_roberta = np.zeros(( len(test_set),30))
for result in results:
output_roberta += result
output_roberta /= len(results )<set_options>
dataset = pd.concat([train, test], ignore_index = True)
 ',train.isnull().sum() )
del results, result, test_set, test_loader, model; gc.collect()<set_options>
def lightGBM_k() :
global y_pred_AA
hidden_layer_sizes=(100,)
 activation = 'relu'
solver = 'adam'
batch_size = 'auto'
alpha = 0.0001
random_state = 0
max_iter = 10000
early_stopping = True
train_X = train_k
train_y1 = target_k
clf = MLPRegressor(
 hidden_layer_sizes=hidden_layer_sizes,
activation=activation,
solver=solver,
batch_size=batch_size,
alpha=alpha,
random_state=random_state,
max_iter=max_iter, 
)
 clf.fit(train_X, train_y1)
 SAVE_TRAINED_DATA_PATH = 'train1.learn'
joblib.dump(clf, SAVE_TRAINED_DATA_PATH)
 clf1 = joblib.load(SAVE_TRAINED_DATA_PATH)
 test_X1 = test_k
predict_Y = clf1.predict(test_X1)
 print(predict_Y)
 predict_Y = np.round(predict_Y, decimals=1)
 predict_Y1 = np.round(predict_Y)
 print(predict_Y1)
 y_pred_AA = predict_Y1
print("学習データの精度: {:.3f}".format(clf.score(train_X, train_y1)))
 print("テスト結果の精度: {:.3f}".format(clf.score(test_X1, predict_Y1)) )
torch.cuda.empty_cache()<define_variables>
def syuunou() :
global s_c
global y_pred_AA
y_pred_z:str=[]
for n in range(len(y_pred_AA)) :
if y_pred_AA[n]==0:
y_pred_z.append('Ghost')
 if y_pred_AA[n]==1:
y_pred_z.append('Ghoul')
 if y_pred_AA[n]==2:
y_pred_z.append('Goblin')
 s_c= pd.DataFrame({"id": ID_black, "type": y_pred_z} )
SEED = 1414
DATA_DIR = ".. /input/google-quest-challenge/"
WORK_DIR = ".. /working/"
BERT_VOCAB_PATH = ".. /input/xlnetlargecased/xlnet_cased_L-24_H-1024_A-16/spiece.model"
BERT_MODEL_PATH = ".. /input/xlnetlargecased/xlnet_cased_L-24_H-1024_A-16/xlnet_model.ckpt.index"
BERT_CONFIG_PATH = ".. /input/xlnetlargecased/xlnet_cased_L-24_H-1024_A-16/xlnet_config.json"
input_columns = ['question_title', 'question_body', 'answer']
seed_everything(SEED)
 batch_size = 32<load_from_csv>
submission = rows
submission.to_csv("submission6.csv", index=False )