# Custom BCEWithLogitsLoss for Sequence Classification using Auto Model

**URL:** <https://discuss.huggingface.co/t/custom-bcewithlogitsloss-for-sequence-classification-using-auto-model/156809>\
**Category:** Beginners\
**Created:** [May 26, 2025, 9:31am UTC](https://discuss.huggingface.co/t/custom-bcewithlogitsloss-for-sequence-classification-using-auto-model/156809 "2025-05-26T09:31:29Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![John6666](https://sea2.discourse-cdn.com/hellohellohello/user_avatar/discuss.huggingface.co/john6666/32/27664_2.png) [@John6666](https://discuss.huggingface.co/u/John6666)\
**Post date:** [May 26, 2025, 11:10am UTC](https://discuss.huggingface.co/t/custom-bcewithlogitsloss-for-sequence-classification-using-auto-model/156809/2 "2025-05-26T11:10:35Z")

</div>

Hmm…

> **[HELP with multilabel classification and BCEWithLogitsLoss](https://discuss.pytorch.org/t/help-with-multilabel-classification-and-bcewithlogitsloss/208094)**
>
> Im trying to classificate multilabels for sentiment analysis. first i separate the data and pass the batch on BERT layer, that encodes and generate embedding. So i create a NN that uses this data from BERT to classify and output a 16 layer data...

> [@Mismatched target and input size for BCE using "multi\_label\_classification"](https://discuss.huggingface.co/t/mismatched-target-and-input-size-for-bce-using-multi-label-classification/8706):
>
> I am trying to build a multi-label, multi-class classification model. Any input text can have zero or more labels, up to 11 possible classes. I have been trying to use the problem\_type="multi\_label\_classification" and everything looks OK, but I get ValueError: Target size (torch.Size([16, 11])) must be the same as input size (torch.Size([16, 2])) when it tries to calculate the binary\_cross\_entropy\_with\_logits I presume my data is in the wrong shape somehow, but I can’t see where exactly. Any s…

> **[ValueError: Target size (torch.Size(\[32\])) must be the same as input size...](https://discuss.pytorch.org/t/valueerror-target-size-torch-size-32-must-be-the-same-as-input-size-torch-size-32-25/182495)**
>
> Hi, Trying to fine-tune a Convnext Tiny model. This is an initialization of the model. from transformers import AutoModelForImageClassification,ConvNextFeatureExtractor,get\_linear\_schedule\_with\_warmup model =...

> BCEWithLogitsLoss is for Binary 0 or 1 use torch.nn.CrossEntropyLoss

---

_[View the full topic](https://discuss.huggingface.co/t/custom-bcewithlogitsloss-for-sequence-classification-using-auto-model/156809)._
