Variational inference of factor graphs