import os
Roberta model (Regression)
In this series, we walk through some of the capability of this library: single-head classification, multi-head classification, multi-label classification, and regression. If you want a more detailed tutorial, check this out
#This will specify a (or a list) of GPUs for training
'CUDA_VISIBLE_DEVICES'] = "0" os.environ[
from that_nlp_library.text_transformation import *
from that_nlp_library.text_augmentation import *
from that_nlp_library.text_main import *
from that_nlp_library.utils import seed_everything
from underthesea import text_normalize
from functools import partial
from pathlib import Path
import pandas as pd
import numpy as np
import nlpaug.augmenter.char as nac
from datasets import load_dataset
import random
from transformers import RobertaTokenizer
from datasets import Dataset
from transformers.models.roberta.modeling_roberta import RobertaModel
import torch
Define the custom augmentation function
def nlp_aug_stochastic(x,aug=None,p=0.5):
if not isinstance(x,list):
if random.random()<p: return aug.augment(x)[0]
return x
=[]
news=[]
originalsfor _x in x:
if random.random()<p: news.append(_x)
else: originals.append(_x)
# only perform augmentation when needed
if len(news): news = aug.augment(news)
return news+originals
= nac.KeyboardAug(aug_char_max=3,aug_char_p=0.1,aug_word_p=0.07)
aug = partial(nlp_aug_stochastic,aug=aug,p=0.3) nearby_aug_func
Create a TextDataController object
We will reuse the data and the preprocessings in this tutorial
= load_dataset('sample_data',data_files=['Womens_Clothing_Reviews.csv'],split='train') dset
= TextDataController(dset,
tdc ='Review Text',
main_text='Rating',
label_names='regression',
sup_types={'Review Text': lambda x: x is not None},
filter_dict=['Title','Division Name'],
metadatas=[text_normalize,str.lower],
content_transformations= [nearby_aug_func,str.lower],
content_augmentations# add "str.lower" here because nearby_aug might return uppercase character
=0.2,
val_ratio=1000,
batch_size=42,
seed=20,
num_proc=False
verbose )
Define our tokenizer for Roberta
= RobertaTokenizer.from_pretrained('roberta-base') _tokenizer
Process and tokenize our dataset
=100,shuffle_trn=True) tdc.process_and_tokenize(_tokenizer,max_length
tdc.main_ddict
DatasetDict({
train: Dataset({
features: ['Title', 'Review Text', 'Rating', 'Division Name', 'label', 'input_ids', 'attention_mask'],
num_rows: 18112
})
validation: Dataset({
features: ['Title', 'Review Text', 'Rating', 'Division Name', 'label', 'input_ids', 'attention_mask'],
num_rows: 4529
})
})
Model Experiment: Roberta Single-Head Regression
from that_nlp_library.models.roberta.classifiers import *
from that_nlp_library.model_main import *
from sklearn.metrics import mean_absolute_error,mean_squared_log_error,f1_score, accuracy_score
Using HuggingFace model initialization
from transformers.models.roberta.modeling_roberta import RobertaForSequenceClassification
=1 num_classes
42)
seed_everything(= RobertaForSequenceClassification.from_pretrained('roberta-base',num_labels=num_classes)
model = model.to('cuda:0') model
Some weights of RobertaForSequenceClassification were not initialized from the model checkpoint at roberta-base and are newly initialized: ['classifier.out_proj.bias', 'classifier.dense.weight', 'classifier.dense.bias', 'classifier.out_proj.weight']
You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.
= [mean_absolute_error,mean_squared_log_error]
metric_funcs = ModelController(model,tdc,seed=42) controller
= 1e-4
lr =32
bs=0.01
wd= 3
epochs
controller.fit(epochs,lr,=metric_funcs,
metric_funcs=bs,
batch_size=wd,
weight_decay=False,
save_checkpoint=compute_metrics,
compute_metrics )
/home/quan/anaconda3/envs/fastai_v2/lib/python3.10/site-packages/transformers/optimization.py:411: FutureWarning: This implementation of AdamW is deprecated and will be removed in a future version. Use the PyTorch implementation torch.optim.AdamW instead, or set `no_deprecation_warning=True` to disable this warning
warnings.warn(
Epoch | Training Loss | Validation Loss | Mean Absolute Error Rating | Mean Squared Log Error Rating |
---|---|---|---|---|
1 | No log | 0.390571 | 0.395417 | 0.024300 |
2 | 1.053300 | 0.416924 | 0.460436 | 0.023507 |
3 | 1.053300 | 0.342913 | 0.397407 | 0.020786 |
Using Roberta-base model (no concatenation), but with a custom head to limit the output range
=1 num_classes
= RobertaModel.from_pretrained('roberta-base') roberta_body
Some weights of RobertaModel were not initialized from the model checkpoint at roberta-base and are newly initialized: ['roberta.pooler.dense.weight', 'roberta.pooler.dense.bias']
You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.
class RobertaSigmoidRange(torch.nn.Module):
def __init__(self,
config,
high,
low,**kwargs
):super().__init__()
self.high=high
self.low=low
self.score = torch.nn.Linear(config.hidden_size, config.num_labels, bias=False)
def forward(self, inp, **kwargs):
= self.score(inp)
logits return torch.sigmoid(logits)*(self.high-self.low)+self.low
={
_model_kwargs# overall model hyperparams
'head_class_sizes':num_classes,
'head_class': RobertaSigmoidRange,
# classfication head hyperparams
'high':5, # the maximum rating
'low': 1, # the minimum rating
}
= model_init_classification(model_class = RobertaBaseForSequenceClassification,
model = 'roberta-base',
cpoint_path =False,
output_hidden_states=42,
seed=roberta_body,
body_model= _model_kwargs) model_kwargs
Loading body weights. This assumes the body is the very first block of your custom architecture
= [mean_absolute_error,mean_squared_log_error]
metric_funcs = ModelController(model,tdc,seed=42) controller
42)
seed_everything(
= 1e-4
lr =32
bs=0.01
wd= 3
epochs
controller.fit(epochs,lr,=metric_funcs,
metric_funcs=bs,
batch_size=wd,
weight_decay=False,
save_checkpoint=compute_metrics,
compute_metrics )
/home/quan/anaconda3/envs/fastai_v2/lib/python3.10/site-packages/transformers/optimization.py:411: FutureWarning: This implementation of AdamW is deprecated and will be removed in a future version. Use the PyTorch implementation torch.optim.AdamW instead, or set `no_deprecation_warning=True` to disable this warning
warnings.warn(
Epoch | Training Loss | Validation Loss | Mean Absolute Error Rating | Mean Squared Log Error Rating |
---|---|---|---|---|
1 | No log | 0.366913 | 0.412213 | 0.023336 |
2 | 0.494600 | 0.320408 | 0.386471 | 0.020400 |
3 | 0.494600 | 0.313202 | 0.371211 | 0.019664 |
Using the Roberta custom model (concatenation)
from transformers.models.roberta.modeling_roberta import RobertaModel
=1 num_classes
= RobertaModel.from_pretrained('roberta-base') roberta_body
Some weights of RobertaModel were not initialized from the model checkpoint at roberta-base and are newly initialized: ['roberta.pooler.dense.bias', 'roberta.pooler.dense.weight']
You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.
={
_model_kwargs# overall model hyperparams
'head_class_sizes':num_classes,
'head_class': ConcatHeadSimple,
# classfication head hyperparams
'layer2concat':4,
'classifier_dropout':0.1
}
= model_init_classification(model_class = RobertaHiddenStateConcatForSequenceClassification,
model = 'roberta-base',
cpoint_path =True, # since we are using 'hidden layer contatenation' technique
output_hidden_states=42,
seed=roberta_body,
body_model= _model_kwargs) model_kwargs
Loading body weights. This assumes the body is the very first block of your custom architecture
Total parameters: 124648705
Total trainable parameters: 124648705
= [mean_absolute_error,mean_squared_log_error]
metric_funcs = ModelController(model,tdc,seed=42) controller
42)
seed_everything(
= 1e-4
lr =32
bs=0.01
wd= 3
epochs
controller.fit(epochs,lr,=metric_funcs,
metric_funcs=bs,
batch_size=wd,
weight_decay=False,
save_checkpoint=compute_metrics,
compute_metrics )
Epoch | Training Loss | Validation Loss | Mean Absolute Error Rating | Mean Squared Log Error Rating |
---|---|---|---|---|
1 | No log | 0.526983 | 0.560607 | 0.029044 |
2 | 1.226800 | 0.338014 | 0.397377 | 0.021910 |
3 | 1.226800 | 0.332928 | 0.389946 | 0.020401 |
'./sample_weights/my_model') controller.trainer.model.save_pretrained(
Predict Validation
_model_kwargs
{'head_class_sizes': 1,
'head_class': that_nlp_library.models.roberta.classifiers.ConcatHeadSimple,
'layer2concat': 4,
'classifier_dropout': 0.1}
= model_init_classification(model_class = RobertaHiddenStateConcatForSequenceClassification,
trained_model = Path('./sample_weights/my_model'),
cpoint_path =True,
output_hidden_states=42,
seed= _model_kwargs)
model_kwargs
= ModelController(trained_model,tdc,seed=42) controller
Some weights of the model checkpoint at sample_weights/my_model were not used when initializing RobertaHiddenStateConcatForSequenceClassification: ['body_model.pooler.dense.weight', 'body_model.pooler.dense.bias']
- This IS expected if you are initializing RobertaHiddenStateConcatForSequenceClassification from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).
- This IS NOT expected if you are initializing RobertaHiddenStateConcatForSequenceClassification from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).
Total parameters: 124058113
Total trainable parameters: 124058113
= controller.predict_ddict(ds_type='validation') df_val
-------------------- Start making predictions --------------------
= df_val.to_pandas()
df_val df_val.head()
Title | Review Text | Rating | Division Name | label | input_ids | attention_mask | pred_Rating | |
---|---|---|---|---|---|---|---|---|
0 | general . . this picture doesn't do the skirt ... | 5.0 | general | 5.0 | [0, 15841, 479, 479, 42, 2170, 630, 75, 109, 5... | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... | 5.009285 | |
1 | general . . easy to wear ! cute , comfy ... wi... | 4.0 | general | 4.0 | [0, 15841, 479, 479, 1365, 7, 3568, 27785, 119... | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... | 4.959775 | |
2 | general . . nice sweater , just did not look g... | 3.0 | general | 3.0 | [0, 15841, 479, 479, 2579, 23204, 2156, 95, 22... | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... | 2.813448 | |
3 | nice cropped jacket | general . nice cropped jacket . this jacket wa... | 5.0 | general | 5.0 | [0, 15841, 479, 2579, 30197, 8443, 479, 42, 84... | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... | 4.425314 |
4 | great dress! | general petite . great dress ! . i wasn't plan... | 5.0 | general petite | 5.0 | [0, 15841, 4716, 1459, 479, 372, 3588, 27785, ... | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... | 5.152634 |
You can try to get your metric to see if it matches your last traing epoch’s above
'label'],df_val['pred_Rating'])
mean_absolute_error(df_val[# 0.3844665757181577
0.38998359958971274
'label'],df_val['pred_Rating'])
mean_squared_log_error(df_val[# 0.020327507632071154
0.020402761232161202
Predict Test set
We will go through details on how to make a prediction on a completely new and raw dataset using our trained model. For now, let’s reuse the sample csv and pretend it’s our test set
= pd.read_csv('sample_data/Womens_Clothing_Reviews.csv',encoding='utf-8-sig').sample(frac=0.2,random_state=1)
df_test
# save the label, as we will calculate some metrics later
= df_test[~df_test['Review Text'].isna()].Rating.values
true_labels
# drop the label (you don't need to, but this is necessary to simulate an actual test set)
'Rating',axis=1,inplace=True) df_test.drop(
= Dataset.from_pandas(df_test)
_test_dset = controller.predict_raw_dset(_test_dset,
_test_dset_predicted =True, # since we have some text filtering in the processing
do_filtering )
-------------------- Start making predictions --------------------
= _test_dset_predicted.to_pandas() df_test_predicted
df_test_predicted.head()
Title | Review Text | Division Name | input_ids | attention_mask | pred_Rating | |
---|---|---|---|---|---|---|
0 | perfect for work and play | general . perfect for work and play . this shi... | general | [0, 15841, 479, 1969, 13, 173, 8, 310, 479, 42... | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... | 5.153669 |
1 | general petite . . i don't know why i had the ... | general petite | [0, 15841, 4716, 1459, 479, 479, 939, 218, 75,... | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... | 4.160178 | |
2 | great pants | general petite . great pants . thes e cords ar... | general petite | [0, 15841, 4716, 1459, 479, 372, 9304, 479, 5,... | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... | 5.120962 |
3 | surprisingly comfy for a button down | general petite . surprisingly comfy for a butt... | general petite | [0, 15841, 4716, 1459, 479, 10262, 3137, 24382... | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... | 4.653287 |
4 | short and small | general petite . short and small . the shirt i... | general petite | [0, 15841, 4716, 1459, 479, 765, 8, 650, 479, ... | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... | 2.688593 |
Let’s quickly check the score to make sure everything works correctly
'pred_Rating']) mean_absolute_error(true_labels,df_test_predicted[
0.3419881553779289
'pred_Rating']) mean_squared_log_error(true_labels,df_test_predicted[
0.016165478401855043
={'Review Text': 'This shirt is so comfortable I love it!',
raw_content'Title': 'Great shirt',
'Division Name': 'general'}
raw_content
{'Review Text': 'This shirt is so comfortable I love it!',
'Title': 'Great shirt',
'Division Name': 'general'}
= controller.predict_raw_text(raw_content) df_result
-------------------- Start making predictions --------------------
df_result
{'Review Text': ['general . great shirt . this shirt is so comfortable i love it !'],
'Title': ['great shirt'],
'Division Name': ['general'],
'input_ids': [[0,
15841,
479,
372,
6399,
479,
42,
6399,
16,
98,
3473,
939,
657,
24,
27785,
2]],
'attention_mask': [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]],
'pred_Rating': [5.104530334472656]}
Model Experiment: Roberta Multi-Head Regression
from that_nlp_library.models.roberta.classifiers import *
from that_nlp_library.model_main import *
from sklearn.metrics import mean_absolute_error,mean_squared_log_error,f1_score, accuracy_score
Re-define the TextDataController
= load_dataset('sample_data',data_files=['Womens_Clothing_Reviews.csv'],split='train') dset
= TextDataController(dset,
tdc ='Review Text',
main_text=['Rating','Department Name'],
label_names=['regression','classification'],
sup_types={'Review Text': lambda x: x is not None,
filter_dict'Department Name': lambda x: x is not None},
=['Title'],
metadatas=[text_normalize,str.lower],
content_transformations= [nearby_aug_func,str.lower],
content_augmentations# add "str.lower" here because nearby_aug might return uppercase character
=0.2,
val_ratio=1000,
batch_size=42,
seed=20,
num_proc=False
verbose )
Define our tokenizer for Roberta
= RobertaTokenizer.from_pretrained('roberta-base') _tokenizer
Process and tokenize our dataset
=100,shuffle_trn=True) tdc.process_and_tokenize(_tokenizer,max_length
tdc.main_ddict
DatasetDict({
train: Dataset({
features: ['Title', 'Review Text', 'Rating', 'Department Name', 'label', 'input_ids', 'attention_mask'],
num_rows: 18101
})
validation: Dataset({
features: ['Title', 'Review Text', 'Rating', 'Department Name', 'label', 'input_ids', 'attention_mask'],
num_rows: 4526
})
})
tdc.label_lists
[[], ['Bottoms', 'Dresses', 'Intimate', 'Jackets', 'Tops', 'Trend']]
Using the Roberta custom model (concatenation)
from transformers.models.roberta.modeling_roberta import RobertaModel
=[1,len(tdc.label_lists[1])] # 1 head size 1 for regression, 1 head size 6 for classification
num_classes num_classes
[1, 6]
= RobertaModel.from_pretrained('roberta-base') roberta_body
Some weights of RobertaModel were not initialized from the model checkpoint at roberta-base and are newly initialized: ['roberta.pooler.dense.bias', 'roberta.pooler.dense.weight']
You should probably TRAIN this model on a down-stream task to be able to use it for predictions and inference.
={
_model_kwargs# overall model hyperparams
'head_class_sizes':num_classes,
'head_class': ConcatHeadSimple,
# classfication head hyperparams
'layer2concat':3,
'classifier_dropout':0.1
}
= model_init_classification(model_class = RobertaHiddenStateConcatForSequenceClassification,
model = 'roberta-base',
cpoint_path =True, # since we are using 'hidden layer contatenation' technique
output_hidden_states=42,
seed=roberta_body,
body_model= _model_kwargs) model_kwargs
Loading body weights. This assumes the body is the very first block of your custom architecture
Total parameters: 124661767
Total trainable parameters: 124661767
If you use multihead
and each head does a different supervised learning type (as in this case when you have both classification and regression head), and you have separate metric for each type, you must define a metric_types
to let the controller knows what metric functions to apply for each head
= [mean_absolute_error,mean_squared_log_error,partial(f1_score,average='macro'),accuracy_score]
metric_funcs = ['regression','regression','classification','classification'] metric_types
= ModelController(model,tdc,seed=42) controller
42)
seed_everything(
= 1e-4
lr =32
bs=0.01
wd= 3
epochs
controller.fit(epochs,lr,=metric_funcs,
metric_funcs=metric_types,
metric_types=bs,
batch_size=wd,
weight_decay=False,
save_checkpoint=compute_metrics,
compute_metrics )
Epoch | Training Loss | Validation Loss | Mean Absolute Error Rating | Mean Squared Log Error Rating | F1 Score Department name | Accuracy Score Department name |
---|---|---|---|---|---|---|
1 | No log | 0.895920 | 0.443452 | 0.025369 | 0.656077 | 0.869200 |
2 | 1.819800 | 0.737174 | 0.423700 | 0.021711 | 0.674119 | 0.881794 |
3 | 1.819800 | 0.730880 | 0.397481 | 0.021648 | 0.684661 | 0.884887 |
'./sample_weights/my_model') controller.trainer.model.save_pretrained(
Predict Validation
_model_kwargs
{'head_class_sizes': [1, 6],
'head_class': that_nlp_library.models.roberta.classifiers.ConcatHeadSimple,
'layer2concat': 3,
'classifier_dropout': 0.1}
= model_init_classification(model_class = RobertaHiddenStateConcatForSequenceClassification,
trained_model = Path('./sample_weights/my_model'),
cpoint_path =True,
output_hidden_states=42,
seed= _model_kwargs)
model_kwargs
= ModelController(trained_model,tdc,seed=42) controller
Some weights of the model checkpoint at sample_weights/my_model were not used when initializing RobertaHiddenStateConcatForSequenceClassification: ['body_model.pooler.dense.weight', 'body_model.pooler.dense.bias']
- This IS expected if you are initializing RobertaHiddenStateConcatForSequenceClassification from the checkpoint of a model trained on another task or with another architecture (e.g. initializing a BertForSequenceClassification model from a BertForPreTraining model).
- This IS NOT expected if you are initializing RobertaHiddenStateConcatForSequenceClassification from the checkpoint of a model that you expect to be exactly identical (initializing a BertForSequenceClassification model from a BertForSequenceClassification model).
Total parameters: 124071175
Total trainable parameters: 124071175
= controller.predict_ddict(ds_type='validation') df_val
-------------------- Start making predictions --------------------
= df_val.to_pandas()
df_val df_val.head()
Title | Review Text | Rating | Department Name | label | input_ids | attention_mask | pred_Rating | pred_Department Name | pred_prob_Department Name | |
---|---|---|---|---|---|---|---|---|---|---|
0 | . such a fun jacket ! great to wear in the spr... | 5.0 | Intimate | [5.0, 2.0] | [0, 4, 215, 10, 1531, 8443, 27785, 372, 7, 356... | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... | 5.087322 | Jackets | 0.884425 | |
1 | simple and elegant | simple and elegant . i thought this shirt was ... | 5.0 | Tops | [5.0, 4.0] | [0, 41918, 8, 14878, 479, 939, 802, 42, 6399, ... | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... | 3.857383 | Tops | 0.989074 |
2 | retro and pretty | retro and pretty . this top has a bit of a ret... | 5.0 | Tops | [5.0, 4.0] | [0, 4903, 1001, 8, 1256, 479, 42, 299, 34, 10,... | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... | 4.827574 | Tops | 0.985488 |
3 | summer/fall wear | summer / fall wear . i first spotted this on a... | 5.0 | Dresses | [5.0, 1.0] | [0, 18581, 2089, 1589, 1136, 3568, 479, 939, 7... | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... | 5.098561 | Dresses | 0.984738 |
4 | perfect except slip | perfect except slip . this is my new favorite ... | 4.0 | Dresses | [4.0, 1.0] | [0, 20473, 4682, 9215, 479, 42, 16, 127, 92, 2... | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... | 3.854942 | Dresses | 0.974034 |
You can try to get your metric to see if it matches your last traing epoch’s above
'Rating'],df_val['pred_Rating']) mean_absolute_error(df_val[
0.39745882958160583
'Rating'],df_val['pred_Rating']) mean_squared_log_error(df_val[
0.021647425684093793
'Department Name'],df_val['pred_Department Name'],average='macro') f1_score(df_val[
0.6845558685013334
Predict Test set
We will go through details on how to make a prediction on a completely new and raw dataset using our trained model. For now, let’s reuse the sample csv and pretend it’s our test set
= pd.read_csv('sample_data/Womens_Clothing_Reviews.csv',encoding='utf-8-sig').sample(frac=0.2,random_state=1)
df_test
# drop the label (you don't need to, but this is necessary to simulate an actual test set)
'Rating','Department Name'],axis=1,inplace=True) df_test.drop([
= Dataset.from_pandas(df_test)
_test_dset = controller.predict_raw_dset(_test_dset,
_test_dset_predicted =True, # since we have some text filtering in the processing
do_filtering=3
topk )
-------------------- Start making predictions --------------------
= _test_dset_predicted.to_pandas() df_test_predicted
df_test_predicted.head()
Title | Review Text | input_ids | attention_mask | pred_Rating | pred_Department Name | pred_prob_Department Name | |
---|---|---|---|---|---|---|---|
0 | perfect for work and play | perfect for work and play . this shirt works f... | [0, 20473, 13, 173, 8, 310, 479, 42, 6399, 136... | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... | 5.025642 | [Tops, Intimate, Dresses] | [0.9891802, 0.00918336, 0.0005342441] |
1 | . i don't know why i had the opposite problem ... | [0, 4, 939, 218, 75, 216, 596, 939, 56, 5, 548... | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... | 4.258958 | [Bottoms, Intimate, Trend] | [0.9956339, 0.0024540052, 0.0011451989] | |
2 | great pants | great pants . thes e cords are great--lightwei... | [0, 12338, 9304, 479, 5, 29, 364, 37687, 32, 3... | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... | 5.143690 | [Bottoms, Intimate, Trend] | [0.9899479, 0.008132041, 0.0010822185] |
3 | surprisingly comfy for a button down | surprisingly comfy for a button down . i am a ... | [0, 33258, 3137, 24382, 13, 10, 6148, 159, 479... | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... | 4.399732 | [Tops, Intimate, Dresses] | [0.9533946, 0.03952966, 0.004206666] |
4 | short and small | short and small . the shirt is mostly a thick ... | [0, 20263, 8, 650, 479, 5, 6399, 16, 2260, 10,... | [1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, ... | 2.788084 | [Tops, Intimate, Jackets] | [0.91881263, 0.076821946, 0.0015537328] |
={'Review Text': 'This shirt is so comfortable I love it!',
raw_content'Title': 'Great shirt'}
raw_content
{'Review Text': 'This shirt is so comfortable I love it!',
'Title': 'Great shirt'}
= controller.predict_raw_text(raw_content) df_result
-------------------- Start making predictions --------------------
df_result
{'Review Text': ['great shirt . this shirt is so comfortable i love it !'],
'Title': ['great shirt'],
'input_ids': [[0,
12338,
6399,
479,
42,
6399,
16,
98,
3473,
939,
657,
24,
27785,
2]],
'attention_mask': [[1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]],
'pred_Rating': [5.002801418304443],
'pred_Department Name': ['Tops'],
'pred_prob_Department Name': [0.9914304614067078]}