Kaggle competition: Mechanisms of Action (MoA) Prediction
<SOS> metric: MeanColumnwiseLogLoss Kaggle data source: mechanisms-of-action-(moa)-prediction<string_transform>
!mkdir /models
def jaccard(str1, str2):
a = set(str1.lower().split())
 b = set(str2.lower().split())
 c = a.intersection(b)
 return float(len(c)) /(len(a)+ len(b)- len(c))<compute_train_metric>
train_features = pd.read_csv('/kaggle/input/lish-moa/train_features.csv')
 train_targets = pd.read_csv('/kaggle/input/lish-moa/train_targets_scored.csv')
 test_features = pd.read_csv('/kaggle/input/lish-moa/test_features.csv')
 sample_submission = pd.read_csv('/kaggle/input/lish-moa/sample_submission.csv')
def loss_func(out, s_target, e_target):
criterion = nn.CrossEntropyLoss()
s_loss = criterion(out[0], s_target)
 e_loss = criterion(out[1], e_target)
 total_loss = s_loss+e_loss
return total_loss<choose_model_class>
def preprocess(df):

 df = df.copy()
df.loc[:, 'cp_type'] = df.loc[:, 'cp_type'].map({'trt_cp': 0, 'ctl_vehicle': 1})
 df.loc[:, 'cp_dose'] = df.loc[:, 'cp_dose'].map({'D1': 0, 'D2': 1})
 df.loc[:, 'cp_time'] = df.loc[:, 'cp_time'].map({24: 0, 48: 1, 72: 2})
 del df['sig_id']
return df
class BertBaseQA(nn.Module):
def __init__(self, hidden_size, num_labels,conf):
super().__init__()
self.hidden_size = hidden_size
self.num_labels = num_labels
self.bert = transformers.RobertaModel.from_pretrained(config.roberta_path,config=conf)
 self.drop_out = nn.Dropout(0.1)
 self.qa_outputs = nn.Linear(self.hidden_size, self.num_labels)
 def forward(self, ids, mask, token_ids):
output = self.bert(
 input_ids = ids,
attention_mask = mask,
token_type_ids = token_ids, 
)
 sequence_output = output[0]
sequence_output = self.drop_out(sequence_output)
 logits = self.qa_outputs(sequence_output)
 start_logits, end_logits = logits.split(1, dim=-1)
 start_logits = start_logits.squeeze(-1)
 end_logits = end_logits.squeeze(-1)
 outputs =(start_logits, end_logits,)
 return outputs<string_transform>
train = preprocess(train_features)
 test = preprocess(test_features)
 del train_targets['sig_id']
class BertDatasetModule(Dataset):
def __init__(self, tokenizer, context, question, max_length, text):
self.context = context
self.question = question
self.text = text
self.tokenizer = tokenizer
self.max_length = max_length
def __len__(self):
'Denotes the total number of samples'
return len(self.context)
 def __getitem__(self, idx):
'Generates one sample of data'
context_ = self.context[idx]
question_ = self.question[idx]
text_ = self.text[idx]
context_ = " " + " ".join(str(context_ ).split())
 text_ = " " + " ".join(str(text_ ).split())
 tok_context = tokenizer.encode(context_)
 tok_question = tokenizer.encode(question_)
 tok_answer = tokenizer.encode(text_)
 context_ids = tok_context.ids
question_ids = tok_question.ids
answer_ids = tok_answer.ids
offsets_orig = tok_context.offsets
input_ids = [0] + question_ids + [2] + [2] + context_ids + [2]
token_type_ids = [0, 0, 0, 0] + [0] *(len(context_ids)) + [0]
mask = [1] * len(token_type_ids)
 offsets = [(0,0)]*4 + offsets_orig + [(0,0)]
s_pos, e_pos = 0, 0
for i in range(len(input_ids)) :
if(input_ids[i: i+len(answer_ids)] == answer_ids):
s_pos = i
e_pos = i + len(answer_ids)- 1
break
assert(( s_pos<len(input_ids)) &(e_pos<len(input_ids)) &(s_pos<=e_pos))
pad_length = self.max_length - len(input_ids)
 if(len(input_ids)<self.max_length):
ids = input_ids +([1]*pad_length)
 elif(len(input_ids)>self.max_length):
ids = input_ids[:self.max_length]
if(len(token_type_ids)<self.max_length):
token_ids = token_type_ids +([0]*pad_length)
 elif(len(token_type_ids)>self.max_length):
token_ids = token_type_ids[:self.max_length]
if(len(mask)<self.max_length):
mask_ids = mask +([0]*pad_length)
 elif(len(token_type_ids)>self.max_length):
mask_ids = mask[:self.max_length]
if(len(input_ids)<self.max_length):
offsets = offsets +([(0, 0)] * pad_length)
 elif(len(input_ids)>self.max_length):
offsets = offsets[:self.max_length]
ids = torch.tensor(ids, dtype = torch.long)
 tt_ids = torch.tensor(token_ids, dtype = torch.long)
 mask_ids = torch.tensor(mask_ids, dtype = torch.long)
 offsets = torch.tensor(offsets, dtype = torch.long)
 start_pos = torch.tensor(s_pos, dtype = torch.long)
 end_pos = torch.tensor(e_pos, dtype = torch.long)
 return {'ids': ids,
'token_type_ids': tt_ids,
'mask':mask_ids,
'start_pos': start_pos,
'end_pos': end_pos,
'offsets': offsets,
'context':context_,
'question':question_,
'text':text_}<train_model>
train_targets = train_targets.loc[train['cp_type']==0].reset_index(drop=True)
 train = train.loc[train['cp_type']==0].reset_index(drop=True )
def train_loop(dataloader, model, optimizer, device, max_grad_norm, scheduler=None):
model.train()
for bi, d in enumerate(tqdm_notebook(dataloader, desc="Iteration")) :
ids = d['ids']
mask_ids = d['mask']
token_ids = d['token_type_ids']
start_pos = d['start_pos']
end_pos = d['end_pos']
offsets = d['offsets']
ids = ids.to(device, dtype = torch.long)
 mask_ids = mask_ids.to(device, dtype = torch.long)
 token_ids = token_ids.to(device, dtype = torch.long)
 start_pos = start_pos.to(device, dtype = torch.long)
 end_pos = end_pos.to(device, dtype = torch.long)
 optimizer.zero_grad()
start_and_end_scores = model(ids, mask_ids, token_ids)
 loss = loss_func(start_and_end_scores, start_pos, end_pos)
 loss.backward()
optimizer.step()
if scheduler is not None:
scheduler.step()
if bi%100==0:
print(f"bi: {bi}, loss: {loss}" )<split>
scaler = MinMaxScaler()
scaler.fit(train)
 train = scaler.transform(train)
 test = scaler.transform(test )
def eval_loop(dataloader, model, device):
model.eval()
pred_s = None
pred_e = None
eval_loss = 0.0
eval_steps = 0
for bi, d in enumerate(dataloader):
ids = d['ids']
mask_ids = d['mask']
token_ids = d['token_type_ids']
start_pos = d['start_pos']
end_pos = d['end_pos']
context = d['context']
question = d['question']
selected_text = d['text']
offsets = d['offsets']
ids = ids.to(device, dtype = torch.long)
 mask_ids = mask_ids.to(device, dtype = torch.long)
 token_ids = token_ids.to(device, dtype = torch.long)
 start_pos = start_pos.to(device, dtype = torch.long)
 end_pos = end_pos.to(device, dtype = torch.long)
 with torch.no_grad() :
start_and_end_scores = model(ids,mask_ids, token_ids)
 loss = loss_func(start_and_end_scores, start_pos, end_pos)
 eval_loss += loss.mean().item()
eval_steps += 1
pred_s = torch.softmax(torch.tensor(start_and_end_scores[0]),dim=1 ).detach().cpu().numpy()
pred_e = torch.softmax(torch.tensor(start_and_end_scores[1]),dim=1 ).detach().cpu().numpy()
eval_loss = eval_loss/eval_steps
pred_start = np.argmax(pred_s, axis=1)
 pred_end = np.argmax(pred_e, axis=1)
 jaccards=[]
for i,tweet in enumerate(context):
idx_start = pred_start[i]
idx_end = pred_end[i]
if idx_end < idx_start:
idx_end = idx_start
filtered_output = ""
for ix in range(idx_start, idx_end + 1):
filtered_output += tweet[offsets[i][ix][0]: offsets[i][ix][1]]
if(ix+1)< len(offsets[i])and offsets[i][ix][1] < offsets[i][ix+1][0]:
filtered_output += " "
if question[i] == "neutral" or len(tweet.split())< 2:
filtered_output = tweet
jaccards.append(jaccard(filtered_output,selected_text[i]))
return eval_loss, pred_start, pred_end, jaccards<define_variables>
train_targets = train_targets.to_numpy()
test_start = []
test_end = []
mean_jaccard = []<split>
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):
return {
'input': torch.tensor(self.features[idx, :], dtype=torch.float),
'target': torch.tensor(self.targets[idx, :], dtype=torch.float)
 }
class TestDataset:
def __init__(self, features):
self.features = features
def __len__(self):
return self.features.shape[0]
def __getitem__(self, idx):
return {
'input': torch.tensor(self.features[idx, :], dtype=torch.float)
 }
kf = StratifiedKFold(n_splits = 5, shuffle = True, random_state = 42)
 for fold,(tr_ind, val_ind)in enumerate(kf.split(raw_train_data, raw_train_data['sentiment'])) :
train_data = raw_train_data.iloc[tr_ind].reset_index(drop=True)
 val_data = raw_train_data.iloc[val_ind].reset_index(drop=True)
 train_dataset = BertDatasetModule(
 tokenizer = tokenizer,
context = train_data['text'],
question = train_data['sentiment'],
max_length = MAX_SEQ_LENGTH,
text = train_data['selected_text'] 
)
 train_dataloader = DataLoader(train_dataset, batch_size = TRAIN_BATCH_SIZE, shuffle=True)
 eval_dataset = BertDatasetModule(
 tokenizer = tokenizer,
context = val_data['text'],
question = val_data['sentiment'],
max_length = MAX_SEQ_LENGTH,
text = val_data['selected_text'] 
)
 eval_dataloader = DataLoader(eval_dataset, batch_size = EVAL_BATCH_SIZE, shuffle=False)
 device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
 print(device)
 model_config = transformers.RobertaConfig.from_pretrained(config.roberta_path)
 model = BertBaseQA(768, 2,model_config ).to(device)
 optimizer = AdamW(model.parameters() , lr=LEARNING_RATE, correct_bias=False)
 NUM_TRAIN_STEPS = int(len(train_dataset)/TRAIN_BATCH_SIZE * NUM_TRAIN_EPOCHS)
 scheduler = transformers.get_constant_schedule_with_warmup(
 optimizer,
num_warmup_steps=500,
last_epoch=-1)
 for epoch in trange(NUM_TRAIN_EPOCHS):
train_loop(train_dataloader, model, optimizer, device, max_grad_norm, scheduler)
 res = eval_loop(eval_dataloader, model, device)
 val_start = res[1]
val_end = res[2]
jaccards = res[3]
mean_jaccard.append(np.mean(jaccards))
torch.save(model.state_dict() ,'model_' + str(fold)+ '.pth' )<categorify>
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.2)
 self.dense2 = nn.utils.weight_norm(nn.Linear(hidden_size, hidden_size))
self.batch_norm3 = nn.BatchNorm1d(hidden_size)
 self.dropout3 = nn.Dropout(0.2)
 self.dense3 = nn.utils.weight_norm(nn.Linear(hidden_size, num_targets))
device = 'cuda' if torch.cuda.is_available() else 'cpu'
self.weight = torch.tensor([0.5] ).to(device)
 def forward(self, x):
x = self.batch_norm1(x)
 x = self.dropout1(x)
 x = F.prelu(self.dense1(x), self.weight)
 x = self.batch_norm2(x)
 x = self.dropout2(x)
 x = F.prelu(self.dense2(x), self.weight)
 x = self.batch_norm3(x)
 x = self.dropout3(x)
 x = self.dense3(x)
 return x
predicted_output = []
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")
 model_config = transformers.RobertaConfig.from_pretrained(config.roberta_path)
 model_0 = BertBaseQA(768, 2,model_config ).to(device)
 model_1 = BertBaseQA(768, 2,model_config ).to(device)
 model_2 = BertBaseQA(768, 2,model_config ).to(device)
 model_3 = BertBaseQA(768, 2,model_config ).to(device)
 model_4 = BertBaseQA(768, 2,model_config ).to(device)
 model_0.load_state_dict(torch.load('model_0.pth'))
