Device-to-device (D2D) communications promise spectral and energy efficiency, total system capacity, and excellent data rates. These improvements in network performance led to much D2D research, but it revealed significant difficulties before their full potential could be realized in 5G networks. D2D communication in 5G networks can bring about performance gains regarding spectral and energy efficiency, total system capacity, and data rate. The major challenge in the 5G network is to meet latency, bandwidth, and traffic density requirements. In addition, the next generation of cellular networks must have increased throughput, decreased power consumption, and guaranteed Quality of Service. This potential, however, is associated with substantial difficulties. To address these challenges and improve the system capabilities of D2D networks, a deep learning-based Improved D2D communication (DLID2DC) model has been proposed. The proposed model is explicitly intended for 5G networks, using the exterior public cloud to replace automation with an explainable artificial intelligence (XAI) method to analyze communication needs. The communicated needs allow a selection of methodologies to transfer machine data from the remote server to the smart devices. The model utilizes deep learning algorithms for resource allocation in D2D communication to maximize the utilization of available spectrum resources. Experimental tests prove that the DLID2DC model brings about better throughput, lower end-to-end delay, better fairness, and improved energy efficiency than traditional methods.