TextCNN — Convolutional Neural Networks for Sentence Classification
選讀・NLP 03・自然語言處理的類神經網路 的論文導讀(第 1/1 篇)。引用編號對應本頁底部的參考文獻。
導覽:本頁與本系列: 導覽:本頁與本系列
挑戰
句子分類器能否不靠完整句法剖析或循環網路,就學到有用的片語偵測器?Kim 在 EMNLP 2014 的論文主張:用預訓練詞向量初始化後,小型卷積模型就能成為很強的基準 [10]。先理解本章的嵌入、卷積與分類損失。重點是分清楚「學習局部特徵」及「選出對整句重要的局部特徵」。
方法

把詞向量堆成句子矩陣。一個濾波器涵蓋連續數個詞及其全部嵌入維度,滑過句子產生特徵圖,再保留最大反應:
串接從位置 開始的 個詞向量; 是對應濾波器向量, 是純量偏差, 是非線性活化函數。純量 是一個視窗的反應, 則是該濾波器的整句池化特徵。串接多個濾波器的池化結果,訓練時使用 dropout,再以 softmax 層預測類別。
寬度為三的濾波器可以在不同位置偵測同一局部模式。最大池化留下最強證據,卻不留下位置或出現次數。雙通道模型固定一份嵌入表、微調另一份;各濾波器作用於兩個通道並相加其反應。預訓練向量帶入外部文字的資訊,因此不是只從小型分類資料集學到所有知識。
結果
表 2 的 MR 準確率為:隨機初始化 CNN-rand 76.1、預訓練 CNN-static 81.0、CNN-non-static 81.5。這支持預訓練與任務調整在此設定的價值,不能解讀為提升完全來自卷積。各資料集的評估流程不同,有固定測試切分,也有交叉驗證;應先比較同一資料集內的模型,再考慮跨任務分數。
消融與設計證據
static、non-static 與 multichannel 比較的是如何調整嵌入。multichannel 把 SST-2 準確率從 non-static 的 87.2 提升至 88.1,卻把 TREC 從 93.6 降至 92.2。因此,多一個通道不是保證升級。論文在同一資料集內固定摺疊切分及相關隨機初始化,以提升比較的意義。重現時仍須留意濾波器寬度與正則化設定。
結論
這適合作為第一個神經文字分類器,因為資訊流清楚:詞向量 → 局部反應 → 池化證據 → 類別。試著解釋哪個三詞視窗觸發了濾波器,再問同一片語出現兩次會有何不同。接著讀 NLP 04,理解預訓練詞向量的來源。
問題與限制
濾波器視窗內仍保有局部詞序,但最大池化會丟掉許多全句結構。遠距離否定、多個互相影響的子句,或重複證據的次數,都可能難以表示。高反應只是模型反應,不等於標籤的因果解釋。將提升歸因於架構前,應與簡單非神經基準比較,並控制外部訓練資料。
參考文獻
- M. Hagiwara, Real-World Natural Language Processing: Practical Applications with Deep Learning, Manning, 2021; Chapters 2–4, 7 and 10–11. publisher
- S. McRoy, Principles of Natural Language Processing, open textbook, 2021; Chapter 6, “Benchmark Tasks for Language Modelling.” chapter
- Scikit-learn developers, “Text feature extraction,” scikit-learn documentation, current online edition. documentation
- Scikit-learn developers, “Logistic regression,” scikit-learn documentation, current online edition. documentation
- Y. Goldberg, “A primer on neural network models for natural language processing,” Journal of Artificial Intelligence Research 57, 2016. paper
- M. Iyyer, V. Manjunatha, J. Boyd-Graber and H. Daumé III, “Deep unordered composition rivals syntactic methods for text classification,” ACL-IJCNLP, 2015. paper
- A. Joulin, E. Grave, P. Bojanowski and T. Mikolov, “Bag of tricks for efficient text classification,” EACL, 2017. paper
- Y. Bengio, R. Ducharme, P. Vincent and C. Jauvin, “A neural probabilistic language model,” Journal of Machine Learning Research 3, 2003. paper
- R. Collobert, J. Weston, L. Bottou, M. Karlen, K. Kavukcuoglu and P. Kuksa, “Natural language processing (almost) from scratch,” Journal of Machine Learning Research 12, 2011. paper
- Y. Kim, “Convolutional neural networks for sentence classification,” EMNLP, 2014. paper
- Y. Zhang and B. Wallace, “A sensitivity analysis of (and practitioners’ guide to) convolutional neural networks for sentence classification,” IJCNLP, 2017. paper
- N. Srivastava, G. Hinton, A. Krizhevsky, I. Sutskever and R. Salakhutdinov, “Dropout: a simple way to prevent neural networks from overfitting,” Journal of Machine Learning Research 15, 2014. paper
- Scikit-learn developers, “Classification metrics,” scikit-learn documentation, current online edition. documentation
- C. Guo, G. Pleiss, Y. Sun and K. Q. Weinberger, “On calibration of modern neural networks,” ICML, 2017. paper
- S. Minaee, N. Kalchbrenner, E. Cambria, N. Nikzad, M. Chenaghlu and J. Gao, “Deep learning-based text classification: a comprehensive review,” ACM Computing Surveys 54(3), 2021. survey
- W. X. Zhao et al., “A survey of large language models,” Frontiers of Computer Science, 2026; online manuscript updated March 2026. survey
- Y. Chang et al., “A survey on evaluation of large language models,” ACM Transactions on Intelligent Systems and Technology, 2024. survey
- G. Sperduti and A. Moreo, “Misspellings in natural language processing: a survey,” arXiv:2501.16836, 2025. survey