# TCCCD: Triplet-Based Cross-Language Code Clone Detection
## 4 Proposed Approach
### Code Representation  
After the data processing step, we fine-tuned the UniXcoder pre-trained model to obtain more-effective code representation. Our fine-tuning procedure included the following steps:  
1. **Tokenization:** Code snippets were subjected to a tokenization process, whereby UniXcoder was utilized as the tokenizer to segment the source code snippets into subwords, resulting in the transformation of the source code into a words list. When UniXcoder tokenizes the source code, it segments source code snippets into subwords. These subwords can include identifiers, keywords, operators, and more from the source code. This tokenization process helps to illustrate the abstract hierarchy of the source code, transforming it into smaller semantic units for subsequent representation and learning. The list of these subwords forms an abstract representation of the source code, providing a more-informative input for our method.
2. **Sequence aggregation:** After tokenization, special tokens [CLS] (abbreviation of Classification) and [SEP] (abbreviation of Separator) are incorporated into the vocabulary  
Figure 2: Overview of TCCCD. (In Process (**a**), the same color pairs represent the code pairs belonging to the same task, but in different programming languages. In Process (**b**), the same color token sequences represent the sequences belonging to the same task, but in different programming languages. After tokenization, UniXcoder converts the sequences into code representation. In Process (**c**), the symbols with the same color and shape stand for code representation vectors belonging to the same task. Next, they are selected to form triplets, and after triplet learning, they are effectively classified in the vector space).  
list, with the [CLS] token marking the beginning of the source code and the [SEP] token indicating the end of the source code, respectively. Finally, the tokenized source code is represented as a sequence of tokens, denoted as \([CLS,\omega_{1},\omega_{2},\omega_{3},...,\omega_{n},SEP]\). Then, we replaced the subwords of each code snippet with their corresponding IDs using the tokenizer function and, then, aggregated them into sequences. Because the maximum input token sequence length for the pre-trained model UniXcoder is 512, the token sequence in our approach was also limited to a maximum length of 512.
3. **Batch creation:** To enhance efficiency in processing and training, we created batches comprising the aggregated sequences. These sequences were grouped into batches, where each batch consisted of pairs of sequences belonging to the same task, but in different programming languages, as well as pairs of sequences from diverse tasks using different programming languages.
4. **Vector generation:** We took the sequences within a batch as the inputs to the UniXcoder model, and the output of UniXcoder included both the contextual vector representations for each token and the sentence representation corresponding to the [CLS] token, which represents the entire code snippet.  
During the fine-tuning process, we applied various data-processing techniques and adjusted the model parameters to obtain more-effective code representation. We preprocessed the dataset to consist of clone code pairs from the same task, but implemented in different programming languages, making it better suited for our proposed approach. Then, we fine-tuned the parameters of UniXcoder to achieve optimal effectiveness, including parameters such as the learning rate and batch size. More-specific details can be found in Section 4.3. Additionally, by learning to minimize the triplet loss, the UniXcoder model can enhance its representational capacity, thereby improving its effectiveness.