<jupyter_start><jupyter_text>both datasets 1 and 2 are imbalanced since the number of non-clickbait tweets in datasets 1 and 2 are 2.1 and 3.1 times bigger than the number of clickbait tweets respectively.<jupyter_code>#change df_trn and df_val
Tdf["label"] = Tdf.iloc[:,0].apply(clean_up)
l = []
for i in range(len(Tdf)):
  l.append(int(Tdf.iloc[:,0][i]))
Tdf["label"] = l

t = []
for i in range(len(Tdf)):
  t.append(Tdf.iloc[:,1][i][0])
Tdf["text"] = t
Tdf.head()
df_trn, df_val = Tdf, df
df_trn.shape, df_val.shape
# Language model data
data_lm = TextLMDataBunch.from_df(train_df = df_trn, valid_df = df_val, path = "")

# Classifier model data
data_clas = TextClasDataBunch.from_df(path = "", train_df = df_trn, valid_df = df_val, vocab=data_lm.train_ds.vocab, bs=32)

learn = language_model_learner(data_lm, pretrained_model=URLs.WT103_1, drop_mult=0.3)

# train the learner object with learning rate = 1e-2
learn.fit_one_cycle(1, 1e-2)
#Like a computer vision model, we can then unfreeze the model and fine-tune it.
learn.unfreeze()
learn.fit_one_cycle(1, 1e-3)
#Finally we save the encoder to be able to use it for classification in the next section.
learn.save_encoder('ft_enc')
learn = text_classifier_learner(data_clas, drop_mult=0.5)
learn.load_encoder('ft_enc')
learn.fit_one_cycle(2, slice(1e-3,1e-2))
learn.freeze_to(-2)
learn.fit_one_cycle(1, slice(5e-3/2., 5e-3))
preds, targets = learn.get_preds()
predictions = np.argmax(preds, axis = 1)
pd.crosstab(predictions, targets,rownames=['Preds'], colnames=['targets'])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13773222293401666, 'fraction_numerical': 0.02754644458680333, 'mean_word_length': 5.881057268722467, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '486118', 'license': 'MIT', 'n_tokens_mistral': 642, 'n_tokens_neox': 622, 'n_words': 148, 'path': 'Model3_transferLearning.ipynb', 'repo_name': 'ClaireWithGithub/Clickbait-Detection', 'size': '1561'}