Artificial neural networks (NNs) are trained, based on the numerical database, to predict the no-wall and ideal-wall β N limits, due to onset of the n = 1 (n is the toroidal mode number) ideal external kink instability, for the HL-2M tokamak. The database is constructed by toroidal computations utilizing both the equilibrium code CHEASE (Lütjens et al 1992 Comput. Phys. Commun. 69 287) and the stability code MARS-F (Liu et al 2000 Phys. Plasmas 7 3681). The stability results show that (1) the plasma elongation generally enhances both β N limits, for either positive or negative triangularity plasmas; (2) the effect is more pronounced for positive triangularity plasmas; (3) the computed no-wall β N limit linearly scales with the plasma internal inductance, with the proportionality coefficient ranging between 1 and 5 for HL-2M; (4) the no-wall limit substantially decreases with increasing pressure peaking factor. Furthermore, both the NN model and the convolutional neural network (CNN) model are trained and tested, producing consistent results. The trained NNs predict both the no-wall and ideal-wall limits with as high as 95% accuracy, compared to those directly computed by the stability code. Additional test cases, produced by the Tokamak Simulation Code (Jardin et al 1993 Nucl. Fusion 33 371), also show reasonable performance of the trained NNs, with the relative error being within 10%. The constructed database provides effective references for the future HL-2M operations. The trained NNs can be used as a real-time monitor for disruption prevention in the HL-2M experiments, or serve as part of the integrated modeling tools for ideal kink stability analysis.