Views
No views yet
1>>> from transformers import pipeline
2>>> unmasker = pipeline('fill-mask', model='bert-large-cased-whole-word-masking')
3>>> unmasker("Hello I'm a [MASK] model.")
4[
5 {
6 "sequence":"[CLS] Hello I'm a fashion model. [SEP]",
7 "score":0.1474294513463974,
8 "token":4633,
9 "token_str":"fashion"
10 },
11 {
12 "sequence":"[CLS] Hello I'm a magazine model. [SEP]",
13 "score":0.05430116504430771,
14 "token":2435,
15 "token_str":"magazine"
16 },
17 {
18 "sequence":"[CLS] Hello I'm a male model. [SEP]",
19 "score":0.039395421743392944,
20 "token":2581,
21 "token_str":"male"
22 },
23 {
24 "sequence":"[CLS] Hello I'm a former model. [SEP]",
25 "score":0.036936815828084946,
26 "token":1393,
27 "token_str":"former"
28 },
29 {
30 "sequence":"[CLS] Hello I'm a professional model. [SEP]",
31 "score":0.03663451969623566,
32 "token":1848,
33 "token_str":"professional"
34 }
35]1from transformers import BertTokenizer, BertModel
2tokenizer = BertTokenizer.from_pretrained('bert-large-cased-whole-word-masking')
3model = BertModel.from_pretrained("bert-large-cased-whole-word-masking")
4text = "Replace me by any text you'd like."
5encoded_input = tokenizer(text, return_tensors='pt')
6output = model(**encoded_input)1from transformers import BertTokenizer, TFBertModel
2tokenizer = BertTokenizer.from_pretrained('bert-large-cased-whole-word-masking')
3model = TFBertModel.from_pretrained("bert-large-cased-whole-word-masking")
4text = "Replace me by any text you'd like."
5encoded_input = tokenizer(text, return_tensors='tf')
6output = model(encoded_input)1>>> from transformers import pipeline
2>>> unmasker = pipeline('fill-mask', model='bert-large-cased-whole-word-masking')
3>>> unmasker("The man worked as a [MASK].")
4[
5 {
6 "sequence":"[CLS] The man worked as a carpenter. [SEP]",
7 "score":0.09021259099245071,
8 "token":25169,
9 "token_str":"carpenter"
10 },
11 {
12 "sequence":"[CLS] The man worked as a cook. [SEP]",
13 "score":0.08125395327806473,
14 "token":9834,
15 "token_str":"cook"
16 },
17 {
18 "sequence":"[CLS] The man worked as a mechanic. [SEP]",
19 "score":0.07524766772985458,
20 "token":19459,
21 "token_str":"mechanic"
22 },
23 {
24 "sequence":"[CLS] The man worked as a waiter. [SEP]",
25 "score":0.07397029548883438,
26 "token":17989,
27 "token_str":"waiter"
28 },
29 {
30 "sequence":"[CLS] The man worked as a guard. [SEP]",
31 "score":0.05848982185125351,
32 "token":3542,
33 "token_str":"guard"
34 }
35]
36
37
38>>> unmasker("The woman worked as a [MASK].")
39[
40 {
41 "sequence":"[CLS] The woman worked as a maid. [SEP]",
42 "score":0.19436432421207428,
43 "token":13487,
44 "token_str":"maid"
45 },
46 {
47 "sequence":"[CLS] The woman worked as a waitress. [SEP]",
48 "score":0.16161060333251953,
49 "token":15098,
50 "token_str":"waitress"
51 },
52 {
53 "sequence":"[CLS] The woman worked as a nurse. [SEP]",
54 "score":0.14942803978919983,
55 "token":7439,
56 "token_str":"nurse"
57 },
58 {
59 "sequence":"[CLS] The woman worked as a secretary. [SEP]",
60 "score":0.10373266786336899,
61 "token":4848,
62 "token_str":"secretary"
63 },
64 {
65 "sequence":"[CLS] The woman worked as a cook. [SEP]",
66 "score":0.06384387612342834,
67 "token":9834,
68 "token_str":"cook"
69 }
70][CLS] Sentence A [SEP] Sentence B [SEP][MASK].| Model | SQUAD 1.1 F1/EM | Multi NLI Accuracy |
|---|---|---|
| BERT-Large, Cased (Whole Word Masking) | 92.9/86.7 | 86.46 |
1@article{DBLP:journals/corr/abs-1810-04805,
2 author = {Jacob Devlin and
3 Ming{-}Wei Chang and
4 Kenton Lee and
5 Kristina Toutanova},
6 title = {{BERT:} Pre-training of Deep Bidirectional Transformers for Language
7 Understanding},
8 journal = {CoRR},
9 volume = {abs/1810.04805},
10 year = {2018},
11 url = {http://arxiv.org/abs/1810.04805},
12 archivePrefix = {arXiv},
13 eprint = {1810.04805},
14 timestamp = {Tue, 30 Oct 2018 20:39:56 +0100},
15 biburl = {https://dblp.org/rec/journals/corr/abs-1810-04805.bib},
16 bibsource = {dblp computer science bibliography, https://dblp.org}
17}