The rapid process of urbanization and industrial development has raised significant concerns regarding the presence and management of hazardous substances. However, conventional methods employed for identifying hazardous substances and monitoring urban safety often suffer from low efficiency and accuracy. This paper proposes a novel approach that combines deep learning and genetic algorithms, which utilizes the Bidirectional Long Short-Term Memory model to capture temporal features in hazardous substance data and introduces the Attention Mechanism for weighted processing of crucial information, thereby improving recognition capability. Genetic Algorithms are employed to optimize the performance and generalization capacity of the deep learning model. Experimental validation demonstrates that the proposed approach achieves higher accuracy and faster processing speed, effectively enhancing urban safety monitoring. This research holds practical implications for urban safety management and accident prevention, offering an innovative solution to guarantee urban safety.