Kaggle competition: Natural Language Processing with Disaster Tweets
<SOS> metric: meanfscore Kaggle data source: natural-language-processing-with-disaster-tweets<choose_model_class>
plt.rcParams.update({'font.size': 14})
 train = pd.read_csv("/kaggle/input/nlp-getting-started/train.csv")
 test = pd.read_csv("/kaggle/input/nlp-getting-started/test.csv")
 sub_sample = pd.read_csv("/kaggle/input/nlp-getting-started/sample_submission.csv" )
class ModelBuilder:
def __init__(self,random_state=666):
self.random_state=random_state
def SimpleNeuralNet(self,shape=None,learning_rate=0.001,output_shape=206):

 model = tf.keras.models.Sequential([
L.InputLayer(input_shape=shape),
L.BatchNormalization() ,
L.Dropout(0.5),
tfa.layers.WeightNormalization(L.Dense(512,kernel_initializer="he_normal")) ,
L.BatchNormalization() ,
L.Activation(tf.nn.leaky_relu),
L.Dropout(0.5),
tfa.layers.WeightNormalization(L.Dense(256,kernel_initializer="he_normal")) ,
L.BatchNormalization() ,
L.Activation(tf.nn.leaky_relu),
L.Dropout(0.3),
tfa.layers.WeightNormalization(L.Dense(output_shape,activation="sigmoid",kernel_initializer="he_normal"))
])
 model.compile(optimizer= tf.keras.optimizers.Adam(lr=learning_rate),loss="binary_crossentropy",metrics=["binary_crossentropy"])
 return model
def transfer_weight(self,model_source,model_dest):
for i in range(len(model_source.layers[:-1])) :
model_dest.layers[i].set_weights(model_source.layers[i].get_weights())
 return model_dest
def metric(self,train,predict):
metrics=[]
for col in range(train.shape[1]):
metrics.append(log_loss(train.iloc[:,col],predict[:,col],labels=[0,1]))
return np.mean(metrics )<compute_test_metric>
train.duplicated().sum()
data_prepare = MoaDataPrepare(train_data,test_data )<choose_model_class>
train = train.drop_duplicates().reset_index(drop=True )
model_builder = ModelBuilder(random_state=606 )<prepare_x_and_y>
train.target.value_counts()
transfer_data = data_prepare.get_train()
transfer_data.loc[:,'sig_id'] = train_data.sig_id
transfer_data = transfer_data.merge(train_targets_nonscored,how='inner',on='sig_id')
 transfer_data = transfer_data.drop('sig_id',axis=1)
 Y_transfer = transfer_data.loc[:,train_targets_nonscored.columns[1:]]
transfer_data = transfer_data.loc[:,data_prepare.get_train().columns]<split>
train.isnull().sum()
x_train,x_test,y_train,y_test = train_test_split(transfer_data,Y_transfer,test_size=0.2,random_state = 101 )<choose_model_class>
test.isnull().sum()
model = model_builder.SimpleNeuralNet(shape =(transfer_data.shape[1],),output_shape = 402 )<choose_model_class>
test.isnull().sum()
save_weight = tf.keras.callbacks.ModelCheckpoint('model.learned.hdf5',save_best_only=True,save_weights_only=True,monitor = 'val_loss',mode='min')
 reduce_lr_loss = ReduceLROnPlateau(monitor='val_loss', factor=0.1, patience=3, verbose=1, epsilon=1e-4, mode='min')
 early = EarlyStopping(monitor='val_loss',patience=5,mode='min' )<train_model>
print(train.keyword.nunique() , test.keyword.nunique())
 print(set(train.keyword.unique())- set(test.keyword.unique()))
model.fit(x_train,y_train,
epochs=30,
batch_size=128,
validation_data=(x_test,y_test),
callbacks=[early,save_weight,reduce_lr_loss]
)<load_pretrained>
print(train.location.nunique() , test.location.nunique() )
model.load_weights('model.learned.hdf5' )<load_from_csv>
for col in ['keyword','location']:
train[col] = train[col].fillna('None')
 test[col] = test[col].fillna('None')
 def clean_loc(x):
