How do I move specific bones like the torso or head when an animation is playing?

My human characters have a walk and run animation. At some point, I need to move the head to look up and down but they snap back when I lift up the controller buttons, so I have to keep the buttons pressed.

How can I fix this?

I am using transform.Rotate

Thanks in advance if you care to share a solution

You can use animation rigging to override animation or an avatar mask in the animator controller that will prevent those pieces of the character from being controlled by the animation

masks are way to go or you have to use a toggle to override in every frame after animation pass.