Financial English BERT Embeddings (Number shape masking)

Description

Pretrained Financial BERT Embeddings model, uploaded to Hugging Face, adapted and imported into Spark NLP. sec-bert-shape is a English model orginally trained by nlpaueb.This model is the same as 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]’.

If you are interested in Financial Embeddings, take a look also at these two models:

  • sec-base: Same as BERT Base but trained with financial documents.
  • sec-num: Same as Bert sec-base but we replace every number token with a [NUM] pseudo-token handling all numeric expressions in a uniform manner, disallowing their fragmentation).

Download

How to use


documentAssembler = DocumentAssembler() \
    .setInputCol("text") \
    .setOutputCol("document")

tokenizer = Tokenizer() \
    .setInputCols("document") \
    .setOutputCol("token")
  
embeddings = BertEmbeddings.pretrained("bert_embeddings_sec_bert_sh","en") \
    .setInputCols(["document", "token"]) \
    .setOutputCol("embeddings")
    
pipeline = Pipeline(stages=[documentAssembler, tokenizer, embeddings])

data = spark.createDataFrame([["I love Spark NLP"]]).toDF("text")

result = pipeline.fit(data).transform(data)
val documentAssembler = new DocumentAssembler() 
    .setInputCol("text") 
    .setOutputCol("document")
 
val tokenizer = new Tokenizer() 
    .setInputCols(Array("document"))
    .setOutputCol("token")

val embeddings = BertEmbeddings.pretrained("bert_embeddings_sec_bert_sh","en") 
    .setInputCols(Array("document", "token")) 
    .setOutputCol("embeddings")

val pipeline = new Pipeline().setStages(Array(documentAssembler, tokenizer, embeddings))

val data = Seq("I love Spark NLP").toDF("text")

val result = pipeline.fit(data).transform(data)

Model Information

Model Name: bert_embeddings_sec_bert_sh
Compatibility: Spark NLP 3.4.2+
License: Open Source
Edition: Official
Input Labels: [sentence, token]
Output Labels: [bert]
Language: en
Size: 409.5 MB
Case sensitive: true

References

  • https://huggingface.co/nlpaueb/sec-bert-shape
  • https://arxiv.org/abs/2203.06482
  • http://nlp.cs.aueb.gr/