wyluilipe commited on
Commit
46f724b
1 Parent(s): d4976ae

Create README.md

Browse files
Files changed (1) hide show
  1. README.md +27 -0
README.md ADDED
@@ -0,0 +1,27 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ```python
2
+
3
+ from transformers import BertTokenizer, BertForSequenceClassification
4
+ import torch
5
+ import numpy as np
6
+ import json
7
+
8
+ class Prehibition:
9
+ def __init__(self):
10
+ model_name = 'wyluilipe/prehibiton-themes-clf'
11
+ self.tokenizer = BertTokenizer.from_pretrained(model_name)
12
+ self.model = BertForSequenceClassification.from_pretrained(model_name)
13
+
14
+ def predict(self, text):
15
+ tokenized = self.tokenizer.batch_encode_plus(
16
+ [text],
17
+ max_length = 512,
18
+ pad_to_max_length=True,
19
+ truncation=True,
20
+ return_token_type_ids=False
21
+ )
22
+ tokens_ids, mask = torch.tensor(tokenized['input_ids']), torch.tensor(tokenized['attention_mask'])
23
+ with torch.no_grad():
24
+ model_output = self.model(tokens_ids, mask)
25
+ return np.argmax(model_output['logits']).item()
26
+
27
+ ```