Two wheeled vehicle vertical stability is due to steering geometry, specifically trail. There are radio controlled motorcycles that don't require any special algorithims or gyro sensors to work, they just use a lot of trail, and a steering servo with a low resistance to small "non-commanded" movements caused by trail effect, allowing the self correction process to work.
Trail is the distance from where the front tire pivot point axis would intercept the pavement, back to the point where the front tire actually makes contact with the pavement.
When a bicycle is vertical, the trail creates a castor effect (like the wheels on a shopping cart), creating a tendency for the front tire to move in the direction traveled.
When a bicycle is leaned, the trail creates a inwards steering torque force on the front tire. This is because contact patch moves laterally when steering and vice versa. Suspend a bicycle off the ground. Steer left, and the contact patch area on the front tire will move right and vice versa. This lateral motion is relativly large on a radio control motorcycle, and moderate for human controlled bicycles / motorcycles. To see this effect, a person can hold a bicycle by the rear seat and lean it over, and the front tire will steer inwards.
Getting back to a leaned bicycle, gravity results in downwards force on the center of mass, and the pavement in turn generates an upwards force on the tires. At the front tire of a bicycle, this upwards force is applied "behind" the pivot axis and causes the front tire to steer inwards, and given suffiecient inwards steering and speed, the lean angle of the bicyle will be reduced until it is vertical again (it may overcorrect due to momentum).
The amount of trail effect determines the minimal speed required for vertical stability. At or above this minimum speed, a bicycle will be vertically stable, auto-correcting for any reasonable amount of lean introduced. If there is excessive trail, flex, or momentum, in the bicycle, constant overcorrection can occur, resutling in speed wobble.
Gyroscopic reaction generates lean angle stability (as opposed to vertical stability). As speed increases, a bicycle will tend to hold a lean angle and resist changes in lean angle, including the vertical stablity reaction from trail. In the case of motorcycles at high speeds, 100+mph, the lean stability dominates, and the motorcycle just holds a lean angle with no perceptible tendency to straighten up.
To induce a lean on a bicycle, motorcycle, or unicycle, a rider steers outwards to initiate a lean. The outwards steering can be the result of a rider applying an outwards steering torque force on the handlebars (counter-steering), or the result of the rider leaning inwards, causing the motorcycle to lean outwards (since the center of mass won't move sideways without a sideways force at the contact point between tires and pavement (or a side wind)), and the self-correcting geometry causes an outwards steering reaction to the motorcycle being leaned outwards. Deliberate counter-steering is best, since leaning doesn't provide as quick as a response, and at high speeds on a motorcycle, provides no lean inducing steering response.