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
: Same architecture as BERT-BASE trained on financial documents.
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
(this model): 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]'.
We then used
Hugging Face
's
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.
from transformers import AutoTokenizer, AutoModel
tokenizer = AutoTokenizer.from_pretrained("nlpaueb/sec-bert-shape")
model = AutoModel.from_pretrained("nlpaueb/sec-bert-shape")
Pre-process Text
To use SEC-BERT-SHAPE, you have to pre-process texts replacing every numerical token with the corresponding shape pseudo-token, from a list of 214 predefined shape pseudo-tokens. If the numerical token does not correspond to any shape pseudo-token we replace it with the [NUM] pseudo-token.
Below there is an example of how you can pre-process a simple sentence. This approach is quite simple; feel free to modify it as you see fit.
import re
import spacy
from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained("nlpaueb/sec-bert-shape")
spacy_tokenizer = spacy.load("en_core_web_sm")
sentence = "Total net sales decreased 2% or $5.4 billion during 2019 compared to 2018."defsec_bert_shape_preprocess(text):
tokens = [t.text for t in spacy_tokenizer(sentence)]
processed_text = []
for token in tokens:
if re.fullmatch(r"(\d+[\d,.]*)|([,.]\d+)", token):
shape = '[' + re.sub(r'\d', 'X', token) + ']'if shape in tokenizer.additional_special_tokens:
processed_text.append(shape)
else:
processed_text.append('[NUM]')
else:
processed_text.append(token)
return' '.join(processed_text)
tokenized_sentence = tokenizer.tokenize(sec_bert_shape_preprocess(sentence))
print(tokenized_sentence)
"""['total', 'net', 'sales', 'decreased', '[X]', '%', 'or', '$', '[X.X]', 'billion', 'during', '[XXXX]', 'compared', 'to', '[XXXX]', '.']"""
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), % (0.000), , (0.000), millions (0.000)
Sample
Masked Token
Total net sales decreased [MASK]% or $5.4 billion during 2019 compared to 2018.
If you use this model cite the following article:
FiNER: Financial Numeric Entity Recognition for XBRL Tagging
Lefteris Loukas, Manos Fergadiotis, Ilias Chalkidis, Eirini Spyropoulou, Prodromos Malakasiotis, Ion Androutsopoulos and George Paliouras
In the Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (ACL 2022) (Long Papers), Dublin, Republic of Ireland, May 22 - 27, 2022
@inproceedings{loukas-etal-2022-finer,
title = {FiNER: Financial Numeric Entity Recognition for XBRL Tagging},
author = {Loukas, Lefteris and
Fergadiotis, Manos and
Chalkidis, Ilias and
Spyropoulou, Eirini and
Malakasiotis, Prodromos and
Androutsopoulos, Ion and
Paliouras George},
booktitle = {Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (ACL 2022)},
publisher = {Association for Computational Linguistics},
location = {Dublin, Republic of Ireland},
year = {2022},
url = {https://arxiv.org/abs/2203.06482}
}
question answering systems for databases, ontologies, document collections, and the Web, especially biomedical question answering,
natural language generation from databases and ontologies, especially Semantic Web ontologies,
text classification, including filtering spam and abusive content,
information extraction and opinion mining, including legal text analytics and sentiment analysis,
natural language processing tools for Greek, for example parsers and named-entity recognizers,
machine learning in natural language processing, especially deep learning.
The group is part of the Information Processing Laboratory of the Department of Informatics of the Athens University of Economics and Business.
sec-bert-shape huggingface.co is an AI model on huggingface.co that provides sec-bert-shape's model effect (), which can be used instantly with this nlpaueb sec-bert-shape model. huggingface.co supports a free trial of the sec-bert-shape model, and also provides paid use of the sec-bert-shape. Support call sec-bert-shape model through api, including Node.js, Python, http.
sec-bert-shape huggingface.co is an online trial and call api platform, which integrates sec-bert-shape's modeling effects, including api services, and provides a free online trial of sec-bert-shape, you can try sec-bert-shape online for free by clicking the link below.
nlpaueb sec-bert-shape online free url in huggingface.co:
sec-bert-shape is an open source model from GitHub that offers a free installation service, and any user can find sec-bert-shape on GitHub to install. At the same time, huggingface.co provides the effect of sec-bert-shape install, users can directly use sec-bert-shape installed effect in huggingface.co for debugging and trial. It also supports api for free installation.