model_1.load_state_dict(torch.load('model_1.pth'))
model_2.load_state_dict(torch.load('model_2.pth'))
model_3.load_state_dict(torch.load('model_3.pth'))
model_4.load_state_dict(torch.load('model_4.pth'))
model_0.eval()
model_1.eval()
model_2.eval()
model_3.eval()
model_4.eval()
test_dataset = BertDatasetModule(
 tokenizer = tokenizer,
context = raw_test_data['text'],
question = raw_test_data['sentiment'],
max_length = MAX_SEQ_LENGTH,
text = raw_test_data['text'] 
)
 test_dataloader = DataLoader(test_dataset, batch_size = TEST_BATCH_SIZE, shuffle=False)
 for bi, d in enumerate(test_dataloader):
ids = d['ids']
mask_ids = d['mask']
token_ids = d['token_type_ids']
start_pos = d['start_pos']
end_pos = d['end_pos']
context = d['context']
question = d['question']
selected_text = d['text']
offsets = d['offsets']
ids = ids.to(device, dtype = torch.long)
 mask_ids = mask_ids.to(device, dtype = torch.long)
 token_ids = token_ids.to(device, dtype = torch.long)
 start_pos = start_pos.to(device, dtype = torch.long)
 end_pos = end_pos.to(device, dtype = torch.long)
 with torch.no_grad() :
start_and_end_scores0 = model_0(ids,mask_ids, token_ids)
 start_and_end_scores1 = model_1(ids,mask_ids, token_ids)
 start_and_end_scores2 = model_2(ids,mask_ids, token_ids)
 start_and_end_scores3 = model_2(ids,mask_ids, token_ids)
 start_and_end_scores4 = model_3(ids,mask_ids, token_ids)
 start_scores =(start_and_end_scores0[0]+start_and_end_scores1[0]+start_and_end_scores2[0]+start_and_end_scores3[0]+start_and_end_scores4[0])/5
end_scores =(start_and_end_scores0[1]+start_and_end_scores1[1]+start_and_end_scores2[1]+start_and_end_scores3[1]+start_and_end_scores4[1])/5
pred_s = torch.softmax(torch.tensor(start_scores),dim=1 ).detach().cpu().numpy()
pred_e = torch.softmax(torch.tensor(end_scores),dim=1 ).detach().cpu().numpy()
pred_start = np.argmax(pred_s, axis=1)
 pred_end = np.argmax(pred_e, axis=1)
 for i,tweet in enumerate(context):
idx_start = pred_start[i]
idx_end = pred_end[i]
if idx_end < idx_start:
idx_end = idx_start
filtered_output = ""
for ix in range(idx_start, idx_end + 1):
filtered_output += tweet[offsets[i][ix][0]: offsets[i][ix][1]]
if(ix+1)< len(offsets[i])and offsets[i][ix][1] < offsets[i][ix+1][0]:
filtered_output += " "
if question == "neutral" or len(tweet.split())< 2:
filtered_output = tweet
predicted_output.append(filtered_output )<save_to_csv>
def set_seed(seed):
os.environ['PYTHONHASHSEED'] = str(seed)
 torch.manual_seed(seed)
 torch.backends.cudnn.deterministic = True
torch.backends.cudnn.benchmark = False
np.random.seed(seed )
sample = pd.read_csv(".. /input/tweet-sentiment-extraction/sample_submission.csv")
 sample.loc[:, 'selected_text'] = predicted_output
sample.to_csv("submission.csv", index=False)
 sample.head(30 )<define_variables>
