Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to train binary classification #4

Open
ps3-app opened this issue Jan 20, 2021 · 1 comment
Open

How to train binary classification #4

ps3-app opened this issue Jan 20, 2021 · 1 comment

Comments

@ps3-app
Copy link

ps3-app commented Jan 20, 2021

I use sentiment analysis with bert, however it is multiclass classification, how to change for binary class text classification.

@kforcodeai
Copy link

Same as multiclass classification with few modifications.

  1. n_classes = 2, in last layer , self.out = nn.Linear(self.bert.config.hidden_size, n_classes), actually this will be automatically handled by the code for mutlicalss classification itself --- model = SentimentClassifier(len(class_names))
  2. replace softmax with sigmoid here --- F.softmax(model(input_ids, attention_mask), dim=1)
  3. loss function should be changed to BinaryCrossEntropyLoss i.e nn.BCELoss() from ---- loss_fn = nn.CrossEntropyLoss().to(device)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants