Views
No views yet
bert-base-uncased and adds a tiny learned
capitalization embedding channel. The lexical token ID still follows the
uncased BERT vocabulary, while a parallel capitalization_ids tensor carries
case information:10 = lowercase / no capitalization feature / punctuation / special token
21 = first-cap, e.g. Tom
32 = all-caps, e.g. NASA
43 = mixed-case, e.g. iPhonemixed_case_dropout/capitalized_from_3class_steps3000_lr2e5_drop01/final1base model: bert-base-uncased
2capitalization vocab size: 4
3capitalization loss weight: 0.25
4capitalization class weights: [1, 2, 8, 4]
5capitalization embedding dropout: 0.1
6continued pretraining: 3,000 steps on the real-acronym mixAutoModelForMaskedLM. Install the project package first:pip install git+https://github.com/Santosh-Gupta/CapitalizationEmbeddings.git1from transformers import AutoTokenizer
2
3from capitalization_embeddings import (
4 CapitalizedBertForMaskedLM,
5 tokenize_with_capitalization,
6)
7
8repo_id = "Santosh-Gupta/capitalized-bert-base-uncased-mlm"
9
10tokenizer = AutoTokenizer.from_pretrained(repo_id, use_fast=True)
11model = CapitalizedBertForMaskedLM.from_pretrained(repo_id)
12
13encoding = tokenize_with_capitalization(
14 tokenizer,
15 "Tom works at NASA.",
16 return_tensors="pt",
17 use_mixed_case=True,
18)
19
20outputs = model(**encoding)
21print(outputs.logits.shape)
22print(outputs.capitalization_logits.shape)bert-base-cased.| Benchmark | Metric | Uncased | Cased | Capitalized |
|---|---|---|---|---|
| CoNLL-2003 NER | entity F1 | 0.9040 +/- 0.0025 | 0.9119 +/- 0.0035 | 0.9165 +/- 0.0018 |
| WNUT-17 NER | entity F1 | 0.4424 +/- 0.0152 | 0.4426 +/- 0.0100 | 0.4495 +/- 0.0103 |
| SST-5 | accuracy | 0.5410 +/- 0.0039 | 0.5283 +/- 0.0084 | 0.5407 +/- 0.0068 |
1Santosh Gupta. CapitalizationEmbeddings.
2https://github.com/Santosh-Gupta/CapitalizationEmbeddings