Views
No views yet
pip install zipnn1# Use a pipeline as a high-level helper
2from transformers import pipeline
3from zipnn import zipnn_hf
4
5zipnn_hf()
6
7pipe = pipeline("fill-mask", model="royleibov/roberta-base-ZipNN-Compressed")1# Load model directly
2import torch
3from transformers import AutoTokenizer, AutoModelForMaskedLM
4from zipnn import zipnn_hf
5
6zipnn_hf()
7
8tokenizer = AutoTokenizer.from_pretrained("royleibov/roberta-base-ZipNN-Compressed")
9model = AutoModelForMaskedLM.from_pretrained("royleibov/roberta-base-ZipNN-Compressed")python zipnn_compress_path.py safetensors --model royleibov/roberta-base-ZipNN-Compressed --hf_cachezipnn_hf() is added at the top of the file like in the example above.python zipnn_decompress_path.py --model royleibov/roberta-base-ZipNN-Compressed --hf_cache1>>> from transformers import pipeline
2>>> from zipnn import zipnn_hf
3
4>>> zipnn_hf()
5
6>>> unmasker = pipeline('fill-mask', model='royleibov/roberta-base-ZipNN-Compressed')
7>>> unmasker("Hello I'm a <mask> model.")
8
9[{'sequence': "<s>Hello I'm a male model.</s>",
10 'score': 0.3306540250778198,
11 'token': 2943,
12 'token_str': 'Ġmale'},
13 {'sequence': "<s>Hello I'm a female model.</s>",
14 'score': 0.04655390977859497,
15 'token': 2182,
16 'token_str': 'Ġfemale'},
17 {'sequence': "<s>Hello I'm a professional model.</s>",
18 'score': 0.04232972860336304,
19 'token': 2038,
20 'token_str': 'Ġprofessional'},
21 {'sequence': "<s>Hello I'm a fashion model.</s>",
22 'score': 0.037216778844594955,
23 'token': 2734,
24 'token_str': 'Ġfashion'},
25 {'sequence': "<s>Hello I'm a Russian model.</s>",
26 'score': 0.03253649175167084,
27 'token': 1083,
28 'token_str': 'ĠRussian'}]1from transformers import RobertaTokenizer, RobertaModel
2from zipnn import zipnn_hf
3
4zipnn_hf()
5
6tokenizer = RobertaTokenizer.from_pretrained('royleibov/roberta-base-ZipNN-Compressed')
7model = RobertaModel.from_pretrained('royleibov/roberta-base-ZipNN-Compressed')
8text = "Replace me by any text you'd like."
9encoded_input = tokenizer(text, return_tensors='pt')
10output = model(**encoded_input)1from transformers import RobertaTokenizer, TFRobertaModel
2from zipnn import zipnn_hf
3
4zipnn_hf()
5
6tokenizer = RobertaTokenizer.from_pretrained('royleibov/roberta-base-ZipNN-Compressed')
7model = TFRobertaModel.from_pretrained('royleibov/roberta-base-ZipNN-Compressed')
8text = "Replace me by any text you'd like."
9encoded_input = tokenizer(text, return_tensors='tf')
10output = model(encoded_input)1>>> from transformers import pipeline
2>>> from zipnn import zipnn_hf
3
4>>> zipnn_hf()
5
6>>> unmasker = pipeline('fill-mask', model='royleibov/roberta-base-ZipNN-Compressed')
7>>> unmasker("The man worked as a <mask>.")
8
9[{'sequence': '<s>The man worked as a mechanic.</s>',
10 'score': 0.08702439814805984,
11 'token': 25682,
12 'token_str': 'Ġmechanic'},
13 {'sequence': '<s>The man worked as a waiter.</s>',
14 'score': 0.0819653645157814,
15 'token': 38233,
16 'token_str': 'Ġwaiter'},
17 {'sequence': '<s>The man worked as a butcher.</s>',
18 'score': 0.073323555290699,
19 'token': 32364,
20 'token_str': 'Ġbutcher'},
21 {'sequence': '<s>The man worked as a miner.</s>',
22 'score': 0.046322137117385864,
23 'token': 18678,
24 'token_str': 'Ġminer'},
25 {'sequence': '<s>The man worked as a guard.</s>',
26 'score': 0.040150221437215805,
27 'token': 2510,
28 'token_str': 'Ġguard'}]
29
30>>> unmasker("The Black woman worked as a <mask>.")
31
32[{'sequence': '<s>The Black woman worked as a waitress.</s>',
33 'score': 0.22177888453006744,
34 'token': 35698,
35 'token_str': 'Ġwaitress'},
36 {'sequence': '<s>The Black woman worked as a prostitute.</s>',
37 'score': 0.19288744032382965,
38 'token': 36289,
39 'token_str': 'Ġprostitute'},
40 {'sequence': '<s>The Black woman worked as a maid.</s>',
41 'score': 0.06498628109693527,
42 'token': 29754,
43 'token_str': 'Ġmaid'},
44 {'sequence': '<s>The Black woman worked as a secretary.</s>',
45 'score': 0.05375480651855469,
46 'token': 2971,
47 'token_str': 'Ġsecretary'},
48 {'sequence': '<s>The Black woman worked as a nurse.</s>',
49 'score': 0.05245552211999893,
50 'token': 9008,
51 'token_str': 'Ġnurse'}]<s> and the end of one by </s><mask>.| Task | MNLI | QQP | QNLI | SST-2 | CoLA | STS-B | MRPC | RTE |
|---|---|---|---|---|---|---|---|---|
| 87.6 | 91.9 | 92.8 | 94.8 | 63.6 | 91.2 | 90.2 | 78.7 |
1@article{DBLP:journals/corr/abs-1907-11692,
2 author = {Yinhan Liu and
3 Myle Ott and
4 Naman Goyal and
5 Jingfei Du and
6 Mandar Joshi and
7 Danqi Chen and
8 Omer Levy and
9 Mike Lewis and
10 Luke Zettlemoyer and
11 Veselin Stoyanov},
12 title = {RoBERTa: {A} Robustly Optimized {BERT} Pretraining Approach},
13 journal = {CoRR},
14 volume = {abs/1907.11692},
15 year = {2019},
16 url = {http://arxiv.org/abs/1907.11692},
17 archivePrefix = {arXiv},
18 eprint = {1907.11692},
19 timestamp = {Thu, 01 Aug 2019 08:59:33 +0200},
20 biburl = {https://dblp.org/rec/journals/corr/abs-1907-11692.bib},
21 bibsource = {dblp computer science bibliography, https://dblp.org}
22}