readme: ---
  language: en
  pipeline_tag: fill-mask
  license: cc-by-sa-4.0
  thumbnail: https://i.ibb.co/0yz81K9/sec-bert-logo.png
  tags:
  - finance
  - financial
  widget:
  - text: "Total net sales [MASK] 2% or $5.4 billion during 2019 compared to 2018."
  - text: "Total net sales decreased 2% or $5.4 [MASK] during 2019 compared to 2018."
  - text: "During 2019, the Company [MASK] $67.1 billion of its common stock and paid dividend equivalents of $14.1 billion."
  - text: "During 2019, the Company repurchased $67.1 billion of its common [MASK] and paid dividend equivalents of $14.1 billion."
  - text: "During 2019, the Company repurchased $67.1 billion of its common stock and paid [MASK] equivalents of $14.1 billion."
  - text: "During 2019, the Company repurchased $67.1 billion of its common stock and paid dividend [MASK] of $14.1 billion."
  ---
  
  # SEC-BERT
  
  <img align="center" src="https://i.ibb.co/0yz81K9/sec-bert-logo.png" alt="SEC-BERT" width="400"/>
  
  <div style="text-align: justify">
  
  SEC-BERT is a family of BERT models for the financial domain, intended to assist financial NLP research and FinTech applications.
  SEC-BERT consists of the following models:
  * **SEC-BERT-BASE** (this model): Same architecture as BERT-BASE trained on financial documents.
  * [**SEC-BERT-NUM**](https://huggingface.co/nlpaueb/sec-bert-num): Same as SEC-BERT-BASE but we replace every number token with a [NUM] pseudo-token handling all numeric expressions in a uniform manner, disallowing their fragmentation
  * [**SEC-BERT-SHAPE**](https://huggingface.co/nlpaueb/sec-bert-shape): Same as SEC-BERT-BASE but we replace numbers with pseudo-tokens that represent the number’s shape, so numeric expressions (of known shapes) are no longer fragmented, e.g., '53.2' becomes '[XX.X]' and '40,200.5' becomes '[XX,XXX.X]'.
  </div>
  
  ## Pre-training corpus
  
  The model was pre-trained on 260,773 10-K filings from 1993-2019, publicly available at <a href="https://www.sec.gov/">U.S. Securities and Exchange Commission (SEC)</a>
  
  ## Pre-training details
  
  <div style="text-align: justify">
  
  * We created a new vocabulary of 30k subwords by training a [BertWordPieceTokenizer](https://github.com/huggingface/tokenizers) from scratch on the pre-training corpus.
  * We trained BERT using the official code provided in [Google BERT's GitHub repository](https://github.com/google-research/bert)</a>.
  * We then used [Hugging Face](https://huggingface.co)'s [Transformers](https://github.com/huggingface/transformers) conversion script to convert the TF checkpoint in the desired format in order to be able to load the model in two lines of code for both PyTorch and TF2 users.
  * We release a model similar to the English BERT-BASE model (12-layer, 768-hidden, 12-heads, 110M parameters).
  * We chose to follow the same training set-up: 1 million training steps with batches of 256 sequences of length 512 with an initial learning rate 1e-4.
  * We were able to use a single Google Cloud TPU v3-8 provided for free from [TensorFlow Research Cloud (TRC)]((https://sites.research.google/trc), while also utilizing [GCP research credits](https://edu.google.com/programs/credits/research). Huge thanks to both Google programs for supporting us!
  </div>
  
  ## Load Pretrained Model
  
  ```python
  from transformers import AutoTokenizer, AutoModel
  
  tokenizer = AutoTokenizer.from_pretrained("nlpaueb/sec-bert-base")
  model = AutoModel.from_pretrained("nlpaueb/sec-bert-base")
  ```
  
  ## Using SEC-BERT variants as Language Models
  
  | Sample                                              | Masked Token |
  | --------------------------------------------------- | ------------ |
  | Total net sales [MASK] 2% or $5.4 billion during 2019 compared to 2018. | decreased
  
  | Model                                               | Predictions (Probability)  |
  | --------------------------------------------------- | ------------ |
  | **BERT-BASE-UNCASED** | increased (0.221), were (0.131), are (0.103), rose (0.075), of (0.058)
  | **SEC-BERT-BASE** | increased (0.678), decreased (0.282), declined (0.017), grew (0.016), rose (0.004)
  | **SEC-BERT-NUM** | increased (0.753), decreased (0.211), grew (0.019), declined (0.010), rose (0.006)
  | **SEC-BERT-SHAPE** | increased (0.747), decreased (0.214), grew (0.021), declined (0.013), rose (0.002)
  
  
  | Sample                                              | Masked Token |
  | --------------------------------------------------- | ------------ |
  | Total net sales decreased 2% or $5.4 [MASK] during 2019 compared to 2018. | billion
  
  | Model                                               | Predictions (Probability)  |
  | --------------------------------------------------- | ------------ |
  | **BERT-BASE-UNCASED** | billion (0.841), million (0.097), trillion (0.028), ##m (0.015), ##bn (0.006)
  | **SEC-BERT-BASE** | million (0.972), billion (0.028), millions (0.000), ##million (0.000), m (0.000)
  | **SEC-BERT-NUM** | million (0.974), billion (0.012), , (0.010), thousand (0.003), m (0.000)
  | **SEC-BERT-SHAPE** | million (0.978), billion (0.021), 