Shuu12121 / CodeMorph-ModernBERT

huggingface.co
Total runs: 110
24-hour runs: 0
7-day runs: 0
30-day runs: 0
Model's Last Updated: March 07 2025
fill-mask

Introduction of CodeMorph-ModernBERT

Model Details of CodeMorph-ModernBERT

CodeMorph-ModernBERT (For Busy People)

CodeMorph-ModernBERT is a cutting-edge model specialized in code search and code understanding tasks.
It supports a maximum sequence length of 2048 tokens (compared to Microsoft's 512 tokens), and it delivers exceptional performance, especially for Python code search.

Key Features
  • Long Sequence Support
    Capable of processing sequences up to 2048 tokens. This allows it to handle long code snippets and complex functions.

  • High Code Search Accuracy
    Utilizes a SentencePiece-based tokenizer, developed for six languages including Python, achieving significantly better search precision than previous models.

  • Purpose-Built Training
    Trained from scratch on the CodeSearchNet dataset, enabling deep understanding of code syntax and the relationship with comments.

Parameter Settings
Parameter Name Default/Configured Value
vocab_size 50000
hidden_size 768
num_hidden_layers 12
num_attention_heads 12
intermediate_size 3072
max_position_embeddings 2048
type_vocab_size 2
hidden_dropout_prob 0.1
attention_probs_dropout_prob 0.1
local_attention_window 128
rope_theta 160000
local_attention_rope_theta 10000

CodeMorph-ModernBERT(忙しい人向け)

CodeMorph-ModernBERT は、コード検索およびコード理解タスクに特化した最新のモデルです。
最大シーケンス長2048トークン (従来のMicrosoftモデルは512トークン)に対応し、特にPythonコード検索において抜群の性能を発揮します。

主な特徴
  • 長いシーケンス対応
    最大2048トークンのシーケンス処理が可能。長いコードや複雑な関数にも対応します。

  • 高いコード検索性能
    Pythonをはじめとする6言語対応のSentencepieceを用いて作成したトークナイザを採用し、従来モデルを大幅に上回る検索精度を実現しています。

  • 専用にトレーニングされたモデル
    CodeSearchNetデータセットを活用して1から学習。コード特有の文法やコメントとの関係を深く理解します。

パラメータについて
パラメータ名 設定値
vocab_size 50000
hidden_size 768
num_hidden_layers 12
num_attention_heads 12
intermediate_size 3072
max_position_embeddings 2048
type_vocab_size 2
hidden_dropout_prob 0.1
attention_probs_dropout_prob 0.1
local_attention_window 128
rope_theta 160000
local_attention_rope_theta 10000

CodeMorph-ModernBERT is a pre-trained model specifically designed for code search and code understanding tasks. This model has been trained from scratch using the code-search-net/code_search_net dataset to enhance semantic comprehension of code.

  • Architecture : ModernBERT-based
  • Purpose : Code Search / Code Understanding / Code Completion
  • Training Data : CodeSearchNet (All Languages)
  • License : Apache 2.0
Features
  • Trained from Scratch : Unlike traditional NLP models that rely on transfer learning, this model has been pre-trained specifically for code.
  • Custom Tokenizer : A dedicated tokenizer was designed using the CodeSearchNet dataset to optimize code search capabilities.
  • High-Precision Search Performance : Outperforms existing models such as CodeBERT and CodeT5 in search accuracy.
How to Use the Model

The model can be easily loaded using the Hugging Face Transformers library. ( Note: Only compatible with Transformers version 4.48.0 or later )

Loading the Model
from transformers import AutoModelForMaskedLM, AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("Shuu12121/CodeMorph-ModernBERT")
model = AutoModelForMaskedLM.from_pretrained("Shuu12121/CodeMorph-ModernBERT")
Masked Language Model (fill-mask)
from transformers import pipeline

fill_mask = pipeline("fill-mask", model=model, tokenizer=tokenizer)
print(fill_mask("def add_numbers(a, b): return a + [MASK]"))
Extracting Code Embeddings
import torch

def get_embedding(text, model, tokenizer, device="cuda"):
    inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=256)
    if "token_type_ids" in inputs:
        inputs.pop("token_type_ids")
    inputs = {k: v.to(device) for k, v in inputs.items()}
    outputs = model.model(**inputs)
    embedding = outputs.last_hidden_state[:, 0, :]
    return embedding

embedding = get_embedding("def my_function(): pass", model, tokenizer)
print(embedding.shape)
Dataset

This model has been trained using the code-search-net/code_search_net dataset, which contains code snippets from multiple programming languages (Python, Java, JavaScript, etc.), making it highly suitable for code search tasks.

Evaluation Results

The model was evaluated using the Python subset of the code_x_glue_ct_code_to_text dataset. Below are the key evaluation metrics: For more details on the experiment, refer to this link .

Metric Score
MRR (Mean Reciprocal Rank) 0.8172
MAP (Mean Average Precision) 0.8172
R-Precision 0.7501
Recall@10 0.9389
Precision@10 0.8143
NDCG@10 0.8445
F1@10 0.8423
Comparison with Other Models

The table below compares CodeMorph-ModernBERT with other leading code search models:

Model MRR MAP R-Precision
CodeMorph-ModernBERT 0.8172 0.8172 0.7501
microsoft/graphcodebert-base 0.5482 0.5482 0.4458
microsoft/codebert-base-mlm 0.5243 0.5243 0.4378
Salesforce/codet5p-220m-py 0.7512 0.7512 0.6617
Salesforce/codet5-large-ntp-py 0.7846 0.7846 0.7067
Shuu12121/CodeMorph-BERT 0.6851 0.6851 0.5934
Shuu12121/CodeMorph-BERTv2 0.6535 0.6535 0.5543

CodeMorph-ModernBERT achieves significantly higher search accuracy compared to other CodeBERT and CodeT5 models.

License

This model is released under the Apache-2.0 license.

概要

CodeMorph-ModernBERT は、コード検索およびコード理解のタスク向けに1からトレーニングした事前学習済みモデルです。本モデルは code-search-net/code_search_net データセットを活用し、コードの意味的な理解を強化するために訓練されています。

  • アーキテクチャ : ModernBERT ベース
  • 目的 : コード検索 / コード理解 / コード補完
  • トレーニングデータ : CodeSearchNet (全言語)
  • ライセンス : Apache 2.0
特徴
  • ゼロからの学習 : 一般的な NLP モデルの転移学習ではなく、コード特化の事前学習を行いました。
  • カスタムトークナイザ : CodeSearchNet をもとにコード検索向けに独自にトークナイザを設計しました。
  • 高精度の検索性能 : 既存の CodeBERT や CodeT5 と比較して優れた検索性能を発揮。
モデルの使用方法

Hugging Face Transformers ライブラリを利用して、本モデルを簡単にロードできます。(※ Transformers のバージョンは 4.48.0 以上のみ動作します)

モデルのロード
from transformers import AutoModelForMaskedLM, AutoTokenizer

tokenizer = AutoTokenizer.from_pretrained("Shuu12121/CodeMorph-ModernBERT")
model = AutoModelForMaskedLM.from_pretrained("Shuu12121/CodeMorph-ModernBERT")
マスク補完 (fill-mask)
from transformers import pipeline

fill_mask = pipeline("fill-mask", model=model, tokenizer=tokenizer)
print(fill_mask("def add_numbers(a, b): return a + [MASK]"))
コード埋め込みの取得
import torch

def get_embedding(text, model, tokenizer, device="cuda"):
    inputs = tokenizer(text, return_tensors="pt", truncation=True, max_length=256)
    if "token_type_ids" in inputs:
        inputs.pop("token_type_ids")
    inputs = {k: v.to(device) for k, v in inputs.items()}
    outputs = model.model(**inputs)
    embedding = outputs.last_hidden_state[:, 0, :]
    return embedding

embedding = get_embedding("def my_function(): pass", model, tokenizer)
print(embedding.shape)
データセット

本モデルは code-search-net/code_search_net データセットを使用して訓練されました。このデータセットは、複数のプログラミング言語 (Python, Java, JavaScript など) に関するコードスニペットを含んでおり、コード検索タスクに最適です。

評価結果

本モデルは code_x_glue_ct_code_to_text データセットのPythonの部分を用いて評価されました。以下は主要な評価指標です。 また実験の詳細については こちら を確認してください。

