Learning with latent networks