  M dwarfs have enormous potential for our understanding of structure and
formation on both Galactic and exoplanetary scales through their properties and
compositions. However, current atmosphere models have limited ability to
reproduce spectral features in stars at the coolest temperatures ($T_{\rm eff}
< 4200\,$K) and to fully exploit the information content of current and
upcoming large-scale spectroscopic surveys. Here we present a catalog of
spectroscopic temperatures, metallicities, and spectral types for 5875 M dwarfs
in the Apache Point Observatory Galactic Evolution Experiment (APOGEE) and Gaia
DR2 surveys using The Cannon: a flexible, data-driven spectral-modeling and
parameter-inference framework demonstrated to estimate stellar-parameter labels
($T_{\rm eff}$, log$g$, [Fe/H], and detailed abundances) to high precision.
Using a training sample of 87 M dwarfs with optically derived labels spanning
$2860 < T_{\rm eff} < 4130\,$K calibrated with bolometric temperatures, and
$-0.5 < $[Fe/H]$ < 0.5\,$dex calibrated with FGK binary metallicities, we train
a two-parameter model with predictive accuracy (in cross-validation) to $77\,$K
and $0.09\,$dex respectively. We also train a one-dimensional spectral
classification model using 51 M dwarfs with Sloan Digital Sky Survey optical
spectral types ranging from M0 to M6, to predictive accuracy of 0.7 types. We
find Cannon temperatures to be in agreement to within $60\,$K compared to a
subsample of 1702 sources with color-derived temperatures, and Cannon
metallicities to be in agreement to within $0.08\,$dex metallicity compared to
a subsample of 15 FGK+M or M+M binaries. Finally, our comparison between Cannon
and APOGEE pipeline (ASPCAP DR14) labels finds that ASPCAP is systematically
biased toward reporting higher temperatures and lower metallicities for M
dwarfs.
