CoolFace
Modelpublic

Shuu12121/CodeSearch-ModernBERT-Finch

sourceHugging Faceupdated 1y agoView on Hugging Face
0likes79downloads
Model Card

SentenceTransformer based on Shuu12121/CodeModernBERT-Finch

This is a sentence-transformers model finetuned from Shuu12121/CodeModernBERT-Finch. It maps sentences & paragraphs to a 512-dimensional dense vector space and can be used for semantic textual similarity, semantic search, paraphrase mining, text classification, clustering, and more.

Model Details

Model Description

  • Model Type: Sentence Transformer
  • Base model: Shuu12121/CodeModernBERT-Finch <!-- at revision cb1142a6a402471e02d11005b239f349c6d79be0 -->
  • Maximum Sequence Length: 1024 tokens
  • Output Dimensionality: 512 dimensions
  • Similarity Function: Cosine Similarity <!-- - Training Dataset: Unknown --> <!-- - Language: Unknown --> <!-- - License: Unknown -->

Model Sources

Full Model Architecture

SentenceTransformer(
  (0): Transformer({'max_seq_length': 1024, 'do_lower_case': False, 'architecture': 'ModernBertModel'})
  (1): Pooling({'word_embedding_dimension': 512, 'pooling_mode_cls_token': True, 'pooling_mode_mean_tokens': False, 'pooling_mode_max_tokens': False, 'pooling_mode_mean_sqrt_len_tokens': False, 'pooling_mode_weightedmean_tokens': False, 'pooling_mode_lasttoken': False, 'include_prompt': True})
)

Usage

Direct Usage (Sentence Transformers)

First install the Sentence Transformers library:

bash
pip install -U sentence-transformers

Then you can load this model and run inference.

python
from sentence_transformers import SentenceTransformer

# Download from the 🤗 Hub
model = SentenceTransformer("sentence_transformers_model_id")
# Run inference
sentences = [
    '// reBuild partially rebuilds a site given the filesystem events.\n// It returns whetever the content source was changed.\n// TODO(bep) clean up/rewrite this method.',
    'func (s *Site) processPartial(events []fsnotify.Event) (whatChanged, error) {\n\n\tevents = s.filterFileEvents(events)\n\tevents = s.translateFileEvents(events)\n\n\ts.Log.DEBUG.Printf("Rebuild for events %q", events)\n\n\th := s.h\n\n\t// First we need to determine what changed\n\n\tvar (\n\t\tsourceChanged       = []fsnotify.Event{}\n\t\tsourceReallyChanged = []fsnotify.Event{}\n\t\tcontentFilesChanged []string\n\t\ttmplChanged         = []fsnotify.Event{}\n\t\tdataChanged         = []fsnotify.Event{}\n\t\ti18nChanged         = []fsnotify.Event{}\n\t\tshortcodesChanged   = make(map[string]bool)\n\t\tsourceFilesChanged  = make(map[string]bool)\n\n\t\t// prevent spamming the log on changes\n\t\tlogger = helpers.NewDistinctFeedbackLogger()\n\t)\n\n\tcachePartitions := make([]string, len(events))\n\n\tfor i, ev := range events {\n\t\tcachePartitions[i] = resources.ResourceKeyPartition(ev.Name)\n\n\t\tif s.isContentDirEvent(ev) {\n\t\t\tlogger.Println("Source changed", ev)\n\t\t\tsourceChanged = append(sourceChanged, ev)\n\t\t}\n\t\tif s.isLayoutDirEvent(ev) {\n\t\t\tlogger.Println("Template changed", ev)\n\t\t\ttmplChanged = append(tmplChanged, ev)\n\n\t\t\tif strings.Contains(ev.Name, "shortcodes") {\n\t\t\t\tshortcode := filepath.Base(ev.Name)\n\t\t\t\tshortcode = strings.TrimSuffix(shortcode, filepath.Ext(shortcode))\n\t\t\t\tshortcodesChanged[shortcode] = true\n\t\t\t}\n\t\t}\n\t\tif s.isDataDirEvent(ev) {\n\t\t\tlogger.Println("Data changed", ev)\n\t\t\tdataChanged = append(dataChanged, ev)\n\t\t}\n\t\tif s.isI18nEvent(ev) {\n\t\t\tlogger.Println("i18n changed", ev)\n\t\t\ti18nChanged = append(dataChanged, ev)\n\t\t}\n\t}\n\n\t// These in memory resource caches will be rebuilt on demand.\n\tfor _, s := range s.h.Sites {\n\t\ts.ResourceSpec.ResourceCache.DeletePartitions(cachePartitions...)\n\t}\n\n\tif len(tmplChanged) > 0 || len(i18nChanged) > 0 {\n\t\tsites := s.h.Sites\n\t\tfirst := sites[0]\n\n\t\ts.h.init.Reset()\n\n\t\t// TOD(bep) globals clean\n\t\tif err := first.Deps.LoadResources(); err != nil {\n\t\t\treturn whatChanged{}, err\n\t\t}\n\n\t\tfor i := 1; i < len(sites); i++ {\n\t\t\tsite := sites[i]\n\t\t\tvar err error\n\t\t\tdepsCfg := deps.DepsCfg{\n\t\t\t\tLanguage:      site.language,\n\t\t\t\tMediaTypes:    site.mediaTypesConfig,\n\t\t\t\tOutputFormats: site.outputFormatsConfig,\n\t\t\t}\n\t\t\tsite.Deps, err = first.Deps.ForLanguage(depsCfg, func(d *deps.Deps) error {\n\t\t\t\td.Site = &site.Info\n\t\t\t\treturn nil\n\t\t\t})\n\t\t\tif err != nil {\n\t\t\t\treturn whatChanged{}, err\n\t\t\t}\n\t\t}\n\t}\n\n\tif len(dataChanged) > 0 {\n\t\ts.h.init.data.Reset()\n\t}\n\n\tfor _, ev := range sourceChanged {\n\t\tremoved := false\n\n\t\tif ev.Op&fsnotify.Remove == fsnotify.Remove {\n\t\t\tremoved = true\n\t\t}\n\n\t\t// Some editors (Vim) sometimes issue only a Rename operation when writing an existing file\n\t\t// Sometimes a rename operation means that file has been renamed other times it means\n\t\t// it\'s been updated\n\t\tif ev.Op&fsnotify.Rename == fsnotify.Rename {\n\t\t\t// If the file is still on disk, it\'s only been updated, if it\'s not, it\'s been moved\n\t\t\tif ex, err := afero.Exists(s.Fs.Source, ev.Name); !ex || err != nil {\n\t\t\t\tremoved = true\n\t\t\t}\n\t\t}\n\t\tif removed && IsContentFile(ev.Name) {\n\t\t\th.removePageByFilename(ev.Name)\n\t\t}\n\n\t\tsourceReallyChanged = append(sourceReallyChanged, ev)\n\t\tsourceFilesChanged[ev.Name] = true\n\t}\n\n\tfor shortcode := range shortcodesChanged {\n\t\t// There are certain scenarios that, when a shortcode changes,\n\t\t// it isn\'t sufficient to just rerender the already parsed shortcode.\n\t\t// One example is if the user adds a new shortcode to the content file first,\n\t\t// and then creates the shortcode on the file system.\n\t\t// To handle these scenarios, we must do a full reprocessing of the\n\t\t// pages that keeps a reference to the changed shortcode.\n\t\tpagesWithShortcode := h.findPagesByShortcode(shortcode)\n\t\tfor _, p := range pagesWithShortcode {\n\t\t\tcontentFilesChanged = append(contentFilesChanged, p.File().Filename())\n\t\t}\n\t}\n\n\tif len(sourceReallyChanged) > 0 || len(contentFilesChanged) > 0 {\n\t\tvar filenamesChanged []string\n\t\tfor _, e := range sourceReallyChanged {\n\t\t\tfilenamesChanged = append(filenamesChanged, e.Name)\n\t\t}\n\t\tif len(contentFilesChanged) > 0 {\n\t\t\tfilenamesChanged = append(filenamesChanged, contentFilesChanged...)\n\t\t}\n\n\t\tfilenamesChanged = helpers.UniqueStrings(filenamesChanged)\n\n\t\tif err := s.readAndProcessContent(filenamesChanged...); err != nil {\n\t\t\treturn whatChanged{}, err\n\t\t}\n\n\t}\n\n\tchanged := whatChanged{\n\t\tsource: len(sourceChanged) > 0 || len(shortcodesChanged) > 0,\n\t\tother:  len(tmplChanged) > 0 || len(i18nChanged) > 0 || len(dataChanged) > 0,\n\t\tfiles:  sourceFilesChanged,\n\t}\n\n\treturn changed, nil\n\n}',
    'func WebPageImageResolver(doc *goquery.Document) ([]candidate, int) {\n\timgs := doc.Find("img")\n\n\tvar candidates []candidate\n\tsignificantSurface := 320 * 200\n\tsignificantSurfaceCount := 0\n\tsrc := ""\n\timgs.Each(func(i int, tag *goquery.Selection) {\n\t\tvar surface int\n\t\tsrc = getImageSrc(tag)\n\t\tif src == "" {\n\t\t\treturn\n\t\t}\n\n\t\twidth, _ := tag.Attr("width")\n\t\theight, _ := tag.Attr("height")\n\t\tif width != "" {\n\t\t\tw, _ := strconv.Atoi(width)\n\t\t\tif height != "" {\n\t\t\t\th, _ := strconv.Atoi(height)\n\t\t\t\tsurface = w * h\n\t\t\t} else {\n\t\t\t\tsurface = w\n\t\t\t}\n\t\t} else {\n\t\t\tif height != "" {\n\t\t\t\tsurface, _ = strconv.Atoi(height)\n\t\t\t} else {\n\t\t\t\tsurface = 0\n\t\t\t}\n\t\t}\n\n\t\tif surface > significantSurface {\n\t\t\tsignificantSurfaceCount++\n\t\t}\n\n\t\ttagscore := score(tag)\n\t\tif tagscore >= 0 {\n\t\t\tc := candidate{\n\t\t\t\turl:     src,\n\t\t\t\tsurface: surface,\n\t\t\t\tscore:   score(tag),\n\t\t\t}\n\t\t\tcandidates = append(candidates, c)\n\t\t}\n\t})\n\n\tif len(candidates) == 0 {\n\t\treturn nil, 0\n\t}\n\n\treturn candidates, significantSurfaceCount\n\n}',
]
embeddings = model.encode(sentences)
print(embeddings.shape)
# [3, 512]

# Get the similarity scores for the embeddings
similarities = model.similarity(embeddings, embeddings)
print(similarities)
# tensor([[1.0000, 0.6671, 0.2242],
#         [0.6671, 1.0000, 0.3125],
#         [0.2242, 0.3125, 1.0000]])

<!--

Direct Usage (Transformers)

<details><summary>Click to see the direct usage in Transformers</summary>

</details> -->

<!--

Downstream Usage (Sentence Transformers)

You can finetune this model on your own dataset.

<details><summary>Click to expand</summary>

</details> -->

<!--

Out-of-Scope Use

List how the model may foreseeably be misused and address what users ought not to do with the model. -->

<!--

Bias, Risks and Limitations

What are the known or foreseeable issues stemming from this model? You could also flag here known failure cases or weaknesses of the model. -->

<!--

Recommendations

What are recommendations with respect to the foreseeable issues? For example, filtering explicit content. -->

Training Details

Training Dataset

Unnamed Dataset
  • Size: 58,800 training samples
  • Columns: <code>sentence0</code>, <code>sentence1</code>, and <code>label</code>
  • Approximate statistics based on the first 1000 samples: | | sentence0 | sentence1 | label | |:--------|:------------------------------------------------------------------------------------|:--------------------------------------------------------------------------------------|:--------------------------------------------------------------| | type | string | string | float | | details | <ul><li>min: 3 tokens</li><li>mean: 55.73 tokens</li><li>max: 1024 tokens</li></ul> | <ul><li>min: 28 tokens</li><li>mean: 179.65 tokens</li><li>max: 1024 tokens</li></ul> | <ul><li>min: 1.0</li><li>mean: 1.0</li><li>max: 1.0</li></ul> |
  • Samples: | sentence0 | sentence1 | label | |:-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|:-----------------| | <code>// CASNext is a non-callback, loop-based version of CAS method.<br>//<br>// Usage is like this:<br>//<br>// var state memcached.CASState<br>// for client.CASNext(vb, key, exp, &state) {<br>// state.Value = somemutation(state.Value)<br>// }<br>// if state.Err != nil { ... }</code> | <code>func (c *Client) CASNext(vb uint16, k string, exp int, state *CASState) bool {<br> if state.initialized {<br> if !state.Exists {<br> // Adding a new key:<br> if state.Value == nil {<br> state.Cas = 0<br> return false // no-op (delete of non-existent value)<br> }<br> state.resp, state.Err = c.Add(vb, k, 0, exp, state.Value)<br> } else {<br> // Updating / deleting a key:<br> req := &gomemcached.MCRequest{<br> Opcode: gomemcached.DELETE,<br> VBucket: vb,<br> Key: []byte(k),<br> Cas: state.Cas}<br> if state.Value != nil {<br> req.Opcode = gomemcached.SET<br> req.Opaque = 0<br> req.Extras = []byte{0, 0, 0, 0, 0, 0, 0, 0}<br> req.Body = state.Value<br><br> flags := 0<br> exp := 0 // ??? Should we use initialexp here instead?<br> binary.BigEndian.PutUint64(req.Extras, uint64(flags)<<32|uint64(exp))<br> }<br> state.resp, state.Err = c.Send(req)<br> }<br><br> // If the response status is KEYEEXISTS or NOTSTORED there's a conflict and we'll need to<br> // get the new value (below). Otherwise, we're done (either ...</code> | <code>1.0</code> | | <code>// RestoreResourcePools restores a bulk of resource pools, usually from a backup.</code> | <code>func (f *Facade) RestoreResourcePools(ctx datastore.Context, pools []pool.ResourcePool) error {<br> defer ctx.Metrics().Stop(ctx.Metrics().Start("Facade.RestoreResourcePools"))<br> // Do not DFSLock here, ControlPlaneDao does that<br> var alog audit.Logger<br> for , pool := range pools {<br> alog = f.auditLogger.Message(ctx, "Adding ResourcePool").Action(audit.Add).Entity(&pool)<br> pool.DatabaseVersion = 0<br> if err := f.addResourcePool(ctx, &pool); err != nil {<br> if err == ErrPoolExists {<br> if err := f.updateResourcePool(ctx, &pool); err != nil {<br> glog.Errorf("Could not restore resource pool %s via update: %s", pool.ID, err)<br> return alog.Error(err)<br> }<br> } else {<br> glog.Errorf("Could not restore resource pool %s via add: %s", pool.ID, err)<br> return alog.Error(err)<br> }<br> }<br> alog.Succeeded()<br> }<br> return nil<br>}</code> | <code>1.0</code> | | <code>// run starts a goroutine to handle client connects and broadcast events.</code> | <code>func (s *Streamer) run() {<br> go func() {<br> for {<br> select {<br> case cl := <-s.connecting:<br> s.clients[cl] = true<br><br> case cl := <-s.disconnecting:<br> delete(s.clients, cl)<br><br> case event := <-s.event:<br> for cl := range s.clients {<br> // TODO: non-blocking broadcast<br> //select {<br> //case cl <- event: // Try to send event to client<br> //default:<br> // fmt.Println("Channel full. Discarding value")<br> //}<br> cl <- event<br> }<br> }<br> }<br> }()<br>}</code> | <code>1.0</code> |
  • Loss: <code>MultipleNegativesRankingLoss</code> with these parameters:
json
  {
      "scale": 20.0,
      "similarity_fct": "cos_sim"
  }

Training Hyperparameters

Non-Default Hyperparameters
  • per_device_train_batch_size: 200
  • per_device_eval_batch_size: 200
  • fp16: True
  • multi_dataset_batch_sampler: round_robin
All Hyperparameters

<details><summary>Click to expand</summary>

  • overwrite_output_dir: False
  • do_predict: False
  • eval_strategy: no
  • prediction_loss_only: True
  • per_device_train_batch_size: 200
  • per_device_eval_batch_size: 200
  • per_gpu_train_batch_size: None
  • per_gpu_eval_batch_size: None
  • gradient_accumulation_steps: 1
  • eval_accumulation_steps: None
  • torch_empty_cache_steps: None
  • learning_rate: 5e-05
  • weight_decay: 0.0
  • adam_beta1: 0.9
  • adam_beta2: 0.999
  • adam_epsilon: 1e-08
  • max_grad_norm: 1
  • num_train_epochs: 3
  • max_steps: -1
  • lr_scheduler_type: linear
  • lr_scheduler_kwargs: {}
  • warmup_ratio: 0.0
  • warmup_steps: 0
  • log_level: passive
  • log_level_replica: warning
  • log_on_each_node: True
  • logging_nan_inf_filter: True
  • save_safetensors: True
  • save_on_each_node: False
  • save_only_model: False
  • restore_callback_states_from_checkpoint: False
  • no_cuda: False
  • use_cpu: False
  • use_mps_device: False
  • seed: 42
  • data_seed: None
  • jit_mode_eval: False
  • use_ipex: False
  • bf16: False
  • fp16: True
  • fp16_opt_level: O1
  • half_precision_backend: auto
  • bf16_full_eval: False
  • fp16_full_eval: False
  • tf32: None
  • local_rank: 0
  • ddp_backend: None
  • tpu_num_cores: None
  • tpu_metrics_debug: False
  • debug: []
  • dataloader_drop_last: False
  • dataloader_num_workers: 0
  • dataloader_prefetch_factor: None
  • past_index: -1
  • disable_tqdm: False
  • remove_unused_columns: True
  • label_names: None
  • load_best_model_at_end: False
  • ignore_data_skip: False
  • fsdp: []
  • fsdp_min_num_params: 0
  • fsdp_config: {'minnumparams': 0, 'xla': False, 'xlafsdpv2': False, 'xlafsdpgrad_ckpt': False}
  • fsdp_transformer_layer_cls_to_wrap: None
  • accelerator_config: {'splitbatches': False, 'dispatchbatches': None, 'evenbatches': True, 'useseedablesampler': True, 'nonblocking': False, 'gradientaccumulationkwargs': None}
  • deepspeed: None
  • label_smoothing_factor: 0.0
  • optim: adamw_torch
  • optim_args: None
  • adafactor: False
  • group_by_length: False
  • length_column_name: length
  • ddp_find_unused_parameters: None
  • ddp_bucket_cap_mb: None
  • ddp_broadcast_buffers: False
  • dataloader_pin_memory: True
  • dataloader_persistent_workers: False
  • skip_memory_metrics: True
  • use_legacy_prediction_loop: False
  • push_to_hub: False
  • resume_from_checkpoint: None
  • hub_model_id: None
  • hub_strategy: every_save
  • hub_private_repo: None
  • hub_always_push: False
  • hub_revision: None
  • gradient_checkpointing: False
  • gradient_checkpointing_kwargs: None
  • include_inputs_for_metrics: False
  • include_for_metrics: []
  • eval_do_concat_batches: True
  • fp16_backend: auto
  • push_to_hub_model_id: None
  • push_to_hub_organization: None
  • mp_parameters:
  • auto_find_batch_size: False
  • full_determinism: False
  • torchdynamo: None
  • ray_scope: last
  • ddp_timeout: 1800
  • torch_compile: False
  • torch_compile_backend: None
  • torch_compile_mode: None
  • include_tokens_per_second: False
  • include_num_input_tokens_seen: False
  • neftune_noise_alpha: None
  • optim_target_modules: None
  • batch_eval_metrics: False
  • eval_on_start: False
  • use_liger_kernel: False
  • liger_kernel_config: None
  • eval_use_gather_object: False
  • average_tokens_across_devices: False
  • prompts: None
  • batch_sampler: batch_sampler
  • multi_dataset_batch_sampler: round_robin
  • router_mapping: {}
  • learning_rate_mapping: {}

</details>

Training Logs

EpochStepTraining Loss
1.70075000.2697

Framework Versions

  • Python: 3.10.12
  • Sentence Transformers: 5.0.0
  • Transformers: 4.53.1
  • PyTorch: 2.7.0+cu128
  • Accelerate: 1.7.0
  • Datasets: 3.6.0
  • Tokenizers: 0.21.2

Citation

BibTeX

Sentence Transformers
bibtex
@inproceedings{reimers-2019-sentence-bert,
    title = "Sentence-BERT: Sentence Embeddings using Siamese BERT-Networks",
    author = "Reimers, Nils and Gurevych, Iryna",
    booktitle = "Proceedings of the 2019 Conference on Empirical Methods in Natural Language Processing",
    month = "11",
    year = "2019",
    publisher = "Association for Computational Linguistics",
    url = "https://arxiv.org/abs/1908.10084",
}
MultipleNegativesRankingLoss
bibtex
@misc{henderson2017efficient,
    title={Efficient Natural Language Response Suggestion for Smart Reply},
    author={Matthew Henderson and Rami Al-Rfou and Brian Strope and Yun-hsuan Sung and Laszlo Lukacs and Ruiqi Guo and Sanjiv Kumar and Balint Miklos and Ray Kurzweil},
    year={2017},
    eprint={1705.00652},
    archivePrefix={arXiv},
    primaryClass={cs.CL}
}

<!--

Glossary

Clearly define terms in order to be accessible across audiences. -->

<!--

Model Card Authors

Lists the people who create the model card, providing recognition and accountability for the detailed work that goes into its construction. -->

<!--

Model Card Contact

Provides a way for people who have updates to the Model Card, suggestions, or questions, to contact the Model Card authors. -->