The polarity of a molecule defines its other physical properties such as melting point, boiling point, surface tension, vapor pressure etc... Simply, polarity occurs when the electron distribution in a molecule is asymmetric. This results in a net dipole moment in the molecule. One end of the molecule is charged negative while the other gets a positive charge.
The polarization of a molecule greatly depends on the shape of the molecule. A diatomic molecule like HF mentioned above has no issue of shape. The net dipole moment is only due to the uneven distribution of electrons between the two atoms. However, when there are more than two atoms involved in making a bond, there are many complexities.
The water molecule is of bent shape. Therefore, when the two pair of electrons shared by oxygen with two hydrogen atoms is pulled towards oxygen, the net dipole moment results in the direction of the oxygen atom. There is no other force to cancel out the resultant dipole moment. Hence, the water molecule is highly polar.
Ammonia molecule is of a pyramid shape and the electronegative N atom pulls the electrons towards itself. The three N-H bonds are not in the same plane; hence the dipole moments created do not get canceled out. This makes ammonia a polar molecule.
However, the dipole moments sometimes get canceled due to the shape of the molecules, making the molecule non-polar. Carbon dioxide is such a molecule.