Algorithm or function or model that encourages clustered classfication?
Why not create another set of classes which corresponds to the groups you want? This works if you care more about groups. Later on you can subsequently classify within groups. Another idea would be to devise a loss function which penalize less within group misclassification and more outside group classification but this involves going into implementation details of your NN. As an idea it would involve writing something like softmax multiplied with misclassification cost matrix