Please wait a minute...
浙江大学学报(工学版)  2027, Vol. 61 Issue (1): 154-164    DOI: 10.3785/j.issn.1008-973X.2027.01.015
计算机技术     
基于Transformer和胶囊网络的中文分词方法
刘一鸣1(),付静怡2,王芷婼2,张文芳2,*()
1. 西南交通大学 计算机与人工智能学院,四川 成都 611756
2. 西南交通大学 信息科学与技术学院,四川 成都 611756
Chinese word segmentation based on Transformer and CapsNet
Yiming Liu1(),Jingyi Fu2,Zhiruo Wang2,Wenfang Zhang2,*()
1. School of Computer and Artificial Intelligence, Southwest Jiaotong University, Chengdu 611756, China
2. School of Information Science and Technology, Southwest Jiaotong University, Chengdu 611756, China
 全文: PDF(1801 KB)   HTML
摘要:

针对中文分词任务中特定数据获取困难及效率提升的需求,构建小规模敏感词数据集,并提出创新的Transformer-CapsNet-CRF(TC-CRF)模型. 该模型融合了Transformer的全局特征提取能力、胶囊网络(CapsNet)的局部特征提取优势以及条件随机场(CRF)的序列优化预测能力. 在CTB6数据集上进行实验验证,结果表明,TC-CRF模型在结合BERT预训练的情况下,F1分数达到97.5%. 在小规模敏感词数据集上,TC-CRF模型在不使用任何预训练的情况下,F1分数达到86.9%,显示出卓越的分词效果,验证了其对有限数据的高效利用能力. 研究结果表明,该模型有效地结合了全局和局部特征提取的优势,为中文分词提供了新的解决方案. 本研究创新点在于将胶囊网络与Transformer相结合,并在中文分词中应用BERT预训练模块,上述方法的结合提高了模型的准确性和泛化能力.

关键词: 自然语言处理;  中文分词;  数据集构建;  Transformer;  胶囊网络(CapsNet)    
Abstract:

A small-scale sensitive-word dataset was constructed and an innovative Transformer-CapsNet-CRF (TC-CRF) model was proposed, aiming to address the difficulty of obtaining task-specific data and the demand for improved efficiency in Chinese word segmentation. The global feature extraction capability of Transformer, the local feature extraction advantage of Capsule Network (CapsNet), and the sequence optimization and prediction ability of Conditional Random Field (CRF) were integrated. Experiments were conducted on the CTB6 dataset. Results showed that the TC-CRF model achieved an F1 score of 97.5% when combined with BERT pre-training. On the small-scale sensitive-word dataset, the TC-CRF model achieved an F1 score of 86.9% without using any pre-trained model, demonstrating strong segmentation performance and verifying its ability to effectively utilize limited data. The experimental results indicated that the proposed model effectively combined the advantages of global and local feature extraction, providing a new solution for Chinese word segmentation. The main innovation of this study lay in combining Capsule Network with Transformer and applying the BERT pre-training module to Chinese word segmentation. The integration of these methods improved the accuracy and generalization ability of the model.

Key words: natural language processing    Chinese word segmentation    dataset construction    Transformer    Capsule Network (CapsNet)
收稿日期: 2025-04-11 出版日期: 2026-11-25
CLC:  TP 391  
基金资助: 四川省重点研发计划资助项目(2025YFHZ0161);中央高校基本科研业务费专项资金资助项目(202410613037).
通讯作者: 张文芳     E-mail: 2022112413@my.swjtu.edu.cn;wfzhang@swjtu.edu.cn
作者简介: 刘一鸣(2004—),男,硕士生,从事自然语言处理研究. orcid.org/0009-0004-9521-3224. E-mail:2022112413@my.swjtu.edu.cn
服务  
把本文推荐给朋友
加入引用管理器
E-mail Alert
作者相关文章  
刘一鸣
付静怡
王芷婼
张文芳

引用本文:

刘一鸣,付静怡,王芷婼,张文芳. 基于Transformer和胶囊网络的中文分词方法[J]. 浙江大学学报(工学版), 2027, 61(1): 154-164.

Yiming Liu,Jingyi Fu,Zhiruo Wang,Wenfang Zhang. Chinese word segmentation based on Transformer and CapsNet. Journal of ZheJiang University (Engineering Science), 2027, 61(1): 154-164.

