There is often a correlation between the chemical structure of a compound and its taste.

Low molecular weight salts taste salty
higher molecular weight salts bitterness.

Organic compounds containing hydroxyl (OH) groups  sweet taste

Organic compounds containing carbonyl (C=O) groups  sour taste

Overall, the taste of a compound is determined by the specific receptors on the taste buds that detect the compound and send signals to the brain. The structure of the compound plays a role in how it interacts with these receptors, leading to different taste sensations.