why sometimes gravity be taken as negative?
It all depends on your conventions and frame of reference. Gravity is always acting vertically downwards. If you take all quantities moving in the upward direction as positive, then acceleration due to gravity would be taken as negative and vice versa.