应用科学学报 ›› 2026, Vol. 44 ›› Issue (1): 34-49.doi: 10.3969/j.issn.0255-8297.2026.01.003

• 计算机应用专辑 • 上一篇    下一篇

基于改进Transformer的复杂逻辑查询模型

陈昱胤1, 李贯峰1,2, 秦晶1, 肖毓航1   

  1. 1. 宁夏大学 信息工程学院, 宁夏 银川 750021;
    2. 宁夏"东数西算" 人工智能与信息安全重点实验室, 宁夏 银川 750021
  • 收稿日期:2025-08-08 发布日期:2026-02-03
  • 通信作者: 李贯峰,副教授,研究方向为知识图谱。E-mail:ligf@nxu.edu.cn E-mail:ligf@nxu.edu.cn
  • 基金资助:
    国家自然科学基金项目(No.62066038);宁夏自然科学基金项目(No.2024AAC03098);宁夏全职引进高层次人才科研启动项目(No.2023BSB03066)

Complex Logical Query Model Based on Improved Transformer

CHEN Yuyin1, LI Guanfeng1,2, QIN Jing1, XIAO Yuhang1   

  1. 1. School of Information Engineering, Ningxia University, Yinchuan 750021, Ningxia, China;
    2. Ningxia 'East Data West Computing' Key Laboratory of Artificial Intelligence and Information Security, Yinchuan 750021, Ningxia, China
  • Received:2025-08-08 Published:2026-02-03

摘要: 随着知识图谱在智能问答和推荐系统等场景中的广泛应用,回答不完整知识图谱上的复杂逻辑查询成为当前研究的重点与难点。针对基于普通嵌入的方法需要在复杂逻辑查询上进行训练,无法很好地泛化到分布外的查询结构的问题,提出了一种融合动态可组合的多头注意力(dynamically composable multi-head attention,DCMHA)机制与混合专家(mixture-of-experts,MoE)网络的Transformer改进模型DCMHA-MoE。该模型利用三元组变换与双向路径编码技术,将复杂查询图表示为序列输入,并动态建模其中的结构依赖与语义交互,从而实现复杂逻辑查询。DCMHA实现注意力头的自适应组合,增强语义表达能力;MoE网络引入稀疏激活机制,提高对不同查询结构的适应性并降低计算成本。在FB15K-237与NELL-995数据集上的实验结果表明,与基线模型DiffCLR相比,DCMHA-MoE模型在存在正一阶逻辑(existential positive first-order logic,EPFO)查询($\wedge$,$\vee$)中的平均倒数排名(mean reciprocal rank,MRR)平均指标分别提升了10.4%和7.2%,验证了其在复杂逻辑推理任务中的有效性和优越性。

关键词: 复杂逻辑查询, 知识图谱, Transformer, 动态多头注意力机制, 混合专家网络

Abstract: With the widespread application of knowledge graphs in scenarios such as intelligent question answering and recommendation systems, answering complex logical queries on incomplete knowledge graphs has become the focus and difficulty of current research. In view of the fact that ordinary embedding-based methods need to be trained on complex logical queries and cannot be well generalized to query structures outside the distribution, this paper proposed an improved-Transformer-based model DCMHA-MoE that integrated the dynamically composable multi-head attention (DCMHA) mechanism and the mixture-of-experts (MoE) network. This model represented complex query graphs as sequence inputs through triple transformation and bidirectional path encoding technology, and dynamically modeled the structural dependencies and semantic interactions therein, so that complex logical queries can be realized. The DCMHA realized the adaptive combination of attention heads to enhance the semantic expression ability. The MoE network introduced a sparse activation mechanism to improve the adaptability to different query structures and reduce the computational cost. Experiments were conducted on the FB15K-237 and NELL-995 datasets. The results show that compared with the baseline model DiffCLR, the DCMHA-MoE model improves the mean reciprocal rank (MRR) in existential positive first-order logic (EPFO) query $(\wedge, \vee)$ by 10.4% and 7.2%, respectively, which verifies the effectiveness and superiority of DCMHA-MoE in complex logical query tasks.

Key words: complex logical query, knowledge graph, Transformer, dynamic multi-head attention mechanism, mixture-of-experts network

中图分类号: