mochodek commited on
Commit
59208d1
1 Parent(s): 08bf5d7

Update README.md

Browse files
Files changed (1) hide show
  1. README.md +43 -3
README.md CHANGED
@@ -1,3 +1,43 @@
1
- ---
2
- license: apache-2.0
3
- ---
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ license: apache-2.0
3
+ ---
4
+
5
+ ```python
6
+ from transformers import AutoTokenizer, AutoModelForSequenceClassification
7
+ import numpy as np
8
+
9
+ def sigmoid(x):
10
+ return 1/(1 + np.exp(-x))
11
+
12
+ classes = [
13
+ 'code_design',
14
+ 'code_style',
15
+ 'code_naming',
16
+ 'code_logic',
17
+ 'code_io',
18
+ 'code_data',
19
+ 'code_doc',
20
+ 'code_api',
21
+ 'compatibility',
22
+ 'rule_def',
23
+ 'config_commit_patch_review',
24
+ 'config_building_installing',
25
+ ]
26
+ class2id = {class_:id for id, class_ in enumerate(classes)}
27
+ id2class = {id:class_ for class_, id in class2id.items()}
28
+
29
+ checkpoint = 'mochodek/bert4comment-subject'
30
+ tokenizer = AutoTokenizer.from_pretrained(checkpoint)
31
+ model = AutoModelForSequenceClassification.from_pretrained(checkpoint)
32
+
33
+ text = "What do you think about making this constant?"
34
+ encoded_input = tokenizer(text, return_tensors='pt')
35
+ output = model(**encoded_input)
36
+
37
+ logits = output.logits.detach().numpy()
38
+
39
+ scores = sigmoid(logits)
40
+ scores = (scores > 0.5).astype(int).reshape(-1)
41
+ scores_labels = [class_name for class_name in classes if scores[class2id[class_name]] == 1 ]
42
+
43
+ ```