label_cols = ["toxic", "severe_toxic"]
databunch = TextDataBunch.from_df(".", train, val, test,
tokenizer=fastai_tokenizer,
vocab=fastai_bert_vocab,
include_bos=False,
include_eos=False,
text_cols=“comment_text”,
label_cols=label_cols,
bs=config.bs,
collate_fn=partial(pad_collate, pad_first=False, pad_idx=0),
)
from pytorch_pretrained_bert.modeling import BertConfig, BertForSequenceClassification
bert_model = BertForSequenceClassification.from_pretrained(config.bert_model_name, num_labels=2)
Code Works fine when I have two labels columns as my target. But when I have:
label_cols = [“toxic”]
bert_model = BertForSequenceClassification.from_pretrained(config.bert_model_name, num_labels=1)
Gives me error
ValueError: Target size (torch.Size([32])) must be the same as input size (torch.Size([32, 1]))