Feature Extraction
sentence-transformers
Safetensors
code
bert
code-search
code-retrieval
text-embeddings-inference
Instructions to use thinkingdbx/codebert-permissive-embed with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- sentence-transformers
How to use thinkingdbx/codebert-permissive-embed with sentence-transformers:
from sentence_transformers import SentenceTransformer model = SentenceTransformer("thinkingdbx/codebert-permissive-embed") sentences = [ "The weather is lovely today.", "It's so sunny outside!", "He drove to the stadium." ] embeddings = model.encode(sentences) similarities = model.similarity(embeddings, embeddings) print(similarities.shape) # [3, 3] - Notebooks
- Google Colab
- Kaggle
Add HF metadata, usage, and scope
Browse files
README.md
CHANGED
|
@@ -1,13 +1,83 @@
|
|
| 1 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 2 |
|
| 3 |
Produced by Bonacci Foundry. Run `CODEBERT_EMBED_V2-8f13d02d`, spec digest `sha256:8f13d02db956b9db40326791fef0b1269417403422b298df43a80bb7ac072be6`.
|
| 4 |
|
| 5 |
Every number in this card is read from the run's own artifacts. Nothing here was typed by hand.
|
| 6 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 7 |
## What this is
|
| 8 |
|
| 9 |
- **Objective**: embedding
|
| 10 |
-
- **Base model**:
|
| 11 |
- **Method**: full
|
| 12 |
- **Delivery terms**: owned_outright
|
| 13 |
- **Training**: 1,673 steps, final loss 0.5576
|
|
|
|
| 1 |
+
---
|
| 2 |
+
license: apache-2.0
|
| 3 |
+
library_name: sentence-transformers
|
| 4 |
+
pipeline_tag: feature-extraction
|
| 5 |
+
tags:
|
| 6 |
+
- code
|
| 7 |
+
- code-search
|
| 8 |
+
- code-retrieval
|
| 9 |
+
- sentence-transformers
|
| 10 |
+
- feature-extraction
|
| 11 |
+
language:
|
| 12 |
+
- code
|
| 13 |
+
---
|
| 14 |
+
|
| 15 |
+
# codebert-permissive-embed
|
| 16 |
|
| 17 |
Produced by Bonacci Foundry. Run `CODEBERT_EMBED_V2-8f13d02d`, spec digest `sha256:8f13d02db956b9db40326791fef0b1269417403422b298df43a80bb7ac072be6`.
|
| 18 |
|
| 19 |
Every number in this card is read from the run's own artifacts. Nothing here was typed by hand.
|
| 20 |
|
| 21 |
+
## Usage
|
| 22 |
+
|
| 23 |
+
Mean pooling over non-padding tokens, then L2 normalise. `sentence-transformers`
|
| 24 |
+
does this for you because the pooling config ships with the model; with plain
|
| 25 |
+
`transformers` you must do it yourself, or you will get a different vector than
|
| 26 |
+
the one the model was trained to produce.
|
| 27 |
+
|
| 28 |
+
```python
|
| 29 |
+
from sentence_transformers import SentenceTransformer
|
| 30 |
+
|
| 31 |
+
m = SentenceTransformer("thinkingdbx/codebert-permissive-embed")
|
| 32 |
+
q = m.encode("find the function that parses a configuration file")
|
| 33 |
+
d = m.encode(["def load_settings(path):\n return yaml.safe_load(open(path))",
|
| 34 |
+
"def send_email(to, subject, body): ..."])
|
| 35 |
+
print((q @ d.T))
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
```python
|
| 39 |
+
import torch
|
| 40 |
+
from transformers import AutoModel, AutoTokenizer
|
| 41 |
+
|
| 42 |
+
tok = AutoTokenizer.from_pretrained("thinkingdbx/codebert-permissive-embed")
|
| 43 |
+
model = AutoModel.from_pretrained("thinkingdbx/codebert-permissive-embed").eval()
|
| 44 |
+
|
| 45 |
+
def embed(texts, max_length=256):
|
| 46 |
+
b = tok(texts, padding=True, truncation=True, max_length=max_length,
|
| 47 |
+
return_tensors="pt")
|
| 48 |
+
with torch.no_grad():
|
| 49 |
+
h = model(**b).last_hidden_state
|
| 50 |
+
mask = b["attention_mask"].unsqueeze(-1).float()
|
| 51 |
+
v = (h * mask).sum(1) / mask.sum(1).clamp(min=1e-9)
|
| 52 |
+
return torch.nn.functional.normalize(v, dim=-1)
|
| 53 |
+
```
|
| 54 |
+
|
| 55 |
+
## What it is for
|
| 56 |
+
|
| 57 |
+
Semantic code search — retrieving the function that does what a query describes,
|
| 58 |
+
including when the wording and the identifiers do not match. Also usable for
|
| 59 |
+
near-duplicate detection, clustering an unfamiliar codebase, and as the retrieval
|
| 60 |
+
half of a code RAG system.
|
| 61 |
+
|
| 62 |
+
It produces vectors. It does not generate text.
|
| 63 |
+
|
| 64 |
+
## What it is not
|
| 65 |
+
|
| 66 |
+
It is a 110M-parameter model trained on 857k pairs. General-purpose embedding
|
| 67 |
+
models of the same size — E5-Base, BGE-Base, GTE-Base — are trained on hundreds
|
| 68 |
+
of millions of pairs across text and code, and they score higher on most of the
|
| 69 |
+
benchmark below. This model is competitive on natural-language code search and
|
| 70 |
+
weak on code-to-code retrieval, which it was never trained for.
|
| 71 |
+
|
| 72 |
+
What it offers instead is provenance: every file it learned from carried a
|
| 73 |
+
permissive licence, the ledger of what was excluded is published with it, and
|
| 74 |
+
the personal data removed before training was counted.
|
| 75 |
+
|
| 76 |
+
|
| 77 |
## What this is
|
| 78 |
|
| 79 |
- **Objective**: embedding
|
| 80 |
+
- **Base model**: the stage-1 encoder below, trained from scratch (apache-2.0)
|
| 81 |
- **Method**: full
|
| 82 |
- **Delivery terms**: owned_outright
|
| 83 |
- **Training**: 1,673 steps, final loss 0.5576
|