Fix to gradient failure in categorical