Largely through simple memorization. You learn the genders over time. There is a general rule that nouns ending in आ are masculine and nouns ending in ई are feminine. Though there are a few exceptions I would say this rule apples 95% of the time. Nouns not ending in either you just have to memorize.