Update README.md
Browse files
README.md
CHANGED
@@ -6,52 +6,15 @@ I do not own, distribute, or take credits for this model, all copyrights belong
|
|
6 |
|
7 |
|
8 |
# how to load the model
|
9 |
-
download the weights
|
10 |
-
```
|
11 |
-
!git clone https://huggingface.co/not-lain/TunBERT
|
12 |
-
```
|
13 |
-
load the model
|
14 |
```python
|
15 |
-
import
|
16 |
-
import torch
|
17 |
-
from transformers import AutoTokenizer, AutoModelForMaskedLM, AutoModelForSequenceClassification, PreTrainedModel,AutoConfig, BertModel
|
18 |
-
from transformers.modeling_outputs import SequenceClassifierOutput
|
19 |
-
config = AutoConfig.from_pretrained("not-lain/TunBERT")
|
20 |
-
class classifier(nn.Module):
|
21 |
-
def __init__(self,config):
|
22 |
-
super().__init__()
|
23 |
-
|
24 |
-
self.layer0 = nn.Linear(in_features=config.hidden_size, out_features=config.hidden_size, bias=True)
|
25 |
-
self.layer1 = nn.Linear(in_features=config.hidden_size, out_features=config.type_vocab_size, bias=True)
|
26 |
-
def forward(self,tensor):
|
27 |
-
out1 = self.layer0(tensor)
|
28 |
-
return self.layer1(out1)
|
29 |
-
|
30 |
-
|
31 |
-
class TunBERT(PreTrainedModel):
|
32 |
-
def __init__(self, config):
|
33 |
-
super().__init__(config)
|
34 |
-
self.BertModel = BertModel(config)
|
35 |
-
self.dropout = nn.Dropout(p=0.1, inplace=False)
|
36 |
-
self.classifier = classifier(config)
|
37 |
|
38 |
-
|
39 |
-
|
40 |
-
sequence_output = self.dropout(outputs.last_hidden_state)
|
41 |
-
logits = self.classifier(sequence_output)
|
42 |
-
loss =None
|
43 |
-
if labels is not None :
|
44 |
-
loss_func = nn.CrossentropyLoss()
|
45 |
-
loss = loss_func(logits.view(-1,self.config.type_vocab_size),labels.view(-1))
|
46 |
-
return SequenceClassifierOutput(loss = loss, logits= logits, hidden_states=outputs.last_hidden_state,attentions=outputs.attentions)
|
47 |
-
|
48 |
-
|
49 |
-
tunbert = TunBERT(config)
|
50 |
-
tunbert.load_state_dict(torch.load("TunBERT/pytorch_model.bin"))
|
51 |
-
|
52 |
-
tokenizer = AutoTokenizer.from_pretrained("bert-base-uncased")
|
53 |
```
|
54 |
|
|
|
|
|
55 |
|
56 |
# how to use the model
|
57 |
```python
|
|
|
6 |
|
7 |
|
8 |
# how to load the model
|
|
|
|
|
|
|
|
|
|
|
9 |
```python
|
10 |
+
from transformers import AutoTokenizer, AutoModelForSequenceClassification
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
11 |
|
12 |
+
tokenizer = AutoTokenizer.from_pretrained("not-lain/TunBERT")
|
13 |
+
model = AutoModelForSequenceClassification.from_pretrained("not-lain/TunBERT",trust_remote_code=True)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
14 |
```
|
15 |
|
16 |
+
**IMPORTANT** : make sure to enable `trust_remote_code=True`
|
17 |
+
|
18 |
|
19 |
# how to use the model
|
20 |
```python
|