eacortes commited on
Commit
c7bf4a2
·
verified ·
1 Parent(s): 41be055

Upload folder using huggingface_hub

Browse files
Files changed (10) hide show
  1. .gitattributes +1 -0
  2. README.md +193 -0
  3. added_tokens.json +1 -0
  4. config.json +95 -0
  5. model.rknn +3 -0
  6. rknn.json +46 -0
  7. special_tokens_map.json +7 -0
  8. tokenizer.json +0 -0
  9. tokenizer_config.json +59 -0
  10. vocab.txt +0 -0
.gitattributes CHANGED
@@ -33,3 +33,4 @@ saved_model/**/* filter=lfs diff=lfs merge=lfs -text
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
 
 
33
  *.zip filter=lfs diff=lfs merge=lfs -text
34
  *.zst filter=lfs diff=lfs merge=lfs -text
35
  *tfevents* filter=lfs diff=lfs merge=lfs -text
36
+ model.rknn filter=lfs diff=lfs merge=lfs -text
README.md ADDED
@@ -0,0 +1,193 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ language: en
3
+ license: mit
4
+ base_model: dslim/bert-base-NER
5
+ tags:
6
+ - rknn
7
+ - rockchip
8
+ - npu
9
+ - rk-transformers
10
+ - rk3588
11
+ library_name: rk-transformers
12
+ model_name: bert-base-NER
13
+ ---
14
+ # bert-base-NER (RKNN2)
15
+
16
+ > This is an RKNN-compatible version of the [dslim/bert-base-NER](https://huggingface.co/dslim/bert-base-NER) model. It has been optimized for Rockchip NPUs using the [rk-transformers](https://github.com/emapco/rk-transformers) library.
17
+
18
+ <details><summary>Click to see the RKNN model details and usage examples</summary>
19
+
20
+ ## Model Details
21
+
22
+ - **Original Model:** [dslim/bert-base-NER](https://huggingface.co/dslim/bert-base-NER)
23
+ - **Target Platform:** rk3588
24
+ - **rknn-toolkit2 Version:** 2.3.2
25
+ - **rk-transformers Version:** 0.3.0
26
+
27
+ ### Available Model Files
28
+
29
+ | Model File | Optimization Level | Quantization | File Size |
30
+ | :--------- | :----------------- | :----------- | :-------- |
31
+ | [model.rknn](./model.rknn) | 0 | float16 | 212.9 MB |
32
+
33
+ ## Usage
34
+
35
+ ### Installation
36
+
37
+ Install `rk-transformers` with inference dependencies to use this model:
38
+
39
+ ```bash
40
+ pip install rk-transformers[inference]
41
+ ```
42
+
43
+ #### RK-Transformers API
44
+
45
+ ```python
46
+ from rktransformers import RKModelForTokenClassification
47
+ from transformers import AutoTokenizer
48
+
49
+ tokenizer = AutoTokenizer.from_pretrained("rk-transformers/bert-base-NER")
50
+ model = RKModelForTokenClassification.from_pretrained(
51
+ "rk-transformers/bert-base-NER",
52
+ platform="rk3588",
53
+ core_mask="auto",
54
+ )
55
+
56
+ inputs = tokenizer("My name is Philipp and I live in Germany.", return_tensors="np")
57
+ outputs = model(**inputs)
58
+ logits = outputs.logits
59
+ print(logits.shape)
60
+ ```
61
+
62
+ ## Configuration
63
+
64
+ The full configuration for all exported RKNN models is available in the [config.json](./config.json) file.
65
+
66
+ </details>
67
+
68
+ ---
69
+ # bert-base-NER
70
+
71
+ If my open source models have been useful to you, please consider supporting me in building small, useful AI models for everyone (and help me afford med school / help out my parents financially). Thanks!
72
+
73
+ <a href="https://www.buymeacoffee.com/dslim" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/arial-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>
74
+
75
+ ## Model description
76
+
77
+ **bert-base-NER** is a fine-tuned BERT model that is ready to use for **Named Entity Recognition** and achieves **state-of-the-art performance** for the NER task. It has been trained to recognize four types of entities: location (LOC), organizations (ORG), person (PER) and Miscellaneous (MISC).
78
+
79
+ Specifically, this model is a *bert-base-cased* model that was fine-tuned on the English version of the standard [CoNLL-2003 Named Entity Recognition](https://www.aclweb.org/anthology/W03-0419.pdf) dataset.
80
+
81
+ If you'd like to use a larger BERT-large model fine-tuned on the same dataset, a [**bert-large-NER**](https://huggingface.co/dslim/bert-large-NER/) version is also available.
82
+
83
+ ### Available NER models
84
+ | Model Name | Description | Parameters |
85
+ |-------------------|-------------|------------------|
86
+ | [distilbert-NER](https://huggingface.co/dslim/distilbert-NER) **(NEW!)** | Fine-tuned DistilBERT - a smaller, faster, lighter version of BERT | 66M |
87
+ | [bert-large-NER](https://huggingface.co/dslim/bert-large-NER/) | Fine-tuned bert-large-cased - larger model with slightly better performance | 340M |
88
+ | [bert-base-NER](https://huggingface.co/dslim/bert-base-NER)-([uncased](https://huggingface.co/dslim/bert-base-NER-uncased)) | Fine-tuned bert-base, available in both cased and uncased versions | 110M |
89
+
90
+
91
+ ## Intended uses & limitations
92
+
93
+ #### How to use
94
+
95
+ You can use this model with Transformers *pipeline* for NER.
96
+
97
+ ```python
98
+ from transformers import AutoTokenizer, AutoModelForTokenClassification
99
+ from transformers import pipeline
100
+
101
+ tokenizer = AutoTokenizer.from_pretrained("dslim/bert-base-NER")
102
+ model = AutoModelForTokenClassification.from_pretrained("dslim/bert-base-NER")
103
+
104
+ nlp = pipeline("ner", model=model, tokenizer=tokenizer)
105
+ example = "My name is Wolfgang and I live in Berlin"
106
+
107
+ ner_results = nlp(example)
108
+ print(ner_results)
109
+ ```
110
+
111
+ #### Limitations and bias
112
+
113
+ This model is limited by its training dataset of entity-annotated news articles from a specific span of time. This may not generalize well for all use cases in different domains. Furthermore, the model occassionally tags subword tokens as entities and post-processing of results may be necessary to handle those cases.
114
+
115
+ ## Training data
116
+
117
+ This model was fine-tuned on English version of the standard [CoNLL-2003 Named Entity Recognition](https://www.aclweb.org/anthology/W03-0419.pdf) dataset.
118
+
119
+ The training dataset distinguishes between the beginning and continuation of an entity so that if there are back-to-back entities of the same type, the model can output where the second entity begins. As in the dataset, each token will be classified as one of the following classes:
120
+
121
+ Abbreviation|Description
122
+ -|-
123
+ O|Outside of a named entity
124
+ B-MISC |Beginning of a miscellaneous entity right after another miscellaneous entity
125
+ I-MISC | Miscellaneous entity
126
+ B-PER |Beginning of a person’s name right after another person’s name
127
+ I-PER |Person’s name
128
+ B-ORG |Beginning of an organization right after another organization
129
+ I-ORG |organization
130
+ B-LOC |Beginning of a location right after another location
131
+ I-LOC |Location
132
+
133
+
134
+ ### CoNLL-2003 English Dataset Statistics
135
+ This dataset was derived from the Reuters corpus which consists of Reuters news stories. You can read more about how this dataset was created in the CoNLL-2003 paper.
136
+ #### # of training examples per entity type
137
+ Dataset|LOC|MISC|ORG|PER
138
+ -|-|-|-|-
139
+ Train|7140|3438|6321|6600
140
+ Dev|1837|922|1341|1842
141
+ Test|1668|702|1661|1617
142
+ #### # of articles/sentences/tokens per dataset
143
+ Dataset |Articles |Sentences |Tokens
144
+ -|-|-|-
145
+ Train |946 |14,987 |203,621
146
+ Dev |216 |3,466 |51,362
147
+ Test |231 |3,684 |46,435
148
+
149
+ ## Training procedure
150
+
151
+ This model was trained on a single NVIDIA V100 GPU with recommended hyperparameters from the [original BERT paper](https://arxiv.org/pdf/1810.04805) which trained & evaluated the model on CoNLL-2003 NER task.
152
+
153
+ ## Eval results
154
+ metric|dev|test
155
+ -|-|-
156
+ f1 |95.1 |91.3
157
+ precision |95.0 |90.7
158
+ recall |95.3 |91.9
159
+
160
+ The test metrics are a little lower than the official Google BERT results which encoded document context & experimented with CRF. More on replicating the original results [here](https://github.com/google-research/bert/issues/223).
161
+
162
+ ### BibTeX entry and citation info
163
+
164
+ ```
165
+ @article{DBLP:journals/corr/abs-1810-04805,
166
+ author = {Jacob Devlin and
167
+ Ming{-}Wei Chang and
168
+ Kenton Lee and
169
+ Kristina Toutanova},
170
+ title = {{BERT:} Pre-training of Deep Bidirectional Transformers for Language
171
+ Understanding},
172
+ journal = {CoRR},
173
+ volume = {abs/1810.04805},
174
+ year = {2018},
175
+ url = {http://arxiv.org/abs/1810.04805},
176
+ archivePrefix = {arXiv},
177
+ eprint = {1810.04805},
178
+ timestamp = {Tue, 30 Oct 2018 20:39:56 +0100},
179
+ biburl = {https://dblp.org/rec/journals/corr/abs-1810-04805.bib},
180
+ bibsource = {dblp computer science bibliography, https://dblp.org}
181
+ }
182
+ ```
183
+ ```
184
+ @inproceedings{tjong-kim-sang-de-meulder-2003-introduction,
185
+ title = "Introduction to the {C}o{NLL}-2003 Shared Task: Language-Independent Named Entity Recognition",
186
+ author = "Tjong Kim Sang, Erik F. and
187
+ De Meulder, Fien",
188
+ booktitle = "Proceedings of the Seventh Conference on Natural Language Learning at {HLT}-{NAACL} 2003",
189
+ year = "2003",
190
+ url = "https://www.aclweb.org/anthology/W03-0419",
191
+ pages = "142--147",
192
+ }
193
+ ```
added_tokens.json ADDED
@@ -0,0 +1 @@
 
 
1
+ {}
config.json ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "_num_labels": 9,
3
+ "architectures": [
4
+ "BertForTokenClassification"
5
+ ],
6
+ "attention_probs_dropout_prob": 0.1,
7
+ "classifier_dropout": null,
8
+ "hidden_act": "gelu",
9
+ "hidden_dropout_prob": 0.1,
10
+ "hidden_size": 768,
11
+ "id2label": {
12
+ "0": "O",
13
+ "1": "B-MISC",
14
+ "2": "I-MISC",
15
+ "3": "B-PER",
16
+ "4": "I-PER",
17
+ "5": "B-ORG",
18
+ "6": "I-ORG",
19
+ "7": "B-LOC",
20
+ "8": "I-LOC"
21
+ },
22
+ "initializer_range": 0.02,
23
+ "intermediate_size": 3072,
24
+ "label2id": {
25
+ "B-LOC": 7,
26
+ "B-MISC": 1,
27
+ "B-ORG": 5,
28
+ "B-PER": 3,
29
+ "I-LOC": 8,
30
+ "I-MISC": 2,
31
+ "I-ORG": 6,
32
+ "I-PER": 4,
33
+ "O": 0
34
+ },
35
+ "layer_norm_eps": 1e-12,
36
+ "max_position_embeddings": 512,
37
+ "model_type": "bert",
38
+ "num_attention_heads": 12,
39
+ "num_hidden_layers": 12,
40
+ "output_past": true,
41
+ "pad_token_id": 0,
42
+ "position_embedding_type": "absolute",
43
+ "rknn": {
44
+ "model.rknn": {
45
+ "batch_size": 1,
46
+ "custom_string": null,
47
+ "dynamic_input": null,
48
+ "float_dtype": "float16",
49
+ "inputs_yuv_fmt": null,
50
+ "max_seq_length": 512,
51
+ "mean_values": null,
52
+ "model_input_names": [
53
+ "input_ids",
54
+ "attention_mask",
55
+ "token_type_ids"
56
+ ],
57
+ "opset": 19,
58
+ "optimization": {
59
+ "compress_weight": false,
60
+ "enable_flash_attention": true,
61
+ "model_pruning": false,
62
+ "optimization_level": 0,
63
+ "remove_reshape": false,
64
+ "remove_weight": false,
65
+ "sparse_infer": false
66
+ },
67
+ "quantization": {
68
+ "auto_hybrid_cos_thresh": 0.98,
69
+ "auto_hybrid_euc_thresh": null,
70
+ "dataset_columns": null,
71
+ "dataset_name": null,
72
+ "dataset_size": 128,
73
+ "dataset_split": null,
74
+ "dataset_subset": null,
75
+ "do_quantization": false,
76
+ "quant_img_RGB2BGR": false,
77
+ "quantized_algorithm": "normal",
78
+ "quantized_dtype": "w8a8",
79
+ "quantized_hybrid_level": 0,
80
+ "quantized_method": "channel"
81
+ },
82
+ "rktransformers_version": "0.3.0",
83
+ "single_core_mode": false,
84
+ "std_values": null,
85
+ "target_platform": "rk3588",
86
+ "task": "token-classification",
87
+ "task_kwargs": null
88
+ }
89
+ },
90
+ "torch_dtype": "float32",
91
+ "transformers_version": "4.55.4",
92
+ "type_vocab_size": 2,
93
+ "use_cache": true,
94
+ "vocab_size": 28996
95
+ }
model.rknn ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:4fccf2a668008908d0167f73ca769f1e29ab68cb29346878388124149cabd5cd
3
+ size 223236674
rknn.json ADDED
@@ -0,0 +1,46 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "model.rknn": {
3
+ "rktransformers_version": "0.2.0",
4
+ "model_input_names": [
5
+ "input_ids",
6
+ "attention_mask",
7
+ "token_type_ids"
8
+ ],
9
+ "batch_size": 1,
10
+ "max_seq_length": 512,
11
+ "float_dtype": "float16",
12
+ "target_platform": "rk3588",
13
+ "single_core_mode": false,
14
+ "mean_values": null,
15
+ "std_values": null,
16
+ "custom_string": null,
17
+ "inputs_yuv_fmt": null,
18
+ "dynamic_input": null,
19
+ "opset": 19,
20
+ "task": "token-classification",
21
+ "quantization": {
22
+ "do_quantization": false,
23
+ "dataset_name": null,
24
+ "dataset_subset": null,
25
+ "dataset_size": 128,
26
+ "dataset_split": null,
27
+ "dataset_columns": null,
28
+ "quantized_dtype": "w8a8",
29
+ "quantized_algorithm": "normal",
30
+ "quantized_method": "channel",
31
+ "quantized_hybrid_level": 0,
32
+ "quant_img_RGB2BGR": false,
33
+ "auto_hybrid_cos_thresh": 0.98,
34
+ "auto_hybrid_euc_thresh": null
35
+ },
36
+ "optimization": {
37
+ "optimization_level": 0,
38
+ "enable_flash_attention": true,
39
+ "remove_weight": false,
40
+ "compress_weight": false,
41
+ "remove_reshape": false,
42
+ "sparse_infer": false,
43
+ "model_pruning": false
44
+ }
45
+ }
46
+ }
special_tokens_map.json ADDED
@@ -0,0 +1,7 @@
 
 
 
 
 
 
 
 
1
+ {
2
+ "cls_token": "[CLS]",
3
+ "mask_token": "[MASK]",
4
+ "pad_token": "[PAD]",
5
+ "sep_token": "[SEP]",
6
+ "unk_token": "[UNK]"
7
+ }
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
tokenizer_config.json ADDED
@@ -0,0 +1,59 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "added_tokens_decoder": {
3
+ "0": {
4
+ "content": "[PAD]",
5
+ "lstrip": false,
6
+ "normalized": false,
7
+ "rstrip": false,
8
+ "single_word": false,
9
+ "special": true
10
+ },
11
+ "100": {
12
+ "content": "[UNK]",
13
+ "lstrip": false,
14
+ "normalized": false,
15
+ "rstrip": false,
16
+ "single_word": false,
17
+ "special": true
18
+ },
19
+ "101": {
20
+ "content": "[CLS]",
21
+ "lstrip": false,
22
+ "normalized": false,
23
+ "rstrip": false,
24
+ "single_word": false,
25
+ "special": true
26
+ },
27
+ "102": {
28
+ "content": "[SEP]",
29
+ "lstrip": false,
30
+ "normalized": false,
31
+ "rstrip": false,
32
+ "single_word": false,
33
+ "special": true
34
+ },
35
+ "103": {
36
+ "content": "[MASK]",
37
+ "lstrip": false,
38
+ "normalized": false,
39
+ "rstrip": false,
40
+ "single_word": false,
41
+ "special": true
42
+ }
43
+ },
44
+ "clean_up_tokenization_spaces": true,
45
+ "cls_token": "[CLS]",
46
+ "do_basic_tokenize": true,
47
+ "do_lower_case": false,
48
+ "extra_special_tokens": {},
49
+ "mask_token": "[MASK]",
50
+ "max_len": 512,
51
+ "model_max_length": 512,
52
+ "never_split": null,
53
+ "pad_token": "[PAD]",
54
+ "sep_token": "[SEP]",
55
+ "strip_accents": null,
56
+ "tokenize_chinese_chars": true,
57
+ "tokenizer_class": "BertTokenizer",
58
+ "unk_token": "[UNK]"
59
+ }
vocab.txt ADDED
The diff for this file is too large to render. See raw diff