xavierwoon/cestertest
Viewer • Updated • 20 • 14
How to use xavierwoon/cesterrewards with Transformers:
# Use a pipeline as a high-level helper
from transformers import pipeline
pipe = pipeline("text-classification", model="xavierwoon/cesterrewards") # Load model directly
from transformers import AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("xavierwoon/cesterrewards")
model = AutoModelForSequenceClassification.from_pretrained("xavierwoon/cesterrewards")# Load model directly
from transformers import AutoTokenizer, AutoModelForSequenceClassification
tokenizer = AutoTokenizer.from_pretrained("xavierwoon/cesterrewards")
model = AutoModelForSequenceClassification.from_pretrained("xavierwoon/cesterrewards")Cesterrewards is a Bert model that is able to predict the code coverage of Libcester unit test cases.
Expanding the dataset will help increase the accuracy and robustness of the model, and improve code coverage predictions based on real life scenarios.
Use the code below to get started with the model.
from transformers import AutoModelForSequenceClassification, AutoTokenizer
import torch
reward_name = "xavierwoon/cesterrewards"
reward_model = AutoModelForSequenceClassification.from_pretrained(reward_name)
tokenizer = AutoTokenizer.from_pretrained(reward_name)
# Change the prompt to sample unit test cases in Libcester format
prompt = """
CESTER_TEST(create_stack, test_instance,
{
struct Stack stack;
initStack(&stack);
cester_assert_equal(stack.top, -1);
})
"""
inputs = tokenizer(prompt, return_tensors="pt", padding=True, truncation=True, max_length=512)
# Put the model in evaluation mode
reward_model.eval()
# Perform inference to get the reward score
with torch.no_grad():
outputs = reward_model(**inputs)
reward_score = outputs.logits.item() # Extract the scalar value
print("Expected Code Coverage:", reward_score)
Training Data was created based on Data Structures and Algorithm (DSA) codes created using ChatGPT. It would also create corresponding Cester test cases. After testing the code coverage, it was added to the dataset under score.
Base model
google-bert/bert-base-uncased
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="xavierwoon/cesterrewards")