链接本文:

https://www.zjujournals.com/eng/CN/10.3785/j.issn.1008-973X.2027.01.015    或    https://www.zjujournals.com/eng/CN/Y2027/V61/I1/154

图1  TC-CRF模型整体架构
图2  Transformer编码器模块结构
图3  胶囊局部特征建模流程
图4  敏感词数据集类别分布
图5  不同Dropout下CTB6验证集的效果
参数取值参数取值
Seq_len250input_caps_dim16
Dropout0.2input_caps8
Batch32output_caps_dim16
transformer_hidden_size256output_caps8
表1  实验超参数情况
图6  胶囊网络相关参数的调参情况
模型名称input_capsinput_caps_dimoutput_capsoutput_caps_dim
Group_A168168
Group_B8888
Group_C16161616
Group_D816816
表2  胶囊网络不同超参数组合的情况
模型名称F1分数/%
BERT+L-SAN-CRF97.30
BERT+BiLSTM-CRF97.25
BERT+TC-CRF97.52
表3  TC-CRF与基线模型在CTB6测试集上的F1值对比
模型名称para/106
L-SAN+CRF10.9
BiLSTM+CRF10.7
Transfomrer_CRF4.9
Capsule_CRF6.5
TC-CRF9.2
表4  模型参数量对比
模型名称v/(st·s?1)
训练集验证集测试集
Transformer_CRF217.20410.64475.36
TC-CRF260.33465.35388.09
BERT+Transformer_CRF96.69230.11190.61
BERT+TC-CRF92.82210.05169.24
表5  单张A100环境下不同分支模型速度的对比
模型名称F1分数/%
Transformer_CRF93.73
Capsule_CRF93.75
TC-CRF93.43
BERT+Transformer_CRF97.48
BERT+Capsule_CRF97.49
BERT+TC-CRF97.52
表6  不同模型组件组合在CTB6上的消融实验结果对比
图7  TC-CRF与Transformer-CRF在不同规模敏感词数据集上的性能对比
模型名称F1分数/%
PKUMSRCTB6
L-SAN+CRF+BERT96.598.497.3
BiLSTM+CRF+BERT96.398.497.3
AM-GSD[16]96.698.4?
WE-CONV-SEG[18]96.597.5?
BERT_NGRAM[33]97.196.0?
TENER+CLSEG(LS)[34]96.498.2?
ACNNC[35]96.296.4?
BERT+capsule+CRF96.798.497.5
BERT+TC-CRF96.798.497.5
表7  单张A100环境下不同中文分词模型的F1分数对比
图8  TC-CRF标签得分相似度热力图
图9  Transformer标签得分相似度热力图
1 Cai D, Zhao H, Zhang Z, et al. Fast and accurate neural word segmentation for Chinese [C]//Proceedings of the 55th Annual Meeting of the Association for Computational Linguistics. Vancouver: ACL, 2017: 608–615.
2 Du G. Research advanced in Chinese word segmentation methods and challenges. Applied and Computational Engineering, 2024, 37 (1): 16- 22.
doi: 10.54254/2755-2721/37/20230464
3 Sun W, Xu J. Enhancing Chinese word segmentation using unlabeled data [C]// Proceedings of the 2011 Conference on Empirical Methods in Natural Language Processing. Edinburgh: Association for Computational Linguistics, 2011: 970–979.
4 Xu J, Sun X. Dependency-based gated recursive neural network for Chinese word segmentation [C]// Proceedings of the 54th Annual Meeting of the Association for Computational Linguistics. Berlin: ACL, 2016: 567–572.
5 Zhang Y, Clark S. Chinese segmentation with a word-based perceptron algorithm [C]// Proceedings of the 45th Annual Meeting of the Association of Computational Linguistics. Prague: Association for Computational Linguistics, 2007: 840–847.
6 Zhang H P, Liu Q, Cheng X Q, et al. Chinese lexical analysis using hierarchical hidden Markov model [C]//Proceedings of the Second SIGHAN Workshop on Chinese Language Processing -. Sapporo. ACL, 2003: 63–70.
7 Lafferty J D, Mccallum A, Pereira F. Conditional random fields: probabilistic models for segmenting and labeling sequence data [C]// Proceedings of the Eighteenth International Conference on Machine Learning (IC ML '01). San Francisco: Morgan Kaufmann Publishers Inc. , 2001: 282–289.
8 Cai D, Zhao H. Neural word segmentation learning for Chinese [C]//Proceedings of the 54th Annual Meeting of the Association for Computational Linguistics. Berlin: ACL, 2016: 409–420.
9 Yang J, Zhang Y, Dong F. Neural word segmentation with rich pretraining [C]// Proceedings of the 55th Annual Meeting of the Association for Computational Linguistics. Vancouver: ACL, 2017: 839–849.
10 Zhang M, Zhang Y, Fu G. Transition-based neural word segmentation [C]// Proceedings of the 54th Annual Meeting of the Association for Computational Linguistics. Berlin: ACL, 2016: 421–431.
11 Zhou H, Yu Z, Zhang Y, et al. Word-context character embeddings for Chinese word segmentation [C]// Proceedings of the 2017 Conference on Empirical Methods in Natural Language Processing. Copenhagen: ACL, 2017: 760–766.
12 袁里驰. 基于BiLSTM-CRF的中文分词和词性标注联合方法. 中南大学学报(自然科学版), 2023, 54 (8): 3145- 3153.
Yuan Lichi. A joint method for Chinese word segmentation and part-of-speech tagging based on BiLSTM-CRF. Journal of Central South University (Science and Technology), 2023, 54 (8): 3145- 3153.
doi: 10.11817/j.issn.1672-7207.2023.08.018
13 程博, 李卫红, 童昊昕. 基于BiLSTM-CRF的中文层级地址分词. 地球信息科学学报, 2019, 21 (8): 1143- 1151.
Cheng Bo, Li Weihong, Tong Haoxin. Chinese address segmentation based on BiLSTM-CRF. Journal of Geo-Information Science, 2019, 21 (8): 1143- 1151.
14 Li X, Pu X. Semantic role labeling based on highway-BiLSTM-CRF model. International Journal of Computer Trends and Technology, 2021, 69 (10): 23- 27.
doi: 10.14445/22312803/ijctt-v69i10p103
15 Vaswani A, Shazeer N, Parmar N, et al. Attention Is All You Need [C]// Proceedings of the 31st Conference on Neural Information Processing Systems. Long Beach: Curran Associates Inc. , 2017: 6000–6010.
16 周保途. 句法依存引导的自注意力机制的中文分词. 计算机系统应用, 2023, 32 (9): 265- 271.
Zhou Baotu. Chinese Word Segmentation of Self-attention Mechanisms Guided by Syntactic Dependence. Computer Systems and Applications, 2023, 32 (9): 265- 271.
doi: 10.15888/j.cnki.csa.009221
17 Gan L, Zhang Y. Investigating self-attention network for Chinese word segmentation [C]// Proceedings of the IEEE/ACM Transactions on Audio, Speech, and Language Processing. [S. l. ]: IEEE, 2020: 2933–2941.
18 Wang C, Xu B. Convolutional neural network with word embeddings for Chinese word segmentation [C]// Proceedings of the Eighth International Joint Conference on Natural Language Processing (Volume 1: Long Papers). Taipei: Asian Federation of Natural Language Processing, 2017: 163–172.
19 Wei H, Guo X. BWSC: BERT-based N-gram enhanced word segmentation for Chinese [C]// 6th International Conference on Frontier Technologies of Information and Computer. Qingdao: IEEE, 2024: 496–502.
20 Sabour S, Frosst N, Hinton G E. Dynamic routing between capsules [C]// Proceedings of the 31st International Conference on Neural Information Processing Systems. Long Beach: Curran Associates Inc. , 2017: 3859–3869.
21 荆沁璐, 冯林, 王旭, 等. 改进路由机制的元学习少样本研究本分类模型. 小型微型计算机系统, 2023, 44 (11): 2392- 2400.
Jing Qinlu, Feng Lin, Wang Xu, et al. Few-shot text classification model based on meta-learning with improved routing mechanisms. Journal of Chinese Computer Systems, 2023, 44 (11): 2392- 2400.
doi: 10.20009/j.cnki.21-1106/TP.2022-0286
22 陈珊, 孙仁诚, 邵峰晶, 等. 基于胶囊网络的动态路由研究与改进. 计算机工程, 2022, 48 (5): 208- 214.
Chen Shan, Sun Rencheng, Shao Fengjing, et al. Research and improvement of dynamic routing based on capsule network. Computer Engineering, 2022, 48 (5): 208- 214.
doi: 10.19678/j.issn.1000-3428.0062928
23 麦范金, 王挺. 基于双向最大匹配和HMM的分词消歧模型. 数据分析与知识发现, 2008, 24 (8): 37- 41.
Mai Fanjin, Wang Ting. Sense disambiguation of Chinese segmentation based on bi-direction matching method and HMM. Data Analysis and Knowledge Discovery, 2008, 24 (8): 37- 41.
24 黄昌宁, 赵海. 中文分词十年回顾. 中文信息学报, 2007, 21 (3): 8- 19.
Huang Changning, Zhao Hai. Chinese word segmentation: a decade review. Journal of Chinese Information Processing, 2007, 21 (3): 8- 19.
doi: 10.3969/j.issn.1003-0077.2007.03.002
25 涂文博, 袁贞明, 俞凯. 无池化层卷积神经网络的中文分词方法. 计算机工程与应用, 2020, 56 (2): 120- 126.
Tu Wenbo, Yuan Zhenming, Yu Kai. Convolutional neural networks without pooling layer for Chinese word segmentation. Computer Engineering and Applications, 2020, 56 (2): 120- 126.
doi: 10.3778/j.issn.1002-8331.1809-0177
26 Chen X, Qiu X, Zhu C, et al. Gated recursive neural network for Chinese word segmentation [C]// Proceedings of the 53rd Annual Meeting of the Association for Computational Linguistics and the 7th International Joint Conference on Natural Language Processing. Beijing: ACL, 2015: 1744–1753.
27 Chen X, Qiu X, Zhu C, et al. Long short-term memory neural networks for Chinese word segmentation [C]// Proceedings of the 2015 Conference on Empirical Methods in Natural Language Processing. Lisbon: ACL, 2015: 1197–1206.
28 任智慧, 徐浩煜, 封松林, 等. 基于LSTM网络的序列标注中文分词法. 计算机应用研究, 2017, 34 (5): 1321- 1324,1341.
Ren Zhihui, Xu Haoyu, Feng Songlin, et al. Sequence labeling Chinese word segmentation method based on LSTM networks. Application Research of Computers, 2017, 34 (5): 1321- 1324,1341.
doi: 10.3969/j.issn.1001-3695.2017.05.009
29 Jin Y, Tao S, Liu Q, et al. A BiLSTM-CRF based approach to word segmentation in Chinese [C]// 2022 IEEE International Conference on Dependable, Autonomic and Secure Computing, IEEE International Conference on Pervasive Intelligence and Computing, IEEE International Conference on Cloud and Big Data Computing, IEEE International Conference on Cyber Science and Technology Congress (DASC/PiCom/CBDCom/CyberSciTech). Falerna: IEEE, 2022: 1–4.
30 贾旭东, 王莉. 基于多头注意力胶囊网络的文本分类模型. 清华大学学报 (自然科学版), 2020, 60 (5): 415- 421.
Jia Xudong, Wang Li. Text classification model based on multi-head attention capsule neworks. Journal of Tsinghua University (Science and Technology), 2020, 60 (5): 415- 421.
doi: 10.16511/j.cnki.qhdxxb.2020.26.006
31 Emerson T. The second international Chinese word segmentation bakeoff [C]// Proceedings of the 4th SIGHAN Workshop on Chinese Language Processing. Jeju Island: Association for Computational Linguistics, 2005.
32 Palmer M, Xue N, Xia F, et al. Chinese treebank 6.0 (Version 1.0) [DS/OL]. [2025−02−01]. https://catalog.ldc.upenn.edu/LDC2007T36.
33 陆斯悦, 张禄, 李香龙, 等. 基于BERT的电力领域无监督分词方法. 信息技术, 2024 (1): 96- 103.
Lu Siyue, Zhang Lu, Li Xianglong, et al. Unsupervised word segmentation method in power domain based on BERT. Information Technology, 2024 (1): 96- 103.
doi: 10.13274/j.cnki.hdzj.2024.01.015
34 Xu Z, Xiang Y. Improving Chinese word segmentation with character–lexicon class attention. Neural Computing and Applications, 2025, 37 (5): 3857- 3867.
doi: 10.1007/s00521-024-10693-2
35 张忠林, 余炜, 闫光辉, 等. 基于ACNNC模型的中文分词方法. 中文信息学报, 2022, 36 (8): 12- 19,28.
Zhang Zhonglin, Yu Wei, Yan Guanghui, et al. Chinese word segmentation based on ACNNC model. Journal of Chinese Information Processing, 2022, 36 (8): 12- 19,28.
doi: 10.3969/j.issn.1003-0077.2022.08.002
[1] 万伟国,钟凯晨,张迎梅,姚丽,包书鸿,龚大伟. 基于空间自适应Transformer的人脸素描图像生成[J]. 浙江大学学报(工学版), 2026, 60(9): 1953-1961.
[2] 高帅帅,魏诚,惠飞,张竟成,宋汉辰. 基于时空特征与交互关系建模的换道意图预测[J]. 浙江大学学报(工学版), 2026, 60(9): 2031-2041.
[3] 徐恺蔚,KHIZER BIN TALIBHafiz,曹衍龙,许源平,许志杰,宋景春. 基于光流和卷积视觉Transformer的轻量级微表情识别[J]. 浙江大学学报(工学版), 2026, 60(7): 1381-1391.
[4] 梁礼明,王成斌,钟奕,陈林俊,吴健. 基于轻量高频Transformer与特征互补融合的视网膜血管分割[J]. 浙江大学学报(工学版), 2026, 60(7): 1392-1403.
[5] 董绍江,肖涛,吕振鸣,夏浩然,罗家元,孙世政,张霞,刘超. 基于改进RT-DETR的水下色偏环境中小型生物检测[J]. 浙江大学学报(工学版), 2026, 60(7): 1404-1415.
[6] 杨艳春,李佳龙. 基于多路协同与空谱先验的高光谱与多光谱图像融合[J]. 浙江大学学报(工学版), 2026, 60(7): 1427-1437.
[7] 郑文军,黎志昆,韩守飞. 知识增强图Transformer的方面级情感分析[J]. 浙江大学学报(工学版), 2026, 60(6): 1269-1276.
[8] 边文远,火久元,常琛. 基于改进的插补扩散模型与LSTM的风电数据清洗方法[J]. 浙江大学学报(工学版), 2026, 60(5): 1016-1026.
[9] 彭静,闫佳荣,刘佳英,魏子易,白珊,邓亚红. 多尺度残差学习结合Dilformer的双流医学图像配准网络[J]. 浙江大学学报(工学版), 2026, 60(5): 1082-1091.
[10] 侯玉珍,沈晓红,李莉,杨明源,张彩明. 基于掩模和非局部注意力的双阶段去雨网络[J]. 浙江大学学报(工学版), 2026, 60(4): 791-799.
[11] 万刚,王小波,石纲,叶德震,朱思思,司帆. 基于特征细化与注意力增强重构的水下图像增强算法[J]. 浙江大学学报(工学版), 2026, 60(4): 800-811.
[12] 李延松,陈宁,刘锋光,陈盼,黄晓峰,葛慧丽. 基于分阶段语义感知的事件抽取大语言模型框架[J]. 浙江大学学报(工学版), 2026, 60(3): 527-535.
[13] 彭艺,李恒,杨青青,李辉,王健明. 基于CSI导向注意力与门控生成修复的图像语义通信[J]. 浙江大学学报(工学版), 2026, 60(12): 2694-2703.
[14] 彭艺,李恒,杨青青,李辉,王健明. 基于Swin Transformer的图像多级语义MIMO传输[J]. 浙江大学学报(工学版), 2026, 60(11): 2462-2471.
[15] 包晓安,彭书友,张娜,涂小妹,张庆琪,吴彪. 基于多方位感知深度融合检测头的目标检测算法[J]. 浙江大学学报(工学版), 2026, 60(1): 32-42.