FinBERT: Financial Sentiment Analysis with Pre-trained Language Models
Paper β’ 1908.10063 β’ Published β’ 5
How to use nicechester/finbert-sentiment-onnx-quantized with Transformers.js:
// npm i @huggingface/transformers
import { pipeline } from '@huggingface/transformers';
// Allocate pipeline
const pipe = await pipeline('text-classification', 'nicechester/finbert-sentiment-onnx-quantized');INT8 quantized ONNX export of ProsusAI/finbert for 3-class financial sentiment classification (positive, negative, neutral).
Unlike other quantized FinBERT models that only export embeddings, this model preserves the classification head for direct sentiment inference.
Optimized for Node.js backends, edge environments, and in-browser inference using @huggingface/transformers (v3+).
| Property | Value |
|---|---|
| Base Model | ProsusAI/finbert |
| Task | Text Classification (3-class sentiment) |
| Format | ONNX (INT8 dynamic quantization) |
| Model Size | ~110 MB (vs ~438 MB FP32) |
| Size Reduction | ~75% |
| Target Hardware | ARM64 & x86_64 CPUs |
npm install @huggingface/transformers
import { pipeline } from '@huggingface/transformers';
const classifier = await pipeline(
'text-classification',
'nicechester/finbert-sentiment-onnx-quantized',
{ model_file_name: 'model', dtype: 'q8' }
);
const result = await classifier('Revenue exceeded expectations by 15%.');
console.log(result);
// [{ label: 'positive', score: 0.9631 }]
const results = await classifier([
'Strong quarterly earnings driven by cloud growth.',
'Company announces layoffs amid declining sales.',
'Board approved regular dividend payment.'
]);
console.log(results);
// [
// { label: 'positive', score: 0.9245 },
// { label: 'negative', score: 0.8872 },
// { label: 'neutral', score: 0.7654 }
// ]
import { pipeline, env } from '@huggingface/transformers';
env.localModelPath = '/path/to/models';
env.allowRemoteModels = false;
const classifier = await pipeline(
'text-classification',
'finbert-sentiment-onnx-quantized', // folder name under localModelPath
{ model_file_name: 'model', dtype: 'q8' }
);
Required folder structure:
/path/to/models/finbert-sentiment-onnx-quantized/
βββ config.json
βββ tokenizer.json
βββ tokenizer_config.json
βββ vocab.txt
βββ onnx/
βββ model_quantized.onnx
// Single text
[{ label: 'positive' | 'negative' | 'neutral', score: number }]
// Batch
[
{ label: 'positive', score: 0.92 },
{ label: 'negative', score: 0.85 },
...
]
Exported and quantized using Hugging Face Optimum:
# 1. Export to ONNX with classification head
optimum-cli export onnx \
--model ProsusAI/finbert \
--task text-classification \
./finbert-onnx/
# 2. Quantize to INT8
optimum-cli onnxruntime quantize \
--onnx_model ./finbert-onnx/ \
--arm64 \
-o ./finbert-quantized/
@article{araci2019finbert,
title={FinBERT: Financial Sentiment Analysis with Pre-Trained Language Models},
author={Araci, Dogu},
journal={arXiv preprint arXiv:1908.10063},
year={2019}
}
Apache 2.0 (same as base model)
Base model
ProsusAI/finbert