  This paper explores three different strategies for the inversion of spectral
lines (and their Stokes profiles) using artificial neural networks. It is shown
that a straightforward approach in which the network is trained with synthetic
spectra from a simplified model leads to considerable errors in the inversion
of real observations. This problem can be overcome in at least two different
ways that are studied here in detail. The first method makes use of an
additional pre-processing auto-associative neural network to project the
observed profile into the theoretical model subspace. The second method
considers a suitable regularization of the neural network used for the
inversion. These new techniques are shown to be robust and reliable when
applied to the inversion of both synthetic and observed data, with errors
typically below $\sim$100 G.
