Kaggle competition: Bag of Words Meets Bags of Popcorn
clean_train = []
for i in range(0, train["review"].size):
clean_train.append(stage_one(train["review"][i]))<feature_engineering>
files=['/kaggle/input/word2vec-nlp-tutorial/labeledTrainData.tsv.zip',
'/kaggle/input/word2vec-nlp-tutorial/testData.tsv.zip',
'/kaggle/input/word2vec-nlp-tutorial/unlabeledTrainData.tsv.zip']
for file in files :
zip = zipfile.ZipFile(file,'r')
 zip.extractall()
zip.close()
vectorizer = CountVectorizer(analyzer = "word", \
tokenizer = None, \
preprocessor = None, \
stop_words = None, \
max_features = 12000, \
ngram_range=(1, 3))
features = vectorizer.fit_transform(clean_train ).toarray()
dist = np.sum(features, axis=0)
 vocab = vectorizer.get_feature_names()
forest = ExtraTreesClassifier(n_estimators = 150, n_jobs = -1)
 forest = forest.fit(features, train["sentiment"])
 test = pd.read_csv(".. /input/testData.tsv", header=0, delimiter="\t", quoting=3)
 clean_test = []
for i in range(0,len(test["review"])) :
clean_review = stage_one(test["review"][i])
 clean_test.append(clean_review)
 test_features = vectorizer.transform(clean_test)
 test_features = test_features.toarray()
result = forest.predict(test_features)
 output = pd.DataFrame(data={"id":test["id"], "sentiment":result})
 output.to_csv("n_vectorize_1_3 submit.csv", index=False, quoting=3 )<load_from_csv>
train=pd.read_csv('/kaggle/working/labeledTrainData.tsv', delimiter="\t")
 test=pd.read_csv('/kaggle/working/testData.tsv', delimiter="\t" )
def get_date_features() :
directory = '.. /input/'
trainfile = 'train_date.csv'
for i, chunk in enumerate(pd.read_csv(directory + trainfile,
chunksize=1,
low_memory=False)) :
features = list(chunk.columns)
 break
seen = np.zeros(52)
 rv = []
for f in features:
if f == 'Id':
rv.append(f)
 continue
station = int(f.split('_')[1][1:])
 if seen[station]:
continue
seen[station] = 1
rv.append(f)
 return rv
usefuldatefeatures = get_date_features()
def get_mindate() :
directory = '.. /input/'
trainfile = 'train_date.csv'
testfile = 'test_date.csv'
features = None
subset = None
for i, chunk in enumerate(pd.read_csv(directory + trainfile,
usecols=usefuldatefeatures,
chunksize=50000,
low_memory=False)) :
print(i)
 if features is None:
features = list(chunk.columns)
 features.remove('Id')
 df_mindate_chunk = chunk[['Id']].copy()
df_mindate_chunk['mindate'] = chunk[features].min(axis=1 ).values
if subset is None:
subset = df_mindate_chunk.copy()
else:
subset = pd.concat([subset, df_mindate_chunk])
 del chunk
gc.collect()
for i, chunk in enumerate(pd.read_csv(directory + testfile,
usecols=usefuldatefeatures,
chunksize=50000,
low_memory=False)) :
print(i)
 df_mindate_chunk = chunk[['Id']].copy()
df_mindate_chunk['mindate'] = chunk[features].min(axis=1 ).values
subset = pd.concat([subset, df_mindate_chunk])
 del chunk
gc.collect()
return subset
df_mindate = get_mindate()
df_mindate.sort_values(by=['mindate', 'Id'], inplace=True)
 df_mindate['mindate_id_diff'] = df_mindate.Id.diff()
midr = np.full_like(df_mindate.mindate_id_diff.values, np.nan)
 midr[0:-1] = -df_mindate.mindate_id_diff.values[1:]
df_mindate['mindate_id_diff_reverse'] = midr
def mcc(tp, tn, fp, fn):
sup = tp * tn - fp * fn
inf =(tp + fp)*(tp + fn)*(tn + fp)*(tn + fn)
 if inf == 0:
return 0
else:
return sup / np.sqrt(inf)
 def eval_mcc(y_true, y_prob, show=False):
idx = np.argsort(y_prob)
 y_true_sort = y_true[idx]
n = y_true.shape[0]
nump = 1.0 * np.sum(y_true)
 numn = n - nump
