Optimizations for embed and marginalization