Harsh-svg988 GitHub avatar

financial-sentiment-nlp

Harsh-svg988

该项目微调 DistilBERT 对金融推文进行看跌、看涨或中性情感分类,并使用 TF-IDF+逻辑回归基线进行对比。

Stars

4

7 天增长

暂无数据

Fork 数

0

开放 Issue

0

开源协议

暂无数据

最近更新

2026-07-29

AI 仓库情报摘要
FR-AI / ANALYSIS

为什么值得关注

它展示了清晰可复现的流程,通过加权损失和宏 F1 处理类别不平衡,并使用诚实的基线验证了 Transformer 在少数类上的提升。

适合谁使用

  • 对金融文本分类感兴趣的 NLP 从业者
  • 构建交易信号情感分析的数据科学家
  • 学习迁移学习和模型评估的学生
  • 寻求自动化新闻情感工具的金融分析师

典型使用场景

  • 将金融新闻标题或推文分类为看涨/看跌/中性
  • 增强交易策略的实时情感信号
  • 在不平衡数据集中对比 Transformer 模型与传统基线
  • 在 Apple Silicon 上使用加权损失微调 DistilBERT 的教学示例

项目优势

  • 清晰的问题定义和宏 F1 评估,有效处理类别不平衡
  • 诚实的基线(TF-IDF 二元组+类别权重)确保 Transformer 改进是真实的
  • 可复现的流程,包含文档步骤、代码结构和图表
  • 在损失函数和评估指标两个层面处理不平衡

使用前须知

  • 仅在约 1.2 万条推文的单一数据集上测试,对其他金融文本源的泛化性未验证
  • 仅使用 DistilBERT,未与其他 Transformer 模型或更大架构比较
  • 未提供部署或推理 API,需本地 Python 环境运行预测

README 快速开始

Financial Sentiment Analysis with DistilBERT

Fine-tuning a transformer to classify the sentiment of financial-news tweets as Bearish, Bullish, or Neutral, and benchmarking it against a classical TF-IDF + Logistic Regression baseline. Fine-tuning runs on Apple-Silicon GPU (MPS).

Problem

Given a short financial statement (e.g. "$AAPL smashes revenue estimates, guidance raised"), predict market sentiment. This is a 3-class, imbalanced text classification task (65% of tweets are Neutral), so the project reports macro-F1 alongside accuracy so the minority classes actually count.

Results (validation set, 2,388 tweets)

ModelAccuracyMacro-F1
TF-IDF + Logistic Regression (baseline)0.8120.755
Fine-tuned DistilBERT0.8510.818

Fine-tuning lifts macro-F1 by +6.3 points — the gain concentrates on the minority Bearish/Bullish classes, where the transformer's contextual understanding beats bag-of-words. Per-class DistilBERT F1: Bearish 0.76, Bullish 0.81, Neutral 0.89.

Live inference examples (src/predict.py):

"Tesla shares tumble after disappointing quarterly earnings"   -> Bearish (98%)
"$AAPL smashes revenue estimates, guidance raised next quarter" -> Bullish (98%)
"The Federal Reserve will announce its rate decision Wednesday" -> Neutral (98%)

Approach

  1. Data + EDA (src/data.py) — 9,543 train / 2,388 validation tweets; light cleaning that keeps $TICKERS and % since they carry sentiment signal.
  2. Baseline (src/baseline.py) — TF-IDF (1–2 grams) + Logistic Regression with balanced class weights. A strong baseline so the transformer has something real to beat.
  3. Fine-tuning (src/train.py) — DistilBERT with a class-weighted cross-entropy loss to handle imbalance; best checkpoint selected by macro-F1; 3 epochs, lr 2e-5, on MPS.
  4. Evaluation (src/evaluate.py) — classification report, confusion matrix, and a baseline-vs-transformer comparison chart.
  5. Inference (src/predict.py) — sentiment + class probabilities for any text.

Figures (reports/figures/)

01_class_distribution.pngclass imbalance in the training set
02_tweet_length.pngtweet-length distribution
03_confusion_matrix.pngDistilBERT errors by class
04_model_comparison.pngbaseline vs. fine-tuned m

相关仓库与替代方案

根据分类、Topic 和编程语言匹配的相似项目。

slvDev
精选
slvDev GitHub avatar

esp32-ai

A 28.9 million parameter language model runs on an $8 ESP32-S3 microcontroller entirely on-device, generating simple stories at about 9.5 tokens per second.

AI 与机器学习大语言模型
1,960
gavamedia
精选
gavamedia GitHub avatar

deltafin

Deltafin is a research project that runs the 2.8-trillion-parameter Mixture-of-Experts model Kimi K3 on a single Apple Silicon Mac (e.g., M1 Max with 64 GB) at about 16 seconds per token, using exact, reproducible inference with local or streaming expert loading.

AI 与机器学习大语言模型
304
jamesob
精选
jamesob GitHub avatar

local-llm

A comprehensive guide for building and configuring a high-end local machine to run state-of-the-art LLMs, with detailed hardware choices, BIOS tuning, and Docker-based model serving.

AI 与机器学习大语言模型
1,660