tp = nump
tn = 0.0
fp = numn
fn = 0.0
best_mcc = 0.0
best_id = -1
mccs = np.zeros(n)
 for i in range(n):
if y_true_sort[i] == 1:
tp -= 1.0
fn += 1.0
else:
fp -= 1.0
tn += 1.0
new_mcc = mcc(tp, tn, fp, fn)
 mccs[i] = new_mcc
if new_mcc >= best_mcc:
best_mcc = new_mcc
best_id = i
if show:
best_proba = y_prob[idx[best_id]]
y_pred =(y_prob > best_proba ).astype(int)
 return best_proba, best_mcc, y_pred
else:
return best_mcc
def mcc_eval(y_prob, dtrain):
y_true = dtrain.get_label()
best_mcc = eval_mcc(y_true, y_prob)
 return 'MCC', best_mcc
def create_feature_map(features):
outfile = open('xgb.fmap', 'w')
 for i, feat in enumerate(features):
outfile.write('{0}\t{1}\tq
'.format(i, feat))
outfile.close()
def get_importance(gbm, features):
create_feature_map(features)
 importance = gbm.get_fscore(fmap='xgb.fmap')
 importance = sorted(importance.items() , key=itemgetter(1), reverse=True)
 return importance
def LeaveOneOut(data1, data2, columnName, useLOO=False):
grpOutcomes = data1.groupby(columnName)['Response'].mean().reset_index()
grpCount = data1.groupby(columnName)['Response'].count().reset_index()
grpOutcomes['cnt'] = grpCount.Response
if(useLOO):
grpOutcomes = grpOutcomes[grpOutcomes.cnt > 1]
grpOutcomes.drop('cnt', inplace=True, axis=1)
 outcomes = data2['Response'].values
x = pd.merge(data2[[columnName, 'Response']], grpOutcomes,
suffixes=('x_', ''),
how='left',
on=columnName,
left_index=True)['Response']
if(useLOO):
x =(( x*x.shape[0])-outcomes)/(x.shape[0]-1)
 return x.fillna(x.mean())
 def GrabData() :
directory = '.. /input/'
trainfiles = ['train_categorical.csv',
'train_date.csv',
'train_numeric.csv']
testfiles = ['test_categorical.csv',
'test_date.csv',
'test_numeric.csv']
cols = [['Id',
'L1_S24_F1559', 'L3_S32_F3851',
'L1_S24_F1827', 'L1_S24_F1582',
'L3_S32_F3854', 'L1_S24_F1510',
'L1_S24_F1525', 'L2_S26_F3099'],
['Id',
'L3_S30_D3496', 'L3_S30_D3506',
'L3_S30_D3501', 'L3_S30_D3516',
'L3_S30_D3511', 'L3_S32_D3852',
'L3_S33_D3858', 'L3_S34_D3875',
'L3_S29_D3316'],
['Id',
'L1_S24_F1846', 'L3_S32_F3850',
'L1_S24_F1695', 'L1_S24_F1632',
'L3_S33_F3855', 'L1_S24_F1604',
'L3_S29_F3407', 'L3_S33_F3865',
'L3_S38_F3952', 'L1_S24_F1723',
'L3_S33_F3861', 'L3_S33_F3857',
'L3_S33_F3859', 'L3_S34_F3876', 'L3_S29_F3461',
'Response']]
traindata = None
testdata = None
for i, f in enumerate(trainfiles):
print(f)
 subset = None
for i, chunk in enumerate(pd.read_csv(directory + f,
usecols=cols[i],
chunksize=50000,
low_memory=False)) :
print(i)
 if subset is None:
subset = chunk.copy()
else:
subset = pd.concat([subset, chunk])
 del chunk
gc.collect()
if traindata is None:
traindata = subset.copy()
else:
traindata = pd.merge(traindata, subset.copy() , on="Id")
 del subset
gc.collect()
del cols[2][-1]
for i, f in enumerate(testfiles):
print(f)
 subset = None
for i, chunk in enumerate(pd.read_csv(directory + f,
usecols=cols[i],
chunksize=50000,
low_memory=False)) :
print(i)
 if subset is None:
subset = chunk.copy()
else:
subset = pd.concat([subset, chunk])
 del chunk
gc.collect()
if testdata is None:
testdata = subset.copy()
else:
testdata = pd.merge(testdata, subset.copy() , on="Id")
 del subset
gc.collect()
traindata = traindata.merge(df_mindate, on='Id')
 testdata = testdata.merge(df_mindate, on='Id')
 testdata['Response'] = 0
visibletraindata = traindata[::2]
blindtraindata = traindata[1::2]
print(blindtraindata.columns)
 for i in range(2):
for col in cols[i][1:]:
print(col)
 blindtraindata.loc[:, col] = LeaveOneOut(visibletraindata,
blindtraindata,
col, False ).values
testdata.loc[:, col] = LeaveOneOut(visibletraindata,
testdata, col, False ).values
del visibletraindata
gc.collect()
testdata.drop('Response', inplace=True, axis=1)
 return blindtraindata, testdata
def Train() :
train, test = GrabData()
print('Train:', train.shape)
 print('Test', test.shape)
 features = list(train.columns)
 features.remove('Response')
 features.remove('Id')
 print(features)
 num_rounds = 50
params = {}
params['objective'] = "binary:logistic"
params['eta'] = 0.021
params['max_depth'] = 7
params['colsample_bytree'] = 0.82
params['min_child_weight'] = 3
params['base_score'] = 0.005
params['silent'] = True
print('Fitting')
 trainpredictions = None
testpredictions = None
dvisibletrain = \
xgb.DMatrix(train[features],
train.Response,
silent=True)
 dtest = \
xgb.DMatrix(test[features],
silent=True)
 folds = 1
for i in range(folds):
print('Fold:', i)
 params['seed'] = i
watchlist = [(dvisibletrain, 'train'),(dvisibletrain, 'val')]
clf = xgb.train(params, dvisibletrain,
num_boost_round=num_rounds,
evals=watchlist,
early_stopping_rounds=20,
feval=mcc_eval,
maximize=True 
)
 limit = clf.best_iteration+1
predictions = \
clf.predict(dvisibletrain, ntree_limit=limit)
 best_proba, best_mcc, y_pred = eval_mcc(train.Response,
predictions,
True)
 print('tree limit:', limit)
 print('mcc:', best_mcc)
 print(matthews_corrcoef(train.Response,
y_pred))
if(trainpredictions is None):
trainpredictions = predictions
else:
trainpredictions += predictions
predictions = clf.predict(dtest, ntree_limit=limit)
 if(testpredictions is None):
testpredictions = predictions
else:
testpredictions += predictions
imp = get_importance(clf, features)
 print('Importance array: ', imp)
 best_proba, best_mcc, y_pred = eval_mcc(train.Response,
trainpredictions/folds,
True)
 print(matthews_corrcoef(train.Response,
y_pred))
submission = pd.DataFrame({"Id": train.Id,
"Prediction": trainpredictions/folds,
"Response": train.Response})
 submission[['Id',
'Prediction',
'Response']].to_csv('rawtrainxgbsubmission'+str(folds)+'.csv',
index=False)
 submission = pd.DataFrame({"Id": test.Id.values,
"Response": testpredictions/folds})
 submission[['Id', 'Response']].to_csv('rawxgbsubmission'+str(folds)+'.csv',
index=False)
 y_pred =(testpredictions/folds >.22 ).astype(int)
 submission = pd.DataFrame({"Id": test.Id.values,
"Response": y_pred})
 submission[['Id', 'Response']].to_csv('xgbsubmission'+str(folds)+'.csv',
index=False)
 if __name__ == "__main__":
print('Started')
 Train()
print('Finished')
<install_modules>
sub=pd.read_csv('/kaggle/input/word2vec-nlp-tutorial/sampleSubmission.csv' )
!pip install.. /input/efficientnet-install-files/Ker*.whl
!pip install.. /input/efficientnet-install-files/eff*.whl<choose_model_class>
print('the review with question mark is {}'.format(np.mean(train['review'].apply(lambda x : '?' in x))))
print('the review with fullstop mark is {}'.format(np.mean(train['review'].apply(lambda x : '.' in x))))
print('the ratio of the first capital letter is {}'.format(np.mean(train['review'].apply(lambda x : x[0].isupper()))))
print('the ratio with the capital letter is {}'.format(np.mean(train['review'].apply(lambda x : max(y.isupper() for y in x)))))
 print('the ratio with the number is {}'.format(np.mean(train['review'].apply(lambda x : max(y.isdigit() for y in x)))) )
loss = BiTemperedLogisticLoss(t1=0.6, t2=1.4 )<load_pretrained>
import re
import json
from bs4 import BeautifulSoup
from nltk.corpus import stopwords
from keras.preprocessing.sequence import pad_sequences
from keras.preprocessing.text import Tokenizer
IMG_SIZE = 512
size =(IMG_SIZE,IMG_SIZE)
 best_model = keras.models.load_model('.. /input/cassava-challenge-models/Cassava_model_effnetb4_mixed_precision_bitemperedloss(29jan ).h5',compile=False)
 print(best_model)
 TEST_DIR = '.. /input/cassava-leaf-disease-classification/test_images/'
test_images = os.listdir(TEST_DIR)
 predictions = []
for image in test_images:
img = Image.open(TEST_DIR + image)
 print(img)
 img = img.resize(size)
 print(img)
 img = np.expand_dims(img, axis=0)
 print(img.shape)
 predictions.extend(best_model.predict(img ).argmax(axis = 1))
print(best_model.predict(img))
sub = pd.DataFrame({'image_id': test_images, 'label': predictions})
 sub.to_csv('submission.csv', index = False )<install_modules>
train['review']=train['review'].apply(lambda x: BeautifulSoup(x,"html5lib" ).get_text())
 test['review']=test['review'].apply(lambda x: BeautifulSoup(x,"html5lib" ).get_text() )
<set_options>
train['review']=train['review'].apply(lambda x: re.sub("[^a-zA-Z]"," ",x))
test['review']=test['review'].apply(lambda x: re.sub("[^a-zA-Z]"," ",x))
%matplotlib inline
sns.set_style('darkgrid' )<define_variables>
stops = set(stopwords.words("english"))
for i in range(0,25000):
review = train.iloc[i,2]
review = review.lower().split()
words = [r for r in review if not r in stops]
clean_review = ' '.join(words)
 train.iloc[i,2] = clean_review
path = ".. /input/cassava-leaf-disease-classification/"<load_from_csv>
for i in range(0,25000):
review = test.iloc[i,1]
review = review.lower().split()
words = [r for r in review if not r in stops]
clean_review = ' '.join(words)
 test.iloc[i,1] = clean_review
train = pd.read_csv(f'{path}train.csv' )<load_from_disk>
tk = Tokenizer()
tk.fit_on_texts(list(train['review'])+list(test['review']))
text_seq_tr=tk.texts_to_sequences(train['review'])
 text_seq_te=tk.texts_to_sequences(test['review'])
 word_ind=tk.word_index
with open(f'{path}/label_num_to_disease_map.json', 'r')as f:
name_mapping = json.load(f)
 name_mapping = {int(k): v for k, v in name_mapping.items() }
name_mapping<compute_test_metric>
data_info={}
data_info['word_ind']=word_ind
data_info['word_len']=len(word_ind)+1
def log_t(u, t):

 if t == 1.0:
return torch.log(u)
 else:
return(u **(1.0 - t)- 1.0)/(1.0 - t)
 def exp_t(u, t):

 if t == 1.0:
return torch.exp(u)
 else:
return torch.relu(1.0 +(1.0 - t)* u)**(1.0 /(1.0 - t))
def compute_normalization_fixed_point(activations, t, num_iters=5):

 mu = torch.max(activations, dim=-1 ).values.view(-1, 1)
 normalized_activations_step_0 = activations - mu
normalized_activations = normalized_activations_step_0
i = 0
while i < num_iters:
i += 1
logt_partition = torch.sum(exp_t(normalized_activations, t), dim=-1 ).view(-1, 1)
 normalized_activations = normalized_activations_step_0 *(logt_partition **(1.0 - t))
logt_partition = torch.sum(exp_t(normalized_activations, t), dim=-1 ).view(-1, 1)
 return -log_t(1.0 / logt_partition, t)+ mu
def compute_normalization(activations, t, num_iters=5):

 if t < 1.0:
return None
else:
return compute_normalization_fixed_point(activations, t, num_iters)
 def tempered_softmax(activations, t, num_iters=5):

 if t == 1.0:
normalization_constants = torch.log(torch.sum(torch.exp(activations), dim=-1))
activations = activations.transpose(0, 1)
 else:
normalization_constants = compute_normalization(activations, t, num_iters)
 normalization_constants = normalization_constants.transpose(0, 1)
 activations = activations.transpose(0, 1)
 return exp_t(activations - normalization_constants, t)
 def bi_tempered_logistic_loss(activations, labels, t1, t2, label_smoothing=0.0, num_iters=5):

 if label_smoothing > 0.0:
num_classes = labels.shape[-1]
labels =(1 - num_classes /(num_classes - 1)* label_smoothing)* labels + label_smoothing /(num_classes - 1)
 probabilities = tempered_softmax(activations, t2, num_iters)
 probabilities = probabilities.transpose(0, 1)
 temp1 =(log_t(labels + 1e-10, t1)- log_t(probabilities, t1)) * labels
temp2 =(1 /(2 - t1)) *(torch.pow(labels, 2 - t1)- torch.pow(probabilities, 2 - t1))
loss_values = temp1 - temp2
return torch.sum(loss_values, dim=-1 )<define_variables>
pad_train=pad_sequences(text_seq_tr, maxlen=400)
 pad_test=pad_sequences(text_seq_te, maxlen=400 )
class ImageClassificationDataset(Dataset):
def __init__(
 self,
image_names: List,
transforms: Compose,
labels: Optional[List[int]],
img_path: str = '',
mode: str = 'train',
labels_to_ohe: bool = False,
n_classes: int = 5, 
):

 self.mode = mode
self.transforms = transforms
self.img_path = img_path
self.image_names = image_names
if labels is not None:
if not labels_to_ohe:
self.labels = np.array(labels)
 else:
self.labels = np.zeros(( len(labels), n_classes))
self.labels[np.arange(len(labels)) , np.array(labels)] = 1
def __getitem__(self, idx: int)-> Dict[str, np.array]:
image_path = self.img_path + self.image_names[idx]
image = cv2.imread(f'{image_path}', cv2.IMREAD_COLOR)
 image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
 if image is None:
raise FileNotFoundError(image_path)
 target = self.labels[idx]
img = self.transforms(image=image)['image']
sample = {'image_path': image_path, 'image': img, 'target': np.array(target ).astype('int64')}
return sample
def __len__(self)-> int:
return len(self.image_names )<choose_model_class>
x_train, x_valid, y_train, y_valid = train_test_split(pad_train, train['sentiment'], random_state=77, test_size=0.07, stratify=train['sentiment'] )
class CassavaDataModule(pl.LightningDataModule):
def __init__(self,
df,
train_augs,
valid_augs,
path):
super().__init__()
self.df = df
self.train_augs = train_augs
self.valid_augs = valid_augs
self.path = path
def prepare_data(self):
pass
def setup(self, stage=None):
folds = StratifiedKFold(n_splits=5, shuffle=True, random_state=42)
 train_indexes, valid_indexes = list(folds.split(self.df, self.df['label'])) [0]
train_df = self.df.iloc[train_indexes]
valid_df = self.df.iloc[valid_indexes]
self.train_dataset = ImageClassificationDataset(image_names=train_df['image_id'].values,
transforms=train_augs,
labels=train_df['label'].values,
img_path=self.path,
mode='train',
labels_to_ohe=False,
n_classes=5)
 self.valid_dataset = ImageClassificationDataset(image_names=valid_df['image_id'].values,
transforms=valid_augs,
labels=valid_df['label'].values,
img_path=self.path,
mode='valid',
labels_to_ohe=False,
n_classes=5)
 def train_dataloader(self):
train_loader = torch.utils.data.DataLoader(
 self.train_dataset,
batch_size=16,
num_workers=4,
shuffle=True, 
)
 return train_loader
def val_dataloader(self):
valid_loader = torch.utils.data.DataLoader(
 self.valid_dataset,
batch_size=32,
num_workers=4,
shuffle=False, 
)
 return valid_loader
def test_dataloader(self):
return None<choose_model_class>
model=Sequential()
model.add(Embedding(101247,65, input_length=400))
model.add(Flatten())
 model.add(Dense(2,activation='softmax'))
model.compile(loss='sparse_categorical_crossentropy', optimizer='adam', metrics=['acc'] )
class CassvaImgClassifier(nn.Module):
def __init__(self, model_arch, n_class):
super().__init__()
self.model = EfficientNet.from_pretrained(model_arch)
 n_features = self.model._fc.in_features
self.model._fc = nn.Linear(n_features, n_class)
 def forward(self, x, targets):
logits = self.model(x)
 batch_size = targets.size() [0]
targets = nn.functional.one_hot(targets, num_classes=5)
 loss = bi_tempered_logistic_loss(activations=logits, labels=targets, t1=0.4, t2=2.0)
 loss = loss.sum() / batch_size
return logits, loss<choose_model_class>
es=EarlyStopping(patience=4)
 mc=ModelCheckpoint('best.h5',save_best_only=True)
 model.fit(x_train,y_train, batch_size=128, epochs=10, validation_data=[x_valid,y_valid], callbacks=[es,mc] )
class LitCassava(pl.LightningModule):
def __init__(self, model):
super(LitCassava, self ).__init__()
self.model = model
self.metric = pl.metrics.Accuracy()
self.learning_rate = 1e-4
def forward(self, x, targets, *args, **kwargs):
return self.model(x, targets)
 def configure_optimizers(self):
optimizer = torch.optim.AdamW(self.model.parameters() , lr=self.learning_rate, weight_decay=0.001)
 scheduler = torch.optim.lr_scheduler.ReduceLROnPlateau(optimizer, factor=0.1, patience=2)
 return(
 [optimizer],
[{'scheduler': scheduler, 'interval': 'epoch', 'monitor': 'valid_loss'}], 
)
 def training_step(
 self, batch: torch.Tensor, batch_idx: int 
)-> Union[int, Dict[str, Union[torch.Tensor, Dict[str, torch.Tensor]]]]:
image = batch['image']
target = batch['target']
logits, loss = self(image, target)
 score = self.metric(logits.argmax(1), target)
 self.log('train_loss', loss, on_step=False, on_epoch=True, logger=True)
 logs = {'train_loss': loss, f'train_accuracy': score}
return {
'loss': loss,
'log': logs,
'progress_bar': logs,
'logits': logits,
'target': target,
f'train_accuracy': score,
}
def training_epoch_end(self, outputs):
avg_loss = torch.stack([x['loss'] for x in outputs] ).mean()
y_true = torch.cat([x['target'] for x in outputs])
 y_pred = torch.cat([x['logits'] for x in outputs])
 score = self.metric(y_pred.argmax(1), y_true)
 self.log('train_score', score, logger=True)
 logs = {'train_loss': avg_loss, 'train_accuracy': score}
return {'log': logs, 'progress_bar': logs}
def validation_step(
 self, batch: torch.Tensor, batch_idx: int 
)-> Union[int, Dict[str, Union[torch.Tensor, Dict[str, torch.Tensor]]]]:
image = batch['image']
target = batch['target']
logits, loss = self(image, target)
 score = self.metric(logits.argmax(1), target)
 self.log('val_loss', loss, on_step=False, on_epoch=True, logger=True)
 logs = {'valid_loss': loss, f'valid_accuracy': score}
return {
'loss': loss,
'log': logs,
'progress_bar': logs,
'logits': logits,
'target': target,
f'valid_accuracy': score,
}
def validation_epoch_end(self, outputs):
avg_loss = torch.stack([x['loss'] for x in outputs] ).mean()
y_true = torch.cat([x['target'] for x in outputs])
 y_pred = torch.cat([x['logits'] for x in outputs])
 score = self.metric(y_pred.argmax(1), y_true)
 self.log('val_score', score, logger=True)
 logs = {'valid_loss': avg_loss, f'valid_accuracy': score, 'accuracy': score}
return {'valid_loss': avg_loss, 'log': logs, 'progress_bar': logs}<choose_model_class>
model.load_weights('best.h5' )
model = CassvaImgClassifier(model_arch="efficientnet-b3", n_class=5 )<create_dataframe>
res=model.predict(pad_test, batch_size=128 )
dm = CassavaDataModule(train, train_augs, valid_augs, f'{path}train_images/' )<choose_model_class>
sub['sentiment_pro']=res[:,1]
trainer = pl.Trainer(
 checkpoint_callback=ModelCheckpoint(monitor='val_loss',
save_top_k=1, filepath='{epoch}_{val_loss:.4f}_{val_score:.4f}', mode='min'),
gpus=1,
max_epochs=50,
num_sanity_val_steps=0,
weights_summary='top',
callbacks = [EarlyStopping(monitor='val_loss', patience=10, mode='min')],
fast_dev_run=False,
)<choose_model_class>
sub.loc[sub['sentiment_pro']>=0.5,"sentiment"]=1
sub.loc[sub['sentiment_pro']<0.5,"sentiment"]=0
lit_model = LitCassava(model )<train_model>
sub=sub[['id','sentiment']]
<find_best_params><EOS> 
sub.to_csv('result.csv',index=False )