Amortized inference for structured deep generative models