Saved in:
Bibliographic Details
Main Authors: Bartkowiak, Patryk, Graliński, Filip
Format: Preprint
Published: 2025
Subjects:
Online Access:https://arxiv.org/abs/2507.04003
Tags: Add Tag
No Tags, Be the first to tag this record!
_version_ 1866909676037210112
author Bartkowiak, Patryk
Graliński, Filip
author_facet Bartkowiak, Patryk
Graliński, Filip
contents Transformer-based models have demonstrated significant success in various source code representation tasks. Nonetheless, traditional positional embeddings employed by these models inadequately capture the hierarchical structure intrinsic to source code, typically represented as Abstract Syntax Trees (ASTs). To address this, we propose a novel tree-based positional embedding approach that explicitly encodes hierarchical relationships derived from ASTs, including node depth and sibling indices. These hierarchical embeddings are integrated into the transformer architecture, specifically enhancing the CodeBERTa model. We thoroughly evaluate our proposed model through masked language modeling (MLM) pretraining and clone detection fine-tuning tasks. Experimental results indicate that our Tree-Enhanced CodeBERTa consistently surpasses the baseline model in terms of loss, accuracy, F1 score, precision, and recall, emphasizing the importance of incorporating explicit structural information into transformer-based representations of source code.
format Preprint
id arxiv_https___arxiv_org_abs_2507_04003
institution arXiv
publishDate 2025
record_format arxiv
spellingShingle Seamlessly Integrating Tree-Based Positional Embeddings into Transformer Models for Source Code Representation
Bartkowiak, Patryk
Graliński, Filip
Machine Learning
Transformer-based models have demonstrated significant success in various source code representation tasks. Nonetheless, traditional positional embeddings employed by these models inadequately capture the hierarchical structure intrinsic to source code, typically represented as Abstract Syntax Trees (ASTs). To address this, we propose a novel tree-based positional embedding approach that explicitly encodes hierarchical relationships derived from ASTs, including node depth and sibling indices. These hierarchical embeddings are integrated into the transformer architecture, specifically enhancing the CodeBERTa model. We thoroughly evaluate our proposed model through masked language modeling (MLM) pretraining and clone detection fine-tuning tasks. Experimental results indicate that our Tree-Enhanced CodeBERTa consistently surpasses the baseline model in terms of loss, accuracy, F1 score, precision, and recall, emphasizing the importance of incorporating explicit structural information into transformer-based representations of source code.
title Seamlessly Integrating Tree-Based Positional Embeddings into Transformer Models for Source Code Representation
topic Machine Learning
url https://arxiv.org/abs/2507.04003