Text this: Optimal weighting for estimating generalized average treatment effects