  Aims. We present an innovative artificial neural network (ANN) architecture,
called Generative ANN (GANN), that computes the forward model, that is it
learns the function that relates the unknown outputs (stellar atmospheric
parameters, in this case) to the given inputs (spectra). Such a model can be
integrated in a Bayesian framework to estimate the posterior distribution of
the outputs. Methods. The architecture of the GANN follows the same scheme as a
normal ANN, but with the inputs and outputs inverted. We train the network with
the set of atmospheric parameters (Teff, logg, [Fe/H] and [alpha/Fe]),
obtaining the stellar spectra for such inputs. The residuals between the
spectra in the grid and the estimated spectra are minimized using a validation
dataset to keep solutions as general as possible. Results. The performance of
both conventional ANNs and GANNs to estimate the stellar parameters as a
function of the star brightness is presented and compared for different
Galactic populations. GANNs provide significantly improved parameterizations
for early and intermediate spectral types with rich and intermediate
metallicities. The behaviour of both algorithms is very similar for our sample
of late-type stars, obtaining residuals in the derivation of [Fe/H] and
[alpha/Fe] below 0.1dex for stars with Gaia magnitude Grvs<12, which accounts
for a number in the order of four million stars to be observed by the Radial
Velocity Spectrograph of the Gaia satellite. Conclusions. Uncertainty
estimation of computed astrophysical parameters is crucial for the validation
of the parameterization itself and for the subsequent exploitation by the
astronomical community. GANNs produce not only the parameters for a given
spectrum, but a goodness-of-fit between the observed spectrum and the predicted
one for a given set of parameters. Moreover, they allow us to obtain the full
posterior distribution...