if x == 'None':
return 'None'
elif x == 'Earth' or x =='Worldwide' or x == 'Everywhere':
return 'World'
elif 'New York' in x or 'NYC' in x:
return 'New York'
elif 'London' in x:
return 'London'
elif 'Mumbai' in x:
return 'Mumbai'
elif 'Washington' in x and 'D' in x and 'C' in x:
return 'Washington DC'
elif 'San Francisco' in x:
return 'San Francisco'
elif 'Los Angeles' in x:
return 'Los Angeles'
elif 'Seattle' in x:
return 'Seattle'
elif 'Chicago' in x:
return 'Chicago'
elif 'Toronto' in x:
return 'Toronto'
elif 'Sacramento' in x:
return 'Sacramento'
elif 'Atlanta' in x:
return 'Atlanta'
elif 'California' in x:
return 'California'
elif 'Florida' in x:
return 'Florida'
elif 'Texas' in x:
return 'Texas'
elif 'United States' in x or 'USA' in x:
return 'USA'
elif 'United Kingdom' in x or 'UK' in x or 'Britain' in x:
return 'UK'
elif 'Canada' in x:
return 'Canada'
elif 'India' in x:
return 'India'
elif 'Kenya' in x:
return 'Kenya'
elif 'Nigeria' in x:
return 'Nigeria'
elif 'Australia' in x:
return 'Australia'
elif 'Indonesia' in x:
return 'Indonesia'
elif x in top_loc:
return x
else: return 'Others'
train['location_clean'] = train['location'].apply(lambda x: clean_loc(str(x)))
 test['location_clean'] = test['location'].apply(lambda x: clean_loc(str(x)) )
ss = pd.read_csv('.. /input/lish-moa/sample_submission.csv')
 ss.loc[:,'sig_id'] = test_data['sig_id'].values
ss.iloc[:,1:]=0<train_model>
leak = pd.read_csv(".. /input/disasters-on-social-media/socialmedia-disaster-tweets-DFE.csv", encoding='latin_1')
 leak['target'] =(leak['choose_one']=='Relevant' ).astype(int)
 leak['id'] = leak.index
leak = leak[['id', 'target','text']]
merged_df = pd.merge(test, leak, on='id')
 sub1 = merged_df[['id', 'target']]
