Representation learning for OOD detection and explanation