This model predicts similarity between problem prompts and Ballerina code completions.
Use Case: Given a coding problem prompt, evaluate how well a Ballerina solution matches the requirements.
Training:
Based on CodeRankEmbed with a binary similarity head.
import torch
from sentence_transformers import SentenceTransformer
from transformers import AutoTokenizer
# Load tokenizer
tokenizer = AutoTokenizer.from_pretrained("nomic-ai/CodeRankEmbed", trust_remote_code=True)
# Load your trained model
# (You'll need to load the SimilarityModel class and state dict)
# Example inference
code1 = "..."
code2 = "..."
# Tokenize
enc1 = tokenizer(code1, return_tensors='pt', padding=True, truncation=True, max_length=512)
enc2 = tokenizer(code2, return_tensors='pt', padding=True, truncation=True, max_length=512)
# Compute similarity
with torch.no_grad():
similarity = model(enc1['input_ids'], enc1['attention_mask'],
enc2['input_ids'], enc2['attention_mask'])
print(f"Similarity: {similarity.item():.3f}")
# > 0.7: High similarity (likely to pass)
# < 0.3: Low similarity (likely to fail)
@misc{coderankembed2024,
title={CodeRankEmbed: Code Similarity Learning},
author={Nomic AI},
year={2024},
url={https://huggingface.co/nomic-ai/CodeRankEmbed}
}
有文件?提交种子。
发布种子nomic-ai/CodeRankEmbed