If it is a front head lock where your arm is caught along with the head

Then take the arm that is trapped in the headlock, grab his elbow swing yoruself hard in the same direction as the arm that you have trapped.
Or if they have a headlock on you without trapping your arm, it is called a guillotine.

Let us say you are caught in the guillotine just like in this picture. First you should point your chin towards his elbow and try to tuck your chin in so you can breathe. Have your right hand come up on his arm and tug it down to take a little bit of the pressure off. Next take your left arm and bring it over his right shoulder. Now use the arm to pull yourself up use one of your legs to hook his. What this does is hang all your weight on him. He should not be able to put too much pressure on you at this point. At this point use your free arm(the arm that is tugging his arm down so you can breathe) to try to work your head out form there.