Learning Representations for Reasoning: Generalizing Across Diverse Structures