Kaggle competition: Natural Language Processing with Disaster Tweets
<SOS> metric: meanfscore Kaggle data source: natural-language-processing-with-disaster-tweets<categorify>
train = pd.read_csv("/kaggle/input/nlp-getting-started/train.csv" ).sample(frac=1.)
test = pd.read_csv("/kaggle/input/nlp-getting-started/test.csv" )
train_selected = selector.transform(train_set)
 test_selected = selector.transform(test_set )<create_dataframe>
tokenizer = RobertaTokenizer.from_pretrained('roberta-base')
 X_train = np.array([tokenizer.encode(" ".join(simple_preprocess(text, min_len=2, max_len=15)) ,
add_special_tokens=True,
max_length=40,
pad_to_max_length=True)for text in train["text"]])
 X_test = np.array([tokenizer.encode(" ".join(simple_preprocess(text, min_len=2, max_len=15)) ,
add_special_tokens=True,
max_length=40,
pad_to_max_length=True)for text in test["text"]] )
selected_features = train_set.columns[np.where(selector.ranking_==1)]
train_selected = pd.DataFrame(train_selected,columns=selected_features)
 test_selected = pd.DataFrame(test_selected,columns=selected_features )<compute_train_metric>
input_ids = Input(( 40,), dtype=int32)
 lm = TFRobertaModel.from_pretrained('roberta-base')
 sequence, cls = lm(input_ids)
 mean_pooling = GlobalAveragePooling1D()(sequence)
 max_pooling = GlobalMaxPooling1D()(sequence)
 pooling = concatenate([mean_pooling, max_pooling])
 dropout = Dropout(0.5, name="dropout" )(pooling)
 classification = Dense(1, activation="sigmoid", kernel_initializer=glorot_normal(seed=1), bias_initializer=glorot_normal(seed=1), name="classification" )(pooling)
 model = Model(input_ids, classification)
 plot_model(model )
model_results = cv_model(train_selected,train_labels,model,'RF-SEL',model_results )<compute_test_metric>
def rate(epoch):
return 1.5e-5/(epoch + 1)
 scheduler = LearningRateScheduler(rate)
 model.compile(optimizer=Adam(beta_1=0.9, beta_2=0.999),
loss="binary_crossentropy",
metrics=["accuracy"])
 log = model.fit(X_train, train["target"].values,
callbacks=[scheduler],
batch_size=12,
epochs=3,
verbose=1 )
<choose_model_class><EOS> 
test["proba"] = model.predict(X_test)
 test["target"] = test["proba"].apply(lambda p: int(p > 0.5))
test[["id", "target"]].to_csv("/kaggle/working/submission.csv", index=False )