Is there some way for me to penalize a vector of 0's and 1's if they are not grouped?

I am using BCELoss for a multi-class problem. But in my case, the positive classes are next to each other. So I’m wondering if there’s some way for me to penalize if adjacent values are not the same?