In some aspects, polarization of a spin ensemble can be increased using cavity-based techniques. A resonator applies drive field to a spin ensemble in a static magnetic field. The drive field couples the spin ensemble with a cavity, and the coupling increases the polarization of the spin ensemble. In some cases, the cavity is detuned from the spin- resonance frequency, and the Rabi frequency associated with the drive field can be matched to the cavity detuning.