1.School of Computer Science and Technology,Wuhan University of Science and Technology,Wuhan 430065,Hubei,China
2.Hubei Province Key Laboratory of Intelligent Information Processing and Real-Time Industrial System,Wuhan 430065,Hubei,China
3.Hubei Key Laboratory of Digital Finance Innovation,Hubei University of Economics,Wuhan 430205,Hubei,China
4.Interdisciplinary Research Institute in New Finance and Economics (School of Digital Economics),Hubei University of Economics,Wuhan 430205,Hubei,China
In the field of sentiment analysis, large language models (LLMs) have been widely adopted for sentiment judgment. However, financial texts inherently involve complex sentiment features with blurred boundaries between distinct sentiment categories, presenting LLMs with substantial challenges in accurate classification. To address this issue, we propose a method that integrates a financial sentiment knowledge graph with few-shot prompting for multi-level knowledge enhancement. The graph is semi-automatically constructed using LLMs, and financial terms within it are annotated with sentiment labels. This information is explicitly represented through prompt templates, providing semantic-level support for the LLM. Experiments are conducted on Qwen2.5-7B, ChatGLM3-6B, and ChatGLM4-9B, demonstrating that our approach significantly improves sentiment analysis accuracy, with an average F1 increase of 3.67 percentage points over LLM that don’t employ without this method. The results show that this method provides new solutions and important references for financial text sentiment analysis.
在金融领域,情感分析(Sentiment Analysis)已经成为理解市场情绪、预测金融风险和指导投资决策的重要工具。早期研究主要依赖于词典方法,Loughran和McDonald[1]开发的金融情感词典为情感词的分类和计量奠定了基础。随着深度学习的发展,各种基于深度学习的预训练语言模型(如BERT[2]、RoBERTa[3]等)在情感分析任务中展现了更优的性能,这些模型利用上下文信息捕捉能力,显著提高了文本分析的准确性。Fatouros等[4]进一步探讨了大语言模型(Large Language Model,LLM)在金融情感分析中的潜力,结果表明LLM在该领域具有显著优势。
金融文本情感分析是自然语言处理(Natural Language Processing,NLP)领域的重要研究方向,其目标是通过对金融领域的文本数据进行情感倾向性分析,以辅助投资决策和市场预测。Todd等[9]对将情感分析技术应用于金融领域的现有文献进行了评估,并对未来研究方向进行了探讨,指出随着深度学习技术的发展,Transformer架构和多模态分析(Multi-modal Analysis)将成为研究热点。近年来,LLM在金融文本情感分析中的应用逐渐增多,取得了显著效果。例如Zhang等[10]提出的Instruct-FinGPT,通过创建一系列人工编写的指令,将金融情感分析数据集转换为指令格式的数据集,将通用LLM适配至金融情感分析任务,增强了LLM在金融情感分析中的表现。Qian等[11]提出的Fino1模型,使用推理增强方法在多个金融任务中实现了性能提升,超越了同等参数规模的其他模型。
其中, Q 为Query向量; K 为Key向量;为Key向量的维度; V 为Value向量。使用Query向量和Key向量计算输入序列中每个词的相关性之后对Value向量进行加权求和,生成注意力输出。在示例层中,使用少样本示例构建上下文学习模块,其核心作用是通过隐式任务范式定义和动态特征加权引导LLM在无参数修改的条件下适应目标任务。通过示例中的句子-标签对构建任务映射规则,增强目标文本中与示例相似词汇的注意力权重,帮助LLM理解输入文本与情感标签之间的对应关系。知识层是将结构化知识图谱嵌入模块,其核心作用是通过显性领域知识注入和语义约束,引导LLM在注意力机制中优先关注相应金融词汇的情感特征。将构建好的提示模板输入LLM后,经过模型编码器转化为知识向量 EPrompt,如(6)式所示:
其中,是示例层编码的任务范式向量,负责提供结构映射规则;是知识层编码的领域知识向量,负责提供多维度情感知识,从而达到情感特征增强。两者结合进而对 Q 和 K 进行修正,如(7)式所示:
其中,和是完全隐性表达的参数,分别用于衡量嵌入向量对 Q 和 K 的影响程度。当=0时,LLM完全忽略Prompt带来的多层次知识增强,等同于未引入任何知识的原始注意力机制;当≠0时,和受到了多层次知识增强带来的信息,会因提示模板中的示例层和知识层影响到注意力权重分配。
在情感分类任务中,本文使用一组标准的评估指标衡量模型的分类效果,包括准确率(Accuracy)、查准率(Precision)和F1。这些指标基于混淆矩阵计算,如表5所示,该矩阵展示了模型在不同情感类别上的分类结果。其中,TP k :真实为类别k且预测为类别k的样本数。FN kj :真实为类别k但预测为类别j的样本数。
准确率(Accuracy)是最基本的分类性能指标,表示模型正确分类的样本占总样本的比例。查准率(Precision k )为模型预测为某类别的样本中实际为该类别的比例,反映模型对正类的识别能力。F1(F1 k )是查准率和查全率的调和平均数,是一个综合考虑查准率和查全率的指标,尤其在类别不平衡的情况下比准确率更具参考意义。这些指标的计算公式如下:
LOUGHRANT, MCDONALDB. When is a liability not a liability? textual analysis, dictionaries, and 10-ks[J]. The Journal of Finance, 2011, 66(1): 35-65. DOI: 10.1111/j.1540-6261.2010.01625.x .
[2]
DEVLINJ, CHANGM W, LEEK, et al. BERT: Pre-training of deep bidirectional transformers for language understanding[EB/OL]. [2024-12-20]. DOI: 10.18653/v1/n18-2 .
[3]
LIUY H, OTT M, GOYALN, et al. RoBERTa: A Robustly Optimized BERT Pretraining Approach[EB/OL]. [2019-07-26].
[4]
FATOUROSG, SOLDATOSJ, KOUROUMALIK, et al. Transforming sentiment analysis in the financial domain with ChatGPT[J]. Machine Learning with Applications, 2023, 14: 100508. DOI: 10.1016/j.mlwa.2023.100508 .
[5]
JIS X, PANS R, CAMBRIAE, et al. A survey on knowledge graphs: Representation, acquisition, and applications[J]. IEEE Transactions on Neural Networks and Learning Systems, 2022, 33(2): 494-514. DOI: 10.1109/TNNLS.2021.3070843 .
[6]
BROWNT, MANNB, RYDERN, et al. Language models are few-shot learners[EB/OL]. [2020-07-22]. DOI: 10.48550/arXiv.2005.14165 .
[7]
PANS R, LUOL H, WANGY F, et al. Unifying large language models and knowledge graphs: A roadmap[J]. IEEE Transactions on Knowledge and Data Engineering, 2024, 36(7): 3580-3599. DOI: 10.1109/TKDE.2024.3352100 .
[8]
BOZKURTA. Tell me your prompts and I will make them true: The alchemy of prompt engineering and generative AI[J]. Open Praxis, 2024, 16(2): 111-118. DOI: 10.55982/openpraxis.16.2.661 .
[9]
TODDA, BOWDENJ, MOSHFEGHIY. Text-based sentiment analysis in finance: Synthesising the existing literature and exploring future directions[J]. Intelligent Systems in Accounting, Finance and Management, 2024, 31(1): e1549. DOI: 10.1002/isaf.1549 .
[10]
ZHANGB Y, YANGH Y, LIUX Y. Instruct-FinGPT: Financial sentiment analysis by instruction tuning of general-purpose large language models[EB/OL]. [2023-06-22]. DOI: 10.2139/ssrn.4489831 .
[11]
QIANL F, ZHOUW P, WANGY, et al. Fino1: On the transferability of reasoning enhanced LLM to finance[EB/OL]. [2025-02-27]. DOI: 10.2139/ssrn.6037726 .
[12]
YUW H, ZHUC G, LIZ T, et al. A survey of knowledge-enhanced text generation[J]. ACM Computing Surveys, 2022, 54(11s): 1-38. DOI: 10.1145/3512467 .
[13]
WANZ, CHENGF, MAOZ Y, et al. GPT-RE: In-context learning for relation extraction using large language models[C]//Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing, Singapore: Association for Computational Linguistics, 2023: 3534-3547. DOI:10.18653/v1/2023.emnlp-main.214 .
[14]
SUNJ W, DUZ X, CHENY R, et al. Knowledge graph tuning: Real-time large language model personalization based on human feedback[EB/OL].[2024-05-30].
[15]
YORANO, WOLFSONT, BOGINB, et al. Answering questions by meta-reasoning over multiple chains of thought[C]//Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing. Singapore. Stroudsburg: ACL, 2023: 5942-5966. DOI: 10.18653/v1/2023.emnlp-main.364 .
[16]
WUY K, HUN, QIG L, et al. Retrieve-Rewrite-Answer: A KG-to-Text Enhanced LLM Framework for Knowledge Graph Question Answering[EB/OL]. [2023-09-20].
[17]
SAHOOP, SINGHK A, SAHAS, et al. A Systematic Survey of Prompt Engineering in Large Language Models: Techniques and Applications[EB/OL]. [2024-02-05]. DOI: 10.1007/979-8-8688-0569-1_4 .
XUL H, LINH F, PANY, et al. Constructing the affective lexicon ontology[J]. Journal of the China Society for Scientific and Technical Information, 2008, 27(2): 180-185. DOI: 10.3969/j.issn.1000-0135.2008.02.004(Ch ).
DUZ X, QIANY J, LIUX, et al. GLM: General language model pretraining with autoregressive blank infilling[C]//Proceedings of the 60th Annual Meeting of the Association for Computational Linguistics (Volume 1: Long Papers). Stroudsburg: ACL, 2022: 320-335. DOI: 10.18653/v1/2022.acl-long.26 .
[22]
ZENGA H, XUB, WANGB W, et al. ChatGLM: A Family of Large Language Models from GLM-130B to GLM-4 All Tools[EB/OL]. [2024-06-18].
[23]
DOGUA. FinBERT: Financial sentiment analysis with pre‑trained language models[EB/OL]. [2019-08-27].