The invention belongs to the technical field of
software engineering, and discloses a token-level
semantic matching-based
code annotation generation method and
system, and the method comprises the following steps: obtaining a target code and a
data set, carrying out the preprocessing and dividing, and obtaining a
training set as a corpus; performing word segmentation on the codes in the corpus by using a word segmentation device of a pre-trained large
language model, and extracting and storing a context semantic embedding vector of each token in the codes to form a code semantic warehouse; calculating the lexical similarity between the target code and the code in the corpus, and taking the top k high examples as candidate examples; according to the method, a target code and a candidate sample are subjected to token-level
semantic matching, the most similar token in another
code segment is matched, the accuracy rate and the
recall rate are combined to obtain an F1
score, and the sample with the highest
score is reused, the context
semantic feature of fine
granularity is considered in the aspect of retrieval, the
code annotation generation precision is improved, extra training is not needed, and the retrieval efficiency is improved. And the method has good applicability to different scenes.