  Entanglement, as a key resource for modern quantum technologies, is extremely
fragile due to the decoherence. Here, we show that a quantum autoencoder, which
is trained to compress a particular set of quantum entangled states into a
subspace that is robust to decoherence, can be employed to preserve
entanglement. The training process is based on a hybrid quantum-classical
approach to improve the efficiency in building the autoencoder and reduce the
experimental errors during the optimization. Using nitrogen-vacancy centers in
diamond, we demonstrate that the entangled states between the electron and
nuclear spins can be encoded into the nucleus subspace which has much longer
coherence time. As a result, lifetime of the Bell states in this solid-spin
system is extended from 2.22 {\pm} 0.43 {\mu}s to 3.03 {\pm} 0.56 ms, yielding
a three orders of magnitude improvement. The quantum autoencoder approach is
universal, paving the way of utilizing long lifetime nuclear spins as
immediate-access quantum memories in quantum information tasks.
