# Model never predicts minority class in a binary sequence classification

**URL:** <https://discuss.huggingface.co/t/model-never-predicts-minority-class-in-a-binary-sequence-classification/9637>\
**Category:** Beginners\
**Created:** [August 31, 2021, 5:40pm UTC](https://discuss.huggingface.co/t/model-never-predicts-minority-class-in-a-binary-sequence-classification/9637 "2021-08-31T17:40:53Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![SonuG](https://avatars.discourse-cdn.com/v4/letter/s/858c86/32.png) [@SonuG](https://discuss.huggingface.co/u/SonuG)\
**Post date:** [September 1, 2021, 2:10am UTC](https://discuss.huggingface.co/t/model-never-predicts-minority-class-in-a-binary-sequence-classification/9637/3 "2021-09-01T02:10:58Z")

</div>

Thank you for your response. I have over-written compute\_loss function as follows -

```auto
class CustomTrainer(Trainer):        
    def compute_loss(self, model, inputs, return_outputs=False):
        class_weights = torch.FloatTensor([1./5542, 1./36587]).cuda()
        labels = inputs.pop("labels")
        outputs = model(**inputs)
        logits = outputs.logits
        loss_fct = CrossEntropyLoss(weight=class_weights)
        #loss = loss_fct(outputs,labels)
        loss = loss_fct(logits.view(-1, self.model.config.num_labels),
                        labels.float().view(-1, self.model.config.num_labels))
        return (loss, outputs) if return_outputs else loss

```

Is it all that I need to change? because I get an `ValueError: Expected input batch_size (16) to match target batch_size (8).` How can I change shapes of output and labels here?

---

_[View the full topic](https://discuss.huggingface.co/t/model-never-predicts-minority-class-in-a-binary-sequence-classification/9637)._