sub1.to_csv('submit_1.csv', index=False )
histories=[]
scores = []
for fold in range(5):
x_train,x_val,y_train,y_val = data_prepare.getFold(fold)
 print(f'Fold: {fold}
')
 tf.keras.backend.clear_session()
print('training with transfered weights')
 model_fin = model_builder.SimpleNeuralNet(shape=(x_train.shape[1],),learning_rate=0.001,output_shape=206)
 model_fin = model_builder.transfer_weight(model,model_fin)
 for layer in model_fin.layers:
layer.trainable=True
checkpoint_path = f'best_model_{fold}.hdf5'
reduce_lr_loss = ReduceLROnPlateau(monitor='val_loss', factor=0.1, patience=3, verbose=1, epsilon=1e-4, mode='min')
 checkpt = ModelCheckpoint(checkpoint_path, monitor = 'val_loss', verbose = 0, save_best_only = True,
mode = 'min')
 early = EarlyStopping(monitor='val_loss',patience=5,mode='min')
 history=model_fin.fit(x_train.values,
y_train.values,
validation_data=(x_val.values,y_val.values),
epochs=50, batch_size=128,
callbacks=[early,reduce_lr_loss,checkpt] 
)
 print('')
 histories.append(history)
 model_fin= tf.keras.models.load_model(checkpoint_path, custom_objects={'leaky_relu': tf.nn.leaky_relu})
 score= model_builder.metric(y_val,model_fin.predict(x_val ).astype(float))
scores.append(score)
 print(f'Validation metric: {score}')
 test_predict = model_fin.predict(data_prepare.get_test().values)
 ss.loc[:, y_train.columns] += test_predict
print('')
<feature_engineering>
test_str = train.loc[417, 'text']
def clean_text(text):
text = re.sub(r'https?://\S+', '', text)
 text = re.sub(r'
',' ', text)
 text = re.sub('\s+', ' ', text ).strip()
return text
print("Original text: " + test_str)
 print("Cleaned text: " + clean_text(test_str))
ss.loc[:, train_targets_scored.columns[1:]] /= 5<filter>
def find_hashtags(tweet):
return " ".join([match.group(0)[1:] for match in re.finditer(r"
def find_mentions(tweet):
return " ".join([match.group(0)[1:] for match in re.finditer(r"@\w+", tweet)])or 'no'
def find_links(tweet):
return " ".join([match.group(0)[:] for match in re.finditer(r"https?://\S+", tweet)])or 'no'
def process_text(df):
df['text_clean'] = df['text'].apply(lambda x: clean_text(x))
df['hashtags'] = df['text'].apply(lambda x: find_hashtags(x))
df['mentions'] = df['text'].apply(lambda x: find_mentions(x))
df['links'] = df['text'].apply(lambda x: find_links(x))
return df
train = process_text(train)
 test = process_text(test )
ss.loc[test_data[test_data.cp_type=="ctl_vehicle"].index,train_targets_scored.drop('sig_id',axis=1 ).columns]=0<save_to_csv>
def create_stat(df):
df['text_len'] = df['text_clean'].apply(len)
 df['word_count'] = df["text_clean"].apply(lambda x: len(str(x ).split()))
df['stop_word_count'] = df['text_clean'].apply(lambda x: len([w for w in str(x ).lower().split() if w in STOPWORDS]))
df['punctuation_count'] = df['text_clean'].apply(lambda x: len([c for c in str(x)if c in string.punctuation]))
df['hashtag_count'] = df['hashtags'].apply(lambda x: len(str(x ).split()))
df['mention_count'] = df['mentions'].apply(lambda x: len(str(x ).split()))
df['link_count'] = df['links'].apply(lambda x: len(str(x ).split()))
df['caps_count'] = df['text_clean'].apply(lambda x: sum(1 for c in str(x)if c.isupper()))
df['caps_ratio'] = df['caps_count'] / df['text_len']
return df
train = create_stat(train)
 test = create_stat(test)
 print(train.shape, test.shape )
ss.to_csv('./submission.csv',index=False )<set_options>
train.corr() ['target'].drop('target' ).sort_values()
warnings.filterwarnings('ignore' )<load_from_csv>
stopwords = set(STOPWORDS)
train_features = pd.read_csv('.. /input/lish-moa/train_features.csv')
 train_targets_scored = pd.read_csv('.. /input/lish-moa/train_targets_scored.csv')
 train_targets_nonscored = pd.read_csv('.. /input/lish-moa/train_targets_nonscored.csv')
 test_features = pd.read_csv('.. /input/lish-moa/test_features.csv')
 sample_submission = pd.read_csv('.. /input/lish-moa/sample_submission.csv' )<define_variables>
wc = WordCloud().generate(stopwords)
 plt.imshow(wc, interpolation='bilinear')
 plt.axis("off")
 plt.show()
GENES = [col for col in train_features.columns if col.startswith('g-')]
CELLS = [col for col in train_features.columns if col.startswith('c-')]<set_options>
features = ['keyword', 'location_clean']
encoder = ce.TargetEncoder(cols=features)
 encoder.fit(train[features],train['target'])
 train = train.join(encoder.transform(train[features] ).add_suffix('_target'))
test = test.join(encoder.transform(test[features] ).add_suffix('_target'))
def seed_everything(seed=1903):
random.seed(seed)
 os.environ['PYTHONHASHSEED'] = str(seed)
 np.random.seed(seed)
 torch.manual_seed(seed)
 torch.cuda.manual_seed(seed)
 torch.backends.cudnn.deterministic = True
seed_everything(seed=1903 )<concatenate>
vec_links = CountVectorizer(min_df = 5, analyzer = 'word', token_pattern = r'https?://\S+')
 link_vec = vec_links.fit_transform(train['links'])
 link_vec_test = vec_links.transform(test['links'])
 X_train_link = pd.DataFrame(link_vec.toarray() , columns=vec_links.get_feature_names())
 X_test_link = pd.DataFrame(link_vec_test.toarray() , columns=vec_links.get_feature_names())
 vec_men = CountVectorizer(min_df = 5)
 men_vec = vec_men.fit_transform(train['mentions'])
 men_vec_test = vec_men.transform(test['mentions'])
 X_train_men = pd.DataFrame(men_vec.toarray() , columns=vec_men.get_feature_names())
 X_test_men = pd.DataFrame(men_vec_test.toarray() , columns=vec_men.get_feature_names())
 vec_hash = CountVectorizer(min_df = 5)
 hash_vec = vec_hash.fit_transform(train['hashtags'])
 hash_vec_test = vec_hash.transform(test['hashtags'])
 X_train_hash = pd.DataFrame(hash_vec.toarray() , columns=vec_hash.get_feature_names())
 X_test_hash = pd.DataFrame(hash_vec_test.toarray() , columns=vec_hash.get_feature_names())
 print(X_train_link.shape, X_train_men.shape, X_train_hash.shape )
n_comp = 28
data = pd.concat([pd.DataFrame(train_features[GENES]), pd.DataFrame(test_features[GENES])])
 data2 =(PCA(n_components=n_comp, random_state=1903 ).fit_transform(data[GENES]))
train2 = data2[:train_features.shape[0]]; test2 = data2[-test_features.shape[0]:]
train2 = pd.DataFrame(train2, columns=[f'pca_G-{i}' for i in range(n_comp)])
 test2 = pd.DataFrame(test2, columns=[f'pca_G-{i}' for i in range(n_comp)])
 train_features = pd.concat(( train_features, train2), axis=1)
 test_features = pd.concat(( test_features, test2), axis=1)
 n_comp = 5
data = pd.concat([pd.DataFrame(train_features[CELLS]), pd.DataFrame(test_features[CELLS])])
 data2 =(PCA(n_components=n_comp, random_state=1903 ).fit_transform(data[CELLS]))
train2 = data2[:train_features.shape[0]]; test2 = data2[-test_features.shape[0]:]
train2 = pd.DataFrame(train2, columns=[f'pca_C-{i}' for i in range(n_comp)])
 test2 = pd.DataFrame(test2, columns=[f'pca_C-{i}' for i in range(n_comp)])
 train_features = pd.concat(( train_features, train2), axis=1)
 test_features = pd.concat(( test_features, test2), axis=1 )<create_dataframe>
hash_rank =(X_train_hash.transpose().dot(train['target'])/ X_train_hash.sum(axis=0)).sort_values(ascending=False)
 print('Hashtags with which 100% of Tweets are disasters: ')
 print(list(hash_rank[hash_rank==1].index))
print('Total: ' + str(len(hash_rank[hash_rank==1])))
 print('Hashtags with which 0% of Tweets are disasters: ')
 print(list(hash_rank[hash_rank==0].index))
print('Total: ' + str(len(hash_rank[hash_rank==0])) )
var_thresh = VarianceThreshold(threshold=0.4)
 data = train_features.append(test_features)
 data_transformed = var_thresh.fit_transform(data.iloc[:, 4:])
 train_features_transformed = data_transformed[ : train_features.shape[0]]
test_features_transformed = data_transformed[-test_features.shape[0] : ]
train_features = pd.DataFrame(train_features[['sig_id','cp_type','cp_time','cp_dose']].values.reshape(-1, 4),\
columns=['sig_id','cp_type','cp_time','cp_dose'])
 train_features = pd.concat([train_features, pd.DataFrame(train_features_transformed)], axis=1)
 test_features = pd.DataFrame(test_features[['sig_id','cp_type','cp_time','cp_dose']].values.reshape(-1, 4),\
columns=['sig_id','cp_type','cp_time','cp_dose'])
 test_features = pd.concat([test_features, pd.DataFrame(test_features_transformed)], axis=1)
 train_features<merge>
vec_text = TfidfVectorizer(min_df = 10, ngram_range =(1,2), stop_words='english')
 text_vec = vec_text.fit_transform(train['text_clean'])
 text_vec_test = vec_text.transform(test['text_clean'])
 X_train_text = pd.DataFrame(text_vec.toarray() , columns=vec_text.get_feature_names())
 X_test_text = pd.DataFrame(text_vec_test.toarray() , columns=vec_text.get_feature_names())
 print(X_train_text.shape )
train = train_features.merge(train_targets_scored, on='sig_id')
 train = train[train['cp_type']!='ctl_vehicle'].reset_index(drop=True)
 test = test_features[test_features['cp_type']!='ctl_vehicle'].reset_index(drop=True)
 target = train[train_targets_scored.columns]
train = train.drop('cp_type', axis=1)
 test = test.drop('cp_type', axis=1)
<merge>
train = train.join(X_train_link, rsuffix='_link')
 train = train.join(X_train_men, rsuffix='_mention')
 train = train.join(X_train_hash, rsuffix='_hashtag')
 train = train.join(X_train_text, rsuffix='_text')
 test = test.join(X_test_link, rsuffix='_link')
 test = test.join(X_test_men, rsuffix='_mention')
 test = test.join(X_test_hash, rsuffix='_hashtag')
 test = test.join(X_test_text, rsuffix='_text')
 print(train.shape, test.shape )
train_non_scored = train_features.merge(train_targets_nonscored, on='sig_id')
 train_non_scored = train_non_scored[train_non_scored['cp_type']!='ctl_vehicle'].reset_index(drop=True)
 test = test_features[test_features['cp_type']!='ctl_vehicle'].reset_index(drop=True)
 target_non_scored = train_non_scored[train_targets_nonscored.columns]
train_non_scored = train_non_scored.drop('cp_type', axis=1)
 test = test.drop('cp_type', axis=1)
<data_type_conversions>
features_to_drop = ['id', 'keyword','location','text','location_clean','text_clean', 'hashtags', 'mentions','links']
scaler = MinMaxScaler()
X_train = train.drop(columns = features_to_drop + ['target'])
 X_test = test.drop(columns = features_to_drop)
 y_train = train.target
lr = LogisticRegression(solver='liblinear', random_state=777)
 pipeline = Pipeline([('scale',scaler),('lr', lr),])
 pipeline.fit(X_train, y_train)
 y_test = pipeline.predict(X_test)
 submit = sub_sample.copy()
submit.target = y_test
submit.to_csv('submit_lr.csv',index=False )
target_cols = target.drop('sig_id', axis=1 ).columns.values.tolist()
target_non_scored_cols = train_targets_nonscored.drop('sig_id', axis=1 ).columns.values.tolist()<split>
print('Training accuracy: %.4f' % pipeline.score(X_train, y_train))
folds = train.copy()
mskf = MultilabelStratifiedKFold(n_splits=7)
 for f,(t_idx, v_idx)in enumerate(mskf.split(X=train, y=target)) :
folds.loc[v_idx, 'kfold'] = int(f)
 folds['kfold'] = folds['kfold'].astype(int )<split>
print('Training f-1 score: %.4f' % f1_score(y_train, pipeline.predict(X_train)) )
folds_non_scored = train_non_scored.copy()
mskf = MultilabelStratifiedKFold(n_splits=7)
 for f,(t_idx, v_idx)in enumerate(mskf.split(X=train, y=target)) :
folds_non_scored.loc[v_idx, 'kfold'] = int(f)
 folds_non_scored['kfold'] = folds_non_scored['kfold'].astype(int )<categorify>
pd.DataFrame(confusion_matrix(y_train, pipeline.predict(X_train)) )
class MoADataset:
def __init__(self, features, targets):
self.features = features
self.targets = targets
def __len__(self):
return(self.features.shape[0])
 def __getitem__(self, idx):
dct = {
'x' : torch.tensor(self.features[idx, :], dtype=torch.float),
'y' : torch.tensor(self.targets[idx, :], dtype=torch.float)
 }
return dct
class TestDataset:
def __init__(self, features):
self.features = features
def __len__(self):
return(self.features.shape[0])
 def __getitem__(self, idx):
dct = {
'x' : torch.tensor(self.features[idx, :], dtype=torch.float)
 }
return dct<train_model>
cv = ShuffleSplit(n_splits=5, test_size=0.2, random_state=123)
 cv_score = cross_val_score(pipeline, X_train, y_train, cv=cv, scoring='f1')
 print('Cross validation F-1 score: %.3f' %np.mean(cv_score))
def train_fn(model, optimizer, scheduler, loss_fn, dataloader, device):
model.train()
final_loss = 0
for data in dataloader:
optimizer.zero_grad()
inputs, targets = data['x'].to(device), data['y'].to(device)
 outputs = model(inputs)
 loss = loss_fn(outputs, targets)
 loss.backward()
optimizer.step()
scheduler.step()
final_loss += loss.item()
final_loss /= len(dataloader)
 return final_loss
def valid_fn(model, loss_fn, dataloader, device):
model.eval()
final_loss = 0
valid_preds = []
for data in dataloader:
inputs, targets = data['x'].to(device), data['y'].to(device)
 outputs = model(inputs)
 loss = loss_fn(outputs, targets)
 final_loss += loss.item()
valid_preds.append(outputs.sigmoid().detach().cpu().numpy())
 final_loss /= len(dataloader)
 valid_preds = np.concatenate(valid_preds)
 return final_loss, valid_preds
def inference_fn(model, dataloader, device):
model.eval()
preds = []
for data in dataloader:
inputs = data['x'].to(device)
 with torch.no_grad() :
outputs = model(inputs)
 preds.append(outputs.sigmoid().detach().cpu().numpy())
 preds = np.concatenate(preds)
 return preds 
<normalization>
print('Optimal no.of features: %d' % np.insert(X_range, 0, 1)[np.argmax(rfecv.grid_scores_)] )
class Model(nn.Module):
def __init__(self, num_features, num_targets, hidden_size):
super(Model, self ).__init__()
self.batch_norm1 = nn.BatchNorm1d(num_features)
 self.dropout1 = nn.Dropout(0.2)
 self.dense1 = nn.utils.weight_norm(nn.Linear(num_features, hidden_size))
self.batch_norm2 = nn.BatchNorm1d(hidden_size)
 self.dropout2 = nn.Dropout(0.3)
 self.dense2 = nn.utils.weight_norm(nn.Linear(hidden_size, hidden_size))
self.batch_norm3 = nn.BatchNorm1d(hidden_size)
 self.dropout3 = nn.Dropout(0.25)
 self.dense3 = nn.utils.weight_norm(nn.Linear(hidden_size, num_targets))
def forward(self, x):
x = self.batch_norm1(x)
 x = self.dropout1(x)
 x = F.relu(self.dense1(x))
x = self.batch_norm2(x)
 x = self.dropout2(x)
 x = F.relu(self.dense2(x))
x = self.batch_norm3(x)
 x = self.dropout3(x)
 x = self.dense3(x)
 return x<feature_engineering>
selected_features = X_train.columns[rfecv.ranking_ == 1]
X_train2 = X_train[selected_features]
X_test2 = X_test[selected_features]
def process_data(data):
data = pd.get_dummies(data, columns=['cp_time','cp_dose'])
 return data<define_variables>
pipeline.fit(X_train2, y_train)
 cv2 = ShuffleSplit(n_splits=5, test_size=0.2, random_state=456)
 cv_score2 = cross_val_score(pipeline, X_train2, y_train, cv=cv2, scoring='f1')
 print('Cross validation F-1 score: %.3f' %np.mean(cv_score2))
feature_cols = [c for c in process_data(folds ).columns if c not in target_cols]
feature_cols = [c for c in feature_cols if c not in ['kfold','sig_id']]
len(feature_cols )<define_variables>
grid={"C":np.logspace(-2,2,5), "penalty":["l1","l2"]}
lr_cv = GridSearchCV(LogisticRegression(solver='liblinear', random_state=20), grid, cv=cv2, scoring = 'f1')
 pipeline_grid = Pipeline([('scale',scaler),('gridsearch', lr_cv),])
 pipeline_grid.fit(X_train2, y_train)
 print("Best parameter: ", lr_cv.best_params_)
 print("F-1 score: %.3f" %lr_cv.best_score_ )
DEVICE =('cuda' if torch.cuda.is_available() else 'cpu')
 EPOCHS = 100
BATCH_SIZE = 128
LEARNING_RATE = 1e-3
WEIGHT_DECAY = 1e-5
NFOLDS = 7
EARLY_STOPPING_STEPS = 10
EARLY_STOP = True
num_features=len(feature_cols)
 num_targets=len(target_cols)
 num_non_scored_targets=len(target_non_scored_cols)
 hidden_size=2048<import_modules>
y_test2 = pipeline_grid.predict(X_test2)
 submit2 = sub_sample.copy()
submit2.target = y_test2
submit2.to_csv('submit_lr2.csv',index=False )
import copy<prepare_x_and_y>
y_hat = pipeline_grid.predict_proba(X_train2)[:,1]
checker = train.loc[:,['text','keyword','location','target']]
checker['pred_prob'] = y_hat
checker['error'] = np.abs(checker['target'] - checker['pred_prob'])
 error50 = checker.sort_values('error', ascending=False ).head(50)
 error50 = error50.rename_axis('id' ).reset_index()
error50.target.value_counts()
<prepare_x_and_y><EOS> 
pd.options.display.max_colwidth = 200
error50.loc[0:10,['text','target','pred_prob']]