Magic moments for structured output prediction