A mass spectrometer identifies a molecular structure from the spectrum obtained by fitting to a database, but it is difficult to identify an unmeasured molecule. In this study, we developed a deep learning method that learns spectra in a database to infer the molecular structure. Since the inference is done by assembling the molecular structure, it is possible to infer even if the molecular structure is not in the database. By using the latent expression of the molecular structure, we succeeded in inferring the molecular structure with high similarity.