ESCI Challenge for Improving Product Search
[Task 3 - Score 0.836] 3 Common Models Trained Separately
Just 3 Common Model Trained Separately
Just want to share my simple approach which somehow boosts my score from ~0.7 to ~0.8 (LB 0.836).
So I tried to train the models separately for each language.
training 3 models separately¶
here's the checkpoint of the 3 models :¶
In [ ]:
# https://drive.google.com/file/d/1AZqsOCU80Xlz8MOmPCeUSnqVanQlYGMg/view?usp=sharing
here's the training notebook for es, you can change it to any other languange :¶
In [ ]:
# https://colab.research.google.com/drive/1hcVlUzDvQ5H9AjWDplnVOSqIIldMEQny?usp=sharing
setting up for prediction¶
In [1]:
import math
from sentence_transformers import models, losses, datasets
from sentence_transformers import LoggingHandler, SentenceTransformer, util, InputExample
from sentence_transformers.evaluation import EmbeddingSimilarityEvaluator
import logging
from datetime import datetime
import sys
import os
import gzip
import csv
import random
from sentence_transformers.cross_encoder import CrossEncoder
In [2]:
import numpy as np
import pandas as pd
In [3]:
#### Just some code to print debug information to stdout
logging.basicConfig(format='%(asctime)s - %(message)s',
datefmt='%Y-%m-%d %H:%M:%S',
level=logging.INFO,
handlers=[LoggingHandler()])
In [4]:
# Save path of the model
model_save_path_jp = './output/training_classification_task3_crossv1_jp_bert-base-multilingual-cased'
model_save_path_us = './output/training_classification_task3_crossv1_us_bert-base-multilingual-cased'
model_save_path_es = './output/training_classification_task3_crossv1_es_bert-base-multilingual-cased'
In [5]:
model_jp = CrossEncoder(model_save_path_jp)
model_us = CrossEncoder(model_save_path_us)
model_es = CrossEncoder(model_save_path_es)
processing test data¶
In [ ]:
input_dir = "data"
full_test_df = pd.read_csv(r"./task3/test_public-v0.3.csv")
print(full_test_df.shape)
full_test_df.head(3)
In [ ]:
product_df = pd.read_csv(r"./task3/product_catalogue-v0.3.csv")
print(product_df.shape)
product_df.head(3)
In [ ]:
product_df.isnull().sum(axis = 0)
In [ ]:
product_df.fillna("",inplace=True)
In [ ]:
product_df.isnull().sum(axis = 0)
In [ ]:
product_df['product_merge'] = product_df['product_title'] + ' ' + product_df['product_description'] + ' ' + product_df['product_bullet_point'] + ' ' + product_df['product_brand'] + ' ' + product_df['product_color_name']
In [ ]:
product_df['product_merge']
In [ ]:
full_test_df2 = pd.merge(full_test_df,
product_df[["product_id", "product_locale", "product_merge"]],
left_on=["product_id", "query_locale"],
right_on=["product_id", "product_locale"]
)
print(full_test_df2.shape)
full_test_df2.head()
In [9]:
full_test_df2.rename(columns={'product_merge': 'product_title'}, inplace=True)
In [10]:
full_test_df2
Out[10]:
In [11]:
full_test_df2 = full_test_df2[["example_id", "query", "product_title", "query_locale"]]
full_test_df2
Out[11]:
In [23]:
full_test_df2['substitute_label'] = 'kosong'
In [28]:
full_test_df2
Out[28]:
predict test data¶
In [26]:
from tqdm import tqdm
In [30]:
for i in tqdm(range(len(full_test_df2))):
if full_test_df2.iloc[i,3] == 'es' :
scores = model_es.predict([[full_test_df2.iloc[i,1], full_test_df2.iloc[i,2]]],show_progress_bar=False)
if full_test_df2.iloc[i,3] == 'us' :
scores = model_us.predict([[full_test_df2.iloc[i,1], full_test_df2.iloc[i,2]]],show_progress_bar=False)
if full_test_df2.iloc[i,3] == 'jp' :
scores = model_jp.predict([[full_test_df2.iloc[i,1], full_test_df2.iloc[i,2]]],show_progress_bar=False)
if scores[0] > 0.5 :
full_test_df2.iloc[i,-1] = 'substitute'
else :
full_test_df2.iloc[i,-1] = 'no_substitute'
In [31]:
full_test_df2[['example_id','substitute_label']]
Out[31]:
saving submission results¶
In [32]:
full_test_df2[['example_id','substitute_label']].to_csv('./task3/submission.csv',index=False)
Content
Comments
You must login before you can post a comment.