指標 スコア
MRR (Mean Reciprocal Rank) 0.8172
MAP (Mean Average Precision) 0.8172
R-Precision 0.7501
Recall@10 0.9389
Precision@10 0.8143
NDCG@10 0.8445
F1@10 0.8423
他のモデルとの比較

以下は、CodeMorph-ModernBERT と他の主要なコード検索モデルの比較結果です。

モデル MRR MAP R-Precision
CodeMorph-ModernBERT 0.8172 0.8172 0.7501
microsoft/graphcodebert-base 0.5482 0.5482 0.4458
microsoft/codebert-base-mlm 0.5243 0.5243 0.4378
Salesforce/codet5p-220m-py 0.7512 0.7512 0.6617
Salesforce/codet5-large-ntp-py 0.7846 0.7846 0.7067
Shuu12121/CodeMorph-BERT 0.6851 0.6851 0.5934
Shuu12121/CodeMorph-BERTv2 0.6535 0.6535 0.5543
Code Search モデル評価結果 (google/code_x_glue_tc_nl_code_search_adv データセット Test)

以下に、google/code_x_glue_tc_nl_code_search_adv データセット (Test) を使用した、各種Code Searchモデルの評価結果をまとめます。候補プールサイズは全て100です。 また追加実験のコードは こちら です

モデル MRR MAP R-Precision
Shuu12121/CodeMorph-ModernBERT 0.6107 0.6107 0.5038
Salesforce/codet5p-220m-py 0.5037 0.5037 0.3805
Salesforce/codet5-large-ntp-py 0.4872 0.4872 0.3658
microsoft/graphcodebert-base 0.3844 0.3844 0.2764
microsoft/codebert-base-mlm 0.3766 0.3766 0.2683
Shuu12121/CodeMorph-BERTv2 0.3142 0.3142 0.2166
Shuu12121/CodeMorph-BERT 0.2978 0.2978 0.1992

CodeMorph-ModernBERT は、他の CodeBERT や CodeT5 モデルと比較して、より高い検索精度を達成しています。

ライセンス

本モデルは Apache-2.0 ライセンスのもとで提供されます。

Runs of Shuu12121 CodeMorph-ModernBERT on huggingface.co

110
Total runs
0
24-hour runs
0
3-day runs
0
7-day runs
0
30-day runs

More Information About CodeMorph-ModernBERT huggingface.co Model

More CodeMorph-ModernBERT license Visit here:

https://choosealicense.com/licenses/apache-2.0

CodeMorph-ModernBERT huggingface.co

CodeMorph-ModernBERT huggingface.co is an AI model on huggingface.co that provides CodeMorph-ModernBERT's model effect (), which can be used instantly with this Shuu12121 CodeMorph-ModernBERT model. huggingface.co supports a free trial of the CodeMorph-ModernBERT model, and also provides paid use of the CodeMorph-ModernBERT. Support call CodeMorph-ModernBERT model through api, including Node.js, Python, http.

CodeMorph-ModernBERT huggingface.co Url

https://huggingface.co/Shuu12121/CodeMorph-ModernBERT

Shuu12121 CodeMorph-ModernBERT online free

CodeMorph-ModernBERT huggingface.co is an online trial and call api platform, which integrates CodeMorph-ModernBERT's modeling effects, including api services, and provides a free online trial of CodeMorph-ModernBERT, you can try CodeMorph-ModernBERT online for free by clicking the link below.

Shuu12121 CodeMorph-ModernBERT online free url in huggingface.co:

https://huggingface.co/Shuu12121/CodeMorph-ModernBERT

CodeMorph-ModernBERT install

CodeMorph-ModernBERT is an open source model from GitHub that offers a free installation service, and any user can find CodeMorph-ModernBERT on GitHub to install. At the same time, huggingface.co provides the effect of CodeMorph-ModernBERT install, users can directly use CodeMorph-ModernBERT installed effect in huggingface.co for debugging and trial. It also supports api for free installation.

CodeMorph-ModernBERT install url in huggingface.co:

https://huggingface.co/Shuu12121/CodeMorph-ModernBERT

Url of CodeMorph-ModernBERT

CodeMorph-ModernBERT huggingface.co Url

Provider of CodeMorph-ModernBERT huggingface.co

Shuu12121
ORGANIZATIONS

Other API from Shuu12121