Taking granite as an example, the meso-scopic compositions of the rock were identified. The meso-scopic compositions features of rock failure precursor under uniaxial compression were then investigated. Sparrow search algorithm (SSA) is used to modify long short-term memory (LSTM). The meso-scopic composition precursors of rock failure were therefore predicted. It shows that the second rapid increase of crack area and the second rapid decrease of quartz or feldspar area may be used as a precursor of rock failure; the precursor time of rock failure based on meso-scopic compositions is about 4 s earlier than that observed to the naked eye; the modified LSTM has the strongest estimation ability for quartz precursor, followed by feldspar, and the worst estimation ability for cracks.