junnyu commited on
Commit
f027f2f
1 Parent(s): f7bb7f3
Files changed (4) hide show
  1. README.md +35 -0
  2. config.json +29 -0
  3. pytorch_model.bin +3 -0
  4. vocab.txt +0 -0
README.md ADDED
@@ -0,0 +1,35 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ## 介绍
2
+ tf版本 https://github.com/ZhuiyiTechnology/WoBERT
3
+ pytorch版本 https://github.com/JunnYu/WoBERT_pytorch
4
+
5
+ ## 使用
6
+ ```python
7
+ git clone https://github.com/JunnYu/WoBERT_pytorch
8
+ cd WoBERT_pytorch
9
+ import torch
10
+ from transformers import BertForMaskedLM as WoBertForMaskedLM
11
+ from tokenization_wobert import WoBertTokenizer
12
+
13
+ pretrained_model_or_path_list = [
14
+ "junnyu/wobert_chinese_plus_base", "junnyu/wobert_chinese_base"
15
+ ]
16
+ for path in pretrained_model_or_path_list:
17
+ text = "今天[MASK]很好,我[MASK]去公园玩。"
18
+ tokenizer = WoBertTokenizer.from_pretrained(path)
19
+ model = WoBertForMaskedLM.from_pretrained(path)
20
+ inputs = tokenizer(text, return_tensors="pt")
21
+ with torch.no_grad():
22
+ outputs = model(**inputs).logits[0]
23
+ outputs_sentence = ""
24
+ for i, id in enumerate(tokenizer.encode(text)):
25
+ if id == tokenizer.mask_token_id:
26
+ tokens = tokenizer.convert_ids_to_tokens(outputs[i].topk(k=5)[1])
27
+ outputs_sentence += "[" + "||".join(tokens) + "]"
28
+ else:
29
+ outputs_sentence += "".join(
30
+ tokenizer.convert_ids_to_tokens([id],
31
+ skip_special_tokens=True))
32
+ print(outputs_sentence)
33
+ # PLUS WoBERT 今天[天气||阳光||天||心情||空气]很好,我[想||要||打算||准备||就]去公园玩。
34
+ # WoBERT 今天[天气||阳光||天||心情||空气]很好,我[想||要||就||准备||也]去公园玩。
35
+ ```
config.json ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "architectures": [
3
+ "BertForMaskedLM"
4
+ ],
5
+ "attention_probs_dropout_prob": 0.1,
6
+ "directionality": "bidi",
7
+ "gradient_checkpointing": false,
8
+ "hidden_act": "gelu",
9
+ "hidden_dropout_prob": 0.1,
10
+ "hidden_size": 768,
11
+ "initializer_range": 0.02,
12
+ "intermediate_size": 3072,
13
+ "layer_norm_eps": 1e-12,
14
+ "max_position_embeddings": 512,
15
+ "model_type": "bert",
16
+ "num_attention_heads": 12,
17
+ "num_hidden_layers": 12,
18
+ "pad_token_id": 0,
19
+ "pooler_fc_size": 768,
20
+ "pooler_num_attention_heads": 12,
21
+ "pooler_num_fc_layers": 3,
22
+ "pooler_size_per_head": 128,
23
+ "pooler_type": "first_token_transform",
24
+ "position_embedding_type": "absolute",
25
+ "transformers_version": "4.5.1",
26
+ "type_vocab_size": 2,
27
+ "use_cache": true,
28
+ "vocab_size": 33586
29
+ }
pytorch_model.bin ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:9a3ad5bcafdb4e76ba2b0937dd8b74de7bdb2906c1cd2572fb42f70170e65937
3
+ size 449938919
vocab.txt ADDED
The diff for this file is too large to render. See raw diff