Kaggle competition: Tweet Sentiment Extraction
numeric_feats = df.dtypes[df.dtypes != "object"].index
skewed_feats = df[numeric_feats].apply(lambda x: x.skew() ).sort_values(ascending=False)
 skewed_feats<feature_engineering>
%%time
!python.. /input/tweet-inference-scripts/inference_distilbert.py
high_skew = skewed_feats[skewed_feats > 0.5]
skew_index = high_skew.index
for i in skew_index:
df[i] = boxcox1p(df[i], boxcox_normmax(df[i] + 1)) 
<categorify>
%%time
!python.. /input/tweet-inference-scripts/inference_bert_wwm.py
final_features = pd.get_dummies(df ).reset_index(drop=True)
 print('Features size:', df.shape)
 final_features.head()<prepare_x_and_y>
%%time
!python.. /input/tweet-inference-scripts/inference_albert.py
nrow_train = train.shape[0]
X_train = final_features[:nrow_train]
X_test = final_features[nrow_train:]
Y = train['SalePrice']<define_search_space>
%%time
!pip install /kaggle/input/bertweet-libs/sacrebleu-1.4.10-py3-none-any.whl
!cp -R /kaggle/input/bertweet-libs/fairseq-0.9.0/fairseq-0.9.0 /kaggle/working
!cp -R /kaggle/input/bertweet-libs/fastBPE-0.1.0/fastBPE-0.1.0/ /kaggle/working
!pip install /kaggle/working/fairseq-0.9.0/
!pip install /kaggle/working/fastBPE-0.1.0/
!python.. /input/tweet-inference-scripts/inference_bertweet.py
e_alphas = [0.0001, 0.0002, 0.0003, 0.0004, 0.0005, 0.0006, 0.0007]
e_l1ratio = [0.8, 0.85, 0.9, 0.95, 0.99, 1]
alphas_alt = [14.5, 14.6, 14.7, 14.8, 14.9, 15, 15.1, 15.2, 15.3, 15.4, 15.5]
alphas2 = [5e-05, 0.0001, 0.0002, 0.0003, 0.0004, 0.0005, 0.0006, 0.0007, 0.0008]
kfolds = KFold(n_splits=10, shuffle=True, random_state=42)
 ridge = make_pipeline(RobustScaler() , RidgeCV(alphas=alphas_alt, cv=kfolds))
lasso = make_pipeline(RobustScaler() , LassoCV(max_iter=1e7,
alphas=alphas2,random_state=42, cv=kfolds))
elasticnet = make_pipeline(RobustScaler() , ElasticNetCV(max_iter=1e7,
alphas=e_alphas, cv=kfolds, l1_ratio=e_l1ratio)) 
<train_model>
%%time
!python.. /input/tweet-inference-scripts/inference_roberta_anton.py
print('Elasticnet')
 elastic_model = elasticnet.fit(X_train, Y)
 print('Lasso')
 lasso_model = lasso.fit(X_train, Y)
 print('Ridge')
 ridge_model = ridge.fit(X_train, Y )<predict_on_test>
%%time
!python.. /input/tweet-inference-scripts/inference_roberta_large_hiki.py
def blend_models(X):
return(( elastic_model.predict(X)) +(lasso_model.predict(X)) +(ridge_model.predict(X)))/3 
<load_from_csv>
%%time
!python.. /input/tweet-inference-scripts/inference_roberta_hiki.py
<save_to_csv><EOS> 
def string_from_preds_char_level(texts, preds):
selected_texts = []
n_models = len(preds)
 for idx in range(len(texts)) :
data = texts[idx]
start_probas = np.mean(
 [preds[i][0][idx] for i in range(n_models)], 0)
 end_probas = np.mean(
 [preds[i][1][idx] for i in range(n_models)], 0)
 start_idx = np.argmax(start_probas)
 end_idx = np.argmax(end_probas)
 if end_idx < start_idx:
selected_text = data
else:
selected_text = data[start_idx: end_idx]
selected_texts.append(selected_text.strip())
 return selected_texts
df_test = pd.read_csv(
 '.. /input/tweet-sentiment-extraction/test.csv' ).fillna('')
 df_test['selected_text'] = ''
sub = pd.read_csv(
 '.. /input/tweet-sentiment-extraction/sample_submission.csv')
 preds_1 = np.load('preds_char_test_cnn_0_2.npy')
 preds_2 = np.load('preds_char_test_cnn_1_2.npy')
 preds_3 = np.load('preds_char_test_wavenet_2.npy')
 preds_4 = np.load('preds_char_test_wavenet_6_2.npy')
 test_preds =(preds_1 + preds_2 + preds_3 + preds_4)/ 4
selected_texts = string_from_preds_char_level(
 df_test['text'].values, test_preds)
 sub['selected_text'] = selected_texts
df_test['selected_text'] = selected_texts
sub.to_csv('submission.csv', index=False )