Shuu12121 commited on
Commit
edf421e
·
verified ·
1 Parent(s): a0b6b34

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +19 -10
README.md CHANGED
@@ -82,19 +82,28 @@ This model is a SentenceTransformer fine-tuned from [`Shuu12121/CodeModernBERT-O
82
 
83
  ```python
84
  from sentence_transformers import SentenceTransformer
85
-
86
- model = SentenceTransformer("your-model-id")
87
- sentences = [
88
- "def add(a, b): return a + b",
89
- "def sum(x, y): return x + y"
90
- ]
91
- embeddings = model.encode(sentences)
92
-
93
  from torch.nn.functional import cosine_similarity
94
  import torch
95
 
96
- score = cosine_similarity(torch.tensor([embeddings[0]]), torch.tensor([embeddings[1]]))
97
- print(f"Cosine similarity: {score.item():.4f}")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
98
  ```
99
 
100
  ---
 
82
 
83
  ```python
84
  from sentence_transformers import SentenceTransformer
 
 
 
 
 
 
 
 
85
  from torch.nn.functional import cosine_similarity
86
  import torch
87
 
88
+ # Load the fine-tuned model
89
+ model = SentenceTransformer("Shuu12121/CodeCloneDetection-ModernBERT-Owl")
90
+
91
+ # Two code snippets to compare
92
+ code1 = "def add(a, b): return a + b"
93
+ code2 = "def sum(x, y): return x + y"
94
+
95
+ # Encode the code snippets
96
+ embeddings = model.encode([code1, code2], convert_to_tensor=True)
97
+
98
+ # Compute cosine similarity
99
+ similarity_score = cosine_similarity(embeddings[0].unsqueeze(0), embeddings[1].unsqueeze(0)).item()
100
+
101
+ # Print the result
102
+ print(f"Cosine Similarity: {similarity_score:.4f}")
103
+ if similarity_score >= 0.5:
104
+ print("🟢 These code snippets are considered CLONES.")
105
+ else:
106
+ print("🔴 These code snippets are NOT considered clones.")
107
  ```
108
 
109
  ---