An essential step in the discovery of new drugs and materials is thesynthesis of a molecule that exists so far only as an idea to test itsbiological and physical properties. While computer-aided design of virtualmolecules has made large progress, computer-assisted synthesis planning (CASP)to realize physical molecules is still in its infancy and lacks a performancelevel that would enable large-scale molecule discovery. CASP supports thesearch for multi-step synthesis routes, which is very challenging due to highbranching factors in each synthesis step and the hidden rules that govern thereactions. The central and repeatedly applied step in CASP is reactionprediction, for which machine learning methods yield the best performance. Wepropose a novel reaction prediction approach that uses a deep learningarchitecture with modern Hopfield networks (MHNs) that is optimized bycontrastive learning. An MHN is an associative memory that can store andretrieve chemical reactions in each layer of a deep learning architecture. Weshow that our MHN contrastive learning approach enables few- and zero-shotlearning for reaction prediction which, in contrast to previous methods, candeal with rare, single, or even no training example(s) for a reaction. On awell established benchmark, our MHN approach pushes the state-of-the-artperformance up by a large margin as it improves the predictive top-100 accuracyfrom $0.858\pm0.004$ to $0.959\pm0.004$. This advance might pave the way tolarge-scale molecule discovery.