finBERT-金融英文情感分析运行介绍

本文介绍了finBERT项目的实施步骤,包括从GitHub下载项目源码,通过dataset.py处理数据,训练模型,测试模型性能,并最终通过Flask接口实现交互。实验结果显示,经过训练后的模型在金融英文情感分析上的成功率显著提高。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、github项目下载

finBERT项目源码
我的项目路径
我的项目路径

二、模型训练及输出测试

1.运行dataset.py

在这里插入图片描述

2.生成data

数据来源路透社的文章一些节选,需要的可以github项目中有下载地址
在这里插入图片描述

3.训练模型

from pathlib import Path
import sys

sys.path.append('..')
import argparse
import shutil
import os
import logging
from textblob import TextBlob
from pytorch_pretrained_bert.file_utils import PYTORCH_PRETRAINED_BERT_CACHE
from pytorch_pretrained_bert.modeling import BertForSequenceClassification
from pytorch_pretrained_bert.tokenization import BertTokenizer
from pytorch_pretrained_bert.optimization import *

from finbert.finbert import *
import finbert.utils as tools
from pprint import pprint
from sklearn.metrics import classification_report

project_dir = Path.cwd().parent
pd.set_option('max_colwidth', -1)

# %%

logging.basicConfig(format='%(asctime)s - %(levelname)s - %(name)s -   %(message)s',
                    datefmt='%m/%d/%Y %H:%M:%S',
                    level=logging.ERROR)

# %% md

## Prepare the model

# %% md


# %%

# lm_path = project_dir / 'models' / 'TRC2' / 'pytorch_model.bin'
lm_path = project_dir / 'models' / 'classifier_model' / 'TRC2'
cl_path = project_dir / 'models' / 'classifier_model' / 'finbert-sentiment'
cl_data_path = project_dir / 'data' / 'sentiment_data'

try:
    shutil.rmtree(cl_path)
except:
    pass

bertmodel = BertForSequenceClassification.from_pretrained(lm_path, cache_dir
评论 11
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值