Learning and Exploiting Relational Structure for Efficient Inference