Last active
August 14, 2023 17:22
-
-
Save codeKgu/52a6b66511977a28db74fb905c3aa231 to your computer and use it in GitHub Desktop.
Tutorial for multimodal_transformers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from multimodal_transformers.data import load_data | |
from transformers import AutoTokenizer | |
data_df = pd.read_csv('Womens Clothing E-Commerce Reviews.csv') | |
text_cols = ['Title', 'Review Text'] | |
# The label col is expected to contain integers from 0 to N_classes - 1 | |
label_col = 'Recommended IND' | |
categorical_cols = ['Clothing ID', 'Division Name', 'Department Name', 'Class Name'] | |
numerical_cols = ['Rating', 'Age', 'Positive Feedback Count'] | |
label_list = ['Not Recommended', 'Recommended'] # what each label class represents | |
tokenizer = AutoTokenizer.from_pretrained('bert-base-uncased') | |
# make sure NaN values for cat columns are filled before passing to load_data | |
for c in categorical_cols: | |
data_df.loc[:, c] = data_df.loc[:, c].astype(str).fillna("-9999999") | |
torch_dataset = load_data( | |
data_df, | |
text_cols, | |
tokenzier, | |
categorical_cols=categorical_cols, | |
numerical_cols=numerical_cols, | |
sep_text_token_str=tokenizer.sep_token | |
) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment