Loglinear Models with Latent Variables