def get_dataloaders(num_workers, batch_size, x_train, y_train, x_valid, y_valid):

 train_dataset = MoADataset(x_train, y_train)
 valid_dataset = MoADataset(x_valid, y_valid)
 train_loader = torch.utils.data.DataLoader(train_dataset, batch_size=batch_size, num_workers=num_workers)
 valid_loader = torch.utils.data.DataLoader(valid_dataset, batch_size=batch_size, num_workers=num_workers)
 loader = {
"train": train_loader,
"valid": valid_loader
}
return loader
enAvg = '.. /input/ensamble-and-max-nbsvm-and-tfidflr/submissionAvg.csv'
enMax = '.. /input/ensamble-and-max-nbsvm-and-tfidflr/submissionMax.csv'
enCond = '.. /input/ensamble-and-max-nbsvm-and-tfidflr/submissionCondMax.csv'
lstm = '.. /input/basic-lstm/submissionLSTM.csv'<load_from_csv>
def get_testloaders(num_workers, batch_size, x_test):

 test_dataset = TestDataset(x_test)
 test_loader = torch.utils.data.DataLoader(test_dataset, batch_size=batch_size, num_workers=num_workers)
 loader = {
'test': test_loader
}
return loader
p_enAvg = pd.read_csv(enAvg)
 p_enMax = pd.read_csv(enMax)
 p_enCond = pd.read_csv(enCond)
 p_lstm = pd.read_csv(lstm )<define_variables>
def train_model(n_epochs, loaders, model, optimizer, criterion, device, save_path):

 scheduler = StepLR(optimizer, step_size=2, gamma=0.96)
 valid_loss_min = np.Inf
for epoch in range(1, n_epochs + 1):
scheduler.step()
train_loss = 0.0
valid_loss = 0.0
model.train()
for data in loaders['train']:
data_input, data_target = data['input'].to(device), data['target'].to(device)
 optimizer.zero_grad()
output = model(data_input)
 loss = criterion(output, data_target)
 loss.backward()
optimizer.step()
train_loss +=(loss.item() / len(loaders['train']))
model.eval()
for data in loaders['valid']:
data_input, data_target = data['input'].to(device), data['target'].to(device)
 output = model(data_input)
 loss = criterion(output, data_target)
 valid_loss +=(loss.item() / len(loaders['valid']))
if valid_loss < valid_loss_min:
print(f'Epoch: \t{epoch}\tValidation loss decreased({valid_loss_min} -> {valid_loss} ).Saving the model...')
 torch.save(model.state_dict() , save_path)
 valid_loss_min = valid_loss
clear_output(wait=True)
 return model
label_cols = ['toxic', 'severe_toxic', 'obscene', 'threat', 'insult', 'identity_hate']<save_to_csv>
def run_training(seed, kfold, batch_size, epochs, learning_rate, weight_decay):
set_seed(seed)
 for fold,(train_idx, valid_idx)in enumerate(kfold.split(X=train, y=train_targets)) :
x_train, x_valid = train[train_idx], train[valid_idx]
y_train, y_valid = train_targets[train_idx], train_targets[valid_idx]
dataloaders = get_dataloaders(0, batch_size, x_train, y_train, x_valid, y_valid)
 device = 'cuda' if torch.cuda.is_available() else 'cpu'
model = Model(875, 206, 1024 ).to(device)
 criterion_moa = nn.BCEWithLogitsLoss()
optimizer_moa = torch.optim.Adam(model.parameters() , lr=learning_rate, weight_decay=weight_decay)
 train_model(epochs, dataloaders, model, optimizer_moa, criterion_moa, device, f'/models/model_seed_{seed}_fold_{fold}.pt' )
p_res = p_lstm.copy()
p_res[label_cols] =(p_lstm[label_cols] + p_enCond[label_cols])/ 2
p_res.to_csv('submissionCondLstmAvg.csv', index=False )<save_to_csv>
FOLDS = 5
WORKERS = 0
BATCH_SIZE = 128
EPOCHS = 50
LEARNING_RATE = 0.0002
WEIGHT_DECAY = 0.00001
SEED = 42
p_res2 = p_lstm.copy()
for i, j in enumerate(p_res2):
if j == 'id':
continue
temp_df = pd.concat([p_lstm[j], p_enCond[j]], axis=1)
 p_res2[j] = temp_df.apply(lambda r: np.max(r)if np.mean(r)> 0.5 else np.mean(r), axis=1)
 p_res2.to_csv('submissionlstmCondCondMax.csv', index=False )<save_to_csv>
mskf = KFold(n_splits=FOLDS)
 for seed in range(35, 40):
run_training(seed, mskf, BATCH_SIZE, EPOCHS, LEARNING_RATE, WEIGHT_DECAY)
p_res2 = p_lstm.copy()
for i, j in enumerate(p_res2):
if j == 'id':
continue
temp_df = pd.concat([p_lstm[j], p_enCond[j]], axis=1)
 p_res2[j] = temp_df.apply(lambda r: np.max(r)if np.mean(r)> 0.5 else np.min(r), axis=1)
 p_res2.to_csv('submissionlstmCondCondMaxMin.csv', index=False )<load_from_csv>
def inference(loaders, model, device):

 model.eval()
preds = []
for data in loaders['test']:
data_input = data['input'].to(device)
 with torch.no_grad() :
output = model(data_input)
 pred = output.sigmoid().detach().cpu().numpy()
preds.append(pred)
 return np.concatenate(preds )
train = pd.read_csv('.. /input/train.csv')
 test = pd.read_csv('.. /input/test.csv')
 subm = pd.read_csv('.. /input/sample_submission.csv')
 train_text = train['comment_text']
test_text =test['comment_text']
combined_df = pd.concat([train,test],axis=0)
 combined_df.head(n=5)
 word_vectorizer = TfidfVectorizer(sublinear_tf=True,analyzer='word',ngram_range=(1,1),max_features=30000)
 word_vectorizer.fit(combined_df['comment_text'])
 train_word_features = word_vectorizer.transform(train_text)
 test_word_features = word_vectorizer.transform(test_text)
 char_vectorizer = TfidfVectorizer(sublinear_tf=True,analyzer='char',ngram_range=(1,3),max_features=50000)
 char_vectorizer.fit(combined_df['comment_text'])
 train_char_features = char_vectorizer.transform(train_text)
 test_char_features = char_vectorizer.transform(test_text)
 train_features_matrix = hstack([train_char_features,train_word_features])
 test_features_matrix = hstack([test_char_features,test_word_features])
 losses = []
columns = ['toxic','severe_toxic','obscene','threat','insult','identity_hate']
preds = np.zeros(( test.shape[0],len(columns)))
 index = 0
for column in columns:
train_target_result = train[column]
classifier = LogisticRegression(solver='sag')
 cv_loss = np.mean(cross_val_score(classifier,train_features_matrix,train_target_result,cv=4,scoring='roc_auc'))
losses.append(cv_loss)
 print('CV score for class {} is {}'.format(column,cv_loss))
classifier.fit(train_features_matrix,train_target_result)
 preds[:,index] = classifier.predict_proba(test_features_matrix)[:,1]
index = index + 1
print('Total CV score is {}'.format(np.mean(losses)))
 submission_dataframe = pd.DataFrame({'id':subm['id']})
 classification_dataframe = pd.DataFrame(preds,columns=columns)
 final_submission_dataframe = pd.concat([submission_dataframe,classification_dataframe],axis=1)
 final_submission_dataframe.to_csv('submission.csv',index=False)
<define_variables>
def run_inferencing(seed):
set_seed(seed)
 preds = np.zeros(( len(test), 206))
for i in range(0, FOLDS):
dataloaders = get_testloaders(0, 128, test)
 device = 'cuda' if torch.cuda.is_available() else 'cpu'
model = Model(875, 206, 1024)
 model.load_state_dict(torch.load(f'/models/model_seed_{seed}_fold_{i}.pt'))
model.to(device)
 pred = inference(dataloaders, model, device)
 preds += pred
preds = preds / FOLDS
return preds
f_lstm = '.. /input/lstm-glove-lr-decrease-bn-cv-lb-0-047/LSTM-submission.csv'
f_nbsvm = '.. /input/nb-svm-strong-linear-baseline-eda-0-052-lb/submission.csv'
f_eaf = '.. /input/easy-and-fast-lb-044/feat_lr_2cols.csv'
f_tfidf = '.. /input/word-character-n-grams-tfidf-regressions-lb-051/output.csv' 
<load_from_csv>
preds = np.zeros(( len(test), 206))
for seed in range(35, 40):
preds += run_inferencing(seed)
 preds = preds / 5
p_lstm = pd.read_csv(f_lstm)
 p_tfidf = pd.read_csv(f_tfidf)
<feature_engineering>
sample_submission[targets] = preds
sample_submission.loc[test_features['cp_type']=='ctl_vehicle', targets] = 0
sample_submission.to_csv('submission.csv', index=False )