An ancient poem generation method and apparatus based on artificial intelligence, and a device and a storage medium. The method comprises: obtaining a keyword contained in an ancient poem generation request (S10); determining a target type for generating an ancient poem according to the keyword (S20); inputting the keyword into a preset Transformer model, and generating a first poem draft according to the target type (S30), performing occlusion training by using a pre-trained language model to obtain a temporary first poem draft; and comparing each prediction character in the temporary first poem draft with the corresponding occluded character; if the prediction character is different from the occluded character, continuing performing iterative occlusion prediction on the temporary first poem draft until each prediction character is the same as the corresponding occluded character, and taking the obtained temporary first poem draft as a target poem. By means of a loop iteration mode and a pre-trained language model, occlusion prediction is performed on each character in the temporary first poem draft in sequence, so that each character is continuously updated according to the overall context, and the quality of generating the ancient poem is improved.
展开▼