Update README.md
Browse files
README.md
CHANGED
@@ -1 +1,24 @@
|
|
1 |
-
Here is represented tinybert model for German language. The model was created by
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
Here is represented tinybert model for German language. The model was created by distilling of bert base cased model in the way described in https://arxiv.org/abs/1909.10351 (TinyBERT: Distilling BERT for Natural Language Understanding)
|
2 |
+
|
3 |
+
Versions:
|
4 |
+
|
5 |
+
|
6 |
+
How to load model for LM task:
|
7 |
+
|
8 |
+
tokenizer = transformers.BertTokenizer.from_pretrained(model_dir + '/vocab.txt', do_lower_case=False)
|
9 |
+
config = transformers.BertConfig.from_json_file(model_dir+'config.json')
|
10 |
+
model = transformers.BertModel(config=config)
|
11 |
+
model.pooler = nn.Sequential(nn.Linear(in_features=model.config.hidden_size, out_features=model.config.hidden_size, bias=True),
|
12 |
+
nn.LayerNorm((model.config.hidden_size,), eps=1e-12, elementwise_affine=True),
|
13 |
+
nn.Linear(in_features=model.config.hidden_size, out_features=len(tokenizer), bias=True))
|
14 |
+
|
15 |
+
model.resize_token_embeddings(len(tokenizer))
|
16 |
+
|
17 |
+
checkpoint = torch.load(model_dir+'/pytorch_model.bin', map_location=torch.device('cuda'))
|
18 |
+
model.load_state_dict(checkpoint)
|
19 |
+
|
20 |
+
|
21 |
+
In case of NER or Classification task we have to load model for LM task and change pooler:
|
22 |
+
|
23 |
+
model.pooler = nn.Sequential(nn.Dropout(p=config.hidden_dropout_prob, inplace=False),
|
24 |
+
nn.Linear(in_features=config.hidden_size, out_features=n_classes, bias=True))
|