Views
No views yet
1>>> from transformers import pipeline
2>>> unmasker = pipeline('fill-mask', model='bert-large-cased')
3>>> unmasker("Hello I'm a [MASK] model.")
4[
5 {
6 "sequence":"[CLS] Hello I'm a male model. [SEP]",
7 "score":0.22748498618602753,
8 "token":2581,
9 "token_str":"male"
10 },
11 {
12 "sequence":"[CLS] Hello I'm a fashion model. [SEP]",
13 "score":0.09146175533533096,
14 "token":4633,
15 "token_str":"fashion"
16 },
17 {
18 "sequence":"[CLS] Hello I'm a new model. [SEP]",
19 "score":0.05823173746466637,
20 "token":1207,
21 "token_str":"new"
22 },
23 {
24 "sequence":"[CLS] Hello I'm a super model. [SEP]",
25 "score":0.04488750174641609,
26 "token":7688,
27 "token_str":"super"
28 },
29 {
30 "sequence":"[CLS] Hello I'm a famous model. [SEP]",
31 "score":0.03271442651748657,
32 "token":2505,
33 "token_str":"famous"
34 }
35]1from transformers import BertTokenizer, BertModel
2tokenizer = BertTokenizer.from_pretrained('bert-large-cased')
3model = BertModel.from_pretrained("bert-large-cased")
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')
3model = TFBertModel.from_pretrained("bert-large-cased")
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')
3>>> unmasker("The man worked as a [MASK].")
4[
5 {
6 "sequence":"[CLS] The man worked as a doctor. [SEP]",
7 "score":0.0645911768078804,
8 "token":3995,
9 "token_str":"doctor"
10 },
11 {
12 "sequence":"[CLS] The man worked as a cop. [SEP]",
13 "score":0.057450827211141586,
14 "token":9947,
15 "token_str":"cop"
16 },
17 {
18 "sequence":"[CLS] The man worked as a mechanic. [SEP]",
19 "score":0.04392256215214729,
20 "token":19459,
21 "token_str":"mechanic"
22 },
23 {
24 "sequence":"[CLS] The man worked as a waiter. [SEP]",
25 "score":0.03755280375480652,
26 "token":17989,
27 "token_str":"waiter"
28 },
29 {
30 "sequence":"[CLS] The man worked as a teacher. [SEP]",
31 "score":0.03458863124251366,
32 "token":3218,
33 "token_str":"teacher"
34 }
35]
36
37>>> unmasker("The woman worked as a [MASK].")
38[
39 {
40 "sequence":"[CLS] The woman worked as a nurse. [SEP]",
41 "score":0.2572779953479767,
42 "token":7439,
43 "token_str":"nurse"
44 },
45 {
46 "sequence":"[CLS] The woman worked as a waitress. [SEP]",
47 "score":0.16706500947475433,
48 "token":15098,
49 "token_str":"waitress"
50 },
51 {
52 "sequence":"[CLS] The woman worked as a teacher. [SEP]",
53 "score":0.04587847739458084,
54 "token":3218,
55 "token_str":"teacher"
56 },
57 {
58 "sequence":"[CLS] The woman worked as a secretary. [SEP]",
59 "score":0.03577028587460518,
60 "token":4848,
61 "token_str":"secretary"
62 },
63 {
64 "sequence":"[CLS] The woman worked as a maid. [SEP]",
65 "score":0.03298963978886604,
66 "token":13487,
67 "token_str":"maid"
68 }
69][CLS] Sentence A [SEP] Sentence B [SEP][MASK].| Model | SQUAD 1.1 F1/EM | Multi NLI Accuracy |
|---|---|---|
| BERT-Large, Cased (Original) | 91.5/84.8 | 86.09 |
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}