Inferring physical properties of galaxies from their emission-line spectra