Electrical and all-optical poling of nonlinear optical materials: relaxation dynamics