Also, if he is in your bed with you, that can be fairly hormonally stimulating for them (blankets, pillows, shadowy spaces-boxes, under furniture, low ledges, bedding, crumbled paper etc all simulate nesting environments). Make sure you aren't allowing him around pillows/blankets/under furniture/ under clothing and make sure that you are petting on the head only. Snuggles send the wrong idea.
When we visited my parent's house, my too liked to sit on my dads back while he watched TV on his stomach on the bed with the blinds shut. She already loved him, but she was always a weirdo afterwards-- It definitely triggered a hormonal response (not because he was snuggling her, but because of the lighting, the environment and the company therein). You would be amazed at how fast it can happen (and the impact can last from a few minutes to a few weeks)...and it isn't always obvious that your bird is being hormonal...In fact, most people see it as super cute (acting goofy in shadowy spaces, trying to climb in your shirt/under your chin, wanting to cuddle, laying against chest, showing off, special attention to a certain person) or it sometimes shows up as problem behavior (screaming, biting, plucking, running after people, egg-binding etc etc).
If you have any tents/huts/boxes that he is allowed to play with in or around the cage, get rid of them. They are all hormonal triggers, but the huts and tents are super dangerous because they are known to kill birds due to intestinal blockages, strangulation etc etc.
In the event that this is hormonal, you will also want to make sure your bird is getting 10-14 hours of quiet, dark sleep each night. Try to ensure a light cycle as similar as what they would have in nature as they can (in terms of hours of light and dark). Too much light can cause hormonal reactions, but too little is equally problematic.
If hormones are at play, you will also want to evaluate the bird's toy situation (grass-type shredding toys can amplify issues during a hormonal spell, as can confetti-type toys) and avoid feeding warm/mushy foods (as this is similar to regurgitation and can be a trigger). Provide lots of things to entertain your bird during the day (excluding boxes and certain types of toys) and make sure he/she is getting plenty of opportunities to fly around or at least move outside of the cage.
Your bird could also be biting for attention (depending on what you are doing when he bites/what your reaction is ) but depending on age, hormones should always be considered as a possibility (but never used as a scapegoat---even hormonal behavior can be curbed).
It could be a combination of both (hormones and attention-biting (due to boredom etc)).
Right before he bites, what are you doing (watching TV, reading, closing your eyes etc?) If so- he may be trying to get you to pay attention to him...Especially if biting you causes you to stop what you are doing, make a sound, look at him, jerk your toe and start talking, interacting/scolding etc.
Is there anyone in bed next to you? This could also play into the situation. Sometimes, when hormonal, a bird will bite their mate in the presence of other potential suitors...I know that seems counter-intuitive (it can also go the other way, if you are in bed with their favorite person, they might go after you). It just depends, but the favorite person can sometimes get bitten as well (even though it is often their partner who gets bitten first).
When bitten, what do you and everyone else in the room do (what do you say, do you move, what happens to your volume, where do you look? etc etc).
If you are minding your own business and get bitten, the best course of action (if you don't know why you were bitten) is to completely ignore the bird. If that is not possible, you can try swiftly but calmly (and without eye contact etc) moving the bird to a timeout location and walk away (you can VERY CALMLY and quietly say "no bite" if you must, but keep in mind that many parrots like to bite and then say "NO BITE!" right afterwards lol-- Also, this time-out method only works if you are sure the bird has a bond with you and that the bite was intended to get your attention. Be mindful of the fact that if you take your bird to its cage every time it bites, it may notice the pattern and bite when it wants to go back to its cage---so you just have to be very good at watching for patterns and making sure that you aren't setting yourself up for failure.
It sounds like you need to build trust and set some boundaries. I am not a believer in dominance, but for safety reasons and for behavior reasons, you should be allowing a bird who isn't step-up trained on your head. Choose your words wisely...Don't run around saying step up when you know your bird won't do it (or you will be like the parent at the check-out screaming the same empty threats at their unruly kids over and over). To train your bird to step up, you will need a more controlled environment, like a t perch or the cage- During training sessions, pair your actions with words (e.g. step up) but you will want to make sure that the draw of stepping up is greater than the risk on staying put or failing to step up---if you tell your timid bird to step up and it doesn't but then you allow it to fly around the house right afterwards, you have provided little incentive. I am not saying to cage your bird until it steps up, but make sure that you consider these these directly before and after a training session.
Again though, just because your bird is interested in you and will perch on you doesn't mean he trusts you, which is why you need to work on building that relationship and setting routines/ boundaries. Try pairing yourself with food and ignore any behaviors that you do not want to see again. Once you establish trust, then you can start determining when best to use time-outs... but they have to be used mindfully. In a fear-biting bird, time-outs and shunning can actually feel like rewards (if they do not want you around, do not want to be touched or need a break from everybody).