Solar flares are the most violent activities in the solar system, which are caused by the evolution of magnetic field in solar active regions. However, the mechanism which triggers solar flares is still an active research area and many algorithms based on different models are proposed to forecast solar flares. In this paper, we propose a novel data-driven method to forecast solar flares, which is built with convolutional neural network and long short term memory neural network. Our method could precept continuous magnetic field observation data with 6 hours long and predict the probability of flares of different classes in the next 24 hours with a Bayesian neural network. Comparing with traditional method, our method could not only forecast solar flares with high precision rate and low false alarm rate, but also highlight the region which would trigger solar flares with the class activation mapping (CAM). The inception obtained by the CAM could help scientists to dig deeper into physical mechanism which triggers solar flares. We use our method to process real observation data. Results show that our model mainly focuses on the region with strong magnetic field, the polarity reversal line and the magnetic field conversion area, which is consistent to theoretical predictions.