I'm dividing by the number of components in the vector. This makes the magnitude of the cost function invariant to the number of classes (rather than growing linearly) which allows the same learning rates to be used for problems with different numbers of classes. I'm essentially just normalizing the cost function for the dimensionality of the input. It seems like the pylearn2 cost functions should already do this, but they don't...