Views
No views yet
| Label ID | Design Pattern |
|---|---|
| 0 | Observer |
| 1 | Decorator |
| 2 | Adapter |
| 3 | Proxy |
| 4 | Singleton |
| 5 | Facade |
| 6 | AbstractFactory |
| 7 | Memento |
| 8 | FactoryMethod |
| 9 | Prototype |
| 10 | Visitor |
| 11 | Builder |
| 12 | Unknown |
1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2
3# Load the model and tokenizer
4tokenizer = AutoTokenizer.from_pretrained("ichsanbudiman/design-pattern-detection-codebert")
5model = AutoModelForSequenceClassification.from_pretrained("ichsanbudiman/design-pattern-detection-codebert")
6
7# Example input
8input_code = """
9public class Singleton {
10 private static Singleton instance;
11
12 private Singleton() {}
13
14 public static Singleton getInstance() {
15 if (instance == null) {
16 instance = new Singleton();
17 }
18 return instance;
19 }
20}
21"""
22
23# Tokenize the input
24inputs = tokenizer(input_code, return_tensors="pt", padding="max_length", truncation=True, max_length=512)
25
26# Make predictions
27with torch.no_grad():
28 outputs = model(**inputs)
29
30# Get the predicted class and label
31predicted_class = torch.argmax(outputs.logits, dim=1).item()
32predicted_label = model.config.id2label[predicted_class]
33
34print(f"Predicted label: {predicted_label}")Najam Nazar, Aldeida Aleti, Yaokun Zheng, Feature-based software design pattern detection, Journal of Systems and Software, Volume 185, 2022, 111179, ISSN 0164-1212, https://doi.org/10.1016/j.jss.2021.111179.