The Tibet ASγ experiment has been observing cosmic gamma rays and cosmic rays in the energy range from teraelectron volts to several tens of petaelectron volts with a surface detector array since 1990. The derivation of cosmic gamma-ray flux is made by finding the excess distribution of the arrival direction of air showers above background cosmic rays. In 2014, the underground water Cherenkov muon detector (MD) was added to separate cosmic gamma rays from the background on the basis of the muon-less feature of the air showers of gamma-ray origin; hybrid observations using these two detectors were started at this time. In the present study, we developed methods to separate gamma-ray-induced air showers and hadronic cosmic-ray-induced ones using the measured particle number density distribution to improve the sensitivity of cosmic gamma-ray measurements using the Tibet air shower array data alone before the installation of the MD. We tested two approaches based on neural networks. The first method used feature values representing the lateral spread of the secondary particles, and the second method used the shower image data. To compare the separation performance of each method, we analyzed Monte Carlo air shower events in the vertically incident direction with mono-initial-energy gamma rays and protons. When discriminated by a single feature, the feature with the highest separation performance has an area under the curve (AUC) value of 0.701 for a gamma-ray energy of 10 TeV and 0.808 for 100 TeV. A separation method with a multilayer perceptron (MLP) based on multiple features has AUC values of 0.761 for a gamma-ray energy of 10 TeV and 0.854 for 100 TeV, which represents an improvement of approximately 5% in the AUC value compared with the single-feature case. We also found that the feature values that effectively contribute to the separation vary depending on the energy. A separation method with a convolutional neural network (CNN) using the shower image data has AUC values of 0.781 for a gamma-ray energy of 10 TeV and 0.901 for 100 TeV, which are approximately 5% higher than those of the MLP method. We applied the CNN separation method to Monte Carlo gamma-ray and cosmic-ray events from the Crab Nebula in the energy range 10–100 TeV. The AUC values range from 0.753 to 0.879, and the significance of the observed gamma-ray excess is improved by 1.3 to 1.8 times compared with the case without the separation procedure.