背景現(xiàn)有種類繁多的自然語言處理(NLP)工具包,例如CoreNLP [1],UDPipe [2],F(xiàn)LAIR [3],spaCy 和Stanza [4]的英文版,這使用戶可以更輕松地構(gòu)建具有復(fù)雜語言處理能力的工具。最近,在許多下游應(yīng)用中對中文NLP的需求急劇增加。中文NLP平臺通常包括詞法分析(中文分詞(CWS),詞性(POS)標(biāo)記和命名實體識別(NER)),語法分析(依賴項解析(DEP))和語義分析(語義依賴解析(SDP)和語義角色標(biāo)記(SRL))。不過用于中文NLP任務(wù)的高性能和高效率工具包相對較少。 介紹基于以上背景,我們搭建了N-LTP,這是一個基于PyTorch的中文自然語言處理的神經(jīng)自然語言處理工具包,它是基于SOTA預(yù)訓(xùn)練模型構(gòu)建的。 圖1 N-LTP模型概覽 與現(xiàn)有的廣泛使用的NLP工具包相比,N-LTP具有以下優(yōu)點:
使用方法安裝方法$ pip install ltp 快速使用Python
其他語言綁定等// RUST 語言 多任務(wù)模型共享編碼器為了提取所有中文相關(guān)任務(wù)的共享知識,我們采用了多任務(wù)框架,其中六個中文任務(wù)共享一個編碼器。在我們的框架中,我們采用SOTA預(yù)訓(xùn)練模型(ELECTRA [5])作為編碼器。 給定輸入序列 = (),我們首先通過添加特定標(biāo)記 = ()構(gòu)造輸入序列),其中是表示整個序列的特殊符號,是用于分隔非連續(xù)令牌序列的特殊符號(Devlin et al。,2019)。ELECTRA接受構(gòu)造的輸入,并輸出序列 = (, , )的相應(yīng)隱藏表示。 分詞中文分詞(CWS)是中文自然語言處理(NLP)的首要任務(wù)。在N-LTP中,CWS被視為基于字符的序列標(biāo)記問題。具體來說,給定隱層的表示形式 = (, , ),我們采用線性解碼器對每個字符進行分類: 詞性標(biāo)注詞性(POS)標(biāo)記是另一個基本的NLP任務(wù),它可以簡化諸如語法分析之類的下游任務(wù)。和分詞任務(wù)一樣,我們這里也是使用一個簡單地MLP來對每個詞語進行分類。 命名實體識別命名實體識別(NER)是一項常見的自然語言處理任務(wù),目的是在一個句子中查找一個實體(人員,位置,組織等)的起點和終點,并為此實體分配一個類別。 這里我們使用了 Adapted-Transformer[6] 來獲取方向和距離敏感的詞語表示,然后使用線性分類器對其進行分類: 其中 表示每個字符的NER標(biāo)簽概率分布。 依存句法分析依存關(guān)系分析是分析句子的語義結(jié)構(gòu)的任務(wù)。在N-LTP中,我們使用 deep biaffine parser [10](Dozat and Manning,2017)和einser算法 [7](Eisner,1996)以獲取解析結(jié)果,其公式為: 語義依存分析與依存關(guān)系分析相似,語義依存分析[11]是捕獲句子語義結(jié)構(gòu)的任務(wù)。具體來說,給定一個輸入語句,SDP的目的是確定所有彼此語義相關(guān)的詞對,并分配特定的預(yù)定義語義關(guān)系。 這里我們?nèi)匀皇褂?Biaffine 模型來對結(jié)果進行預(yù)測,不過之后我們使用 如果 我們則認為從 到 存在一個邊。 語義角色標(biāo)注語義角色標(biāo)記(SRL)是確定句子的潛在謂語-參數(shù)結(jié)構(gòu)的任務(wù),它可以提供表示形式來回答有關(guān)句子含義的基本問題,包括誰對誰做了什么等。 這里我們使用 Biaffine 和 CRF 的解碼器相結(jié)合的方法構(gòu)建了一個端到端的 SRL 模型。 <section role="presentation" data-formula="P(\hat{{y}}| s)=\frac{\sum_{j=1}\exp f(y_{i,j-1},y_{i,j},s)}{\sum_{y_{i}" }\sum_{j="1}\exp" f(y_{i,j-1}',y_{i,j}',s)}="" '="" data-formula-type="block-equation">其中 表示謂詞為 時的任意標(biāo)簽序列,而 表示從 到 對于 的分數(shù)。 實驗結(jié)果主實驗表1 LTP 和 Stanza 在 LTP 數(shù)據(jù)集上的結(jié)果。 表2展示了LTP 和 Stanza 在 UD 和 Ontonotes 上的結(jié)果,這里報的是Stanza的官方結(jié)果,指標(biāo)采用Stanza提供的評測腳本計算得出。表2 LTP 和 Stanza 在 UD 和 Ontonotes 上的結(jié)果表3 LTP模型與不同任務(wù)上的SOTA預(yù)訓(xùn)練模型進行比較 速度總結(jié)我們介紹了N-LTP,一個面向中文自然語言處理的工具包。我們在6個基本的中文NLP任務(wù)對N-LTP進行了評估,并獲得了最先進的或具有競爭力的性能,希望它能夠促進中文NLP的研究和應(yīng)用。將來,我們將通過添加新的模型或者任務(wù)來繼續(xù)擴展N-LTP。 參考文獻[1]. Christopher Manning, Mihai Surdeanu, John Bauer, Jenny Finkel, Steven Bethard, and David McClosky. 2014. The Stanford CoreNLP natural language pro- cessing toolkit. In Proceedings of 52nd Annual Meeting of the Association for Computational Lin- guistics: System Demonstrations, pages 55–60, Bal- timore, Maryland. Association for Computational Linguistics. [2]. Straka, Milan, and Jana Straková. 2017. Tokenizing, POS tagging, lemmatizing and parsing UD 2.0 with UDPipe. In Proceedings of the CoNLL 2017 Shared Task: Multilingual Parsing from Raw Text to Univer- sal Dependencies, pages 88–99, Vancouver, Canada. Association for Computational Linguistics. [3]. Alan Akbik, Tanja Bergmann, Duncan Blythe, Kashif Rasul, Stefan Schweter, and Roland Vollgraf. 2019. FLAIR: An easy-to-use framework for state-of-the- art NLP. In Proceedings of the 2019 Confer- ence of the North American Chapter of the Asso- ciation for Computational Linguistics (Demonstra- tions), pages 54–59, Minneapolis, Minnesota. Asso- ciation for Computational Linguistics. [4]. Peng Qi, Yuhao Zhang, Yuhui Zhang, Jason Bolton, and Christopher D. Manning. 2020. Stanza: A python natural language processing toolkit for many human languages. In Proceedings of the 58th An- nual Meeting of the Association for Computational Linguistics: System Demonstrations, pages 101– 108, Online. Association for Computational Linguistics. [5]. Kevin Clark, Minh-Thang Luong, Quoc V. Le, and Christopher D. Manning. 2020. ELECTRA: pre-training text encoders as discriminators rather than generators. In 8th International Confer- ence on Learning Representations, ICLR 2020, Ad- dis Ababa, Ethiopia, April 26-30, 2020. OpenRe- view.net. [6]. Hang Yan, Bocao Deng, Xiaonan Li, and Xipeng Qiu. 2019a. Tener: Adapting transformer encoder for named entity recognition. [7]. Jason M. Eisner. 1996. Three new probabilistic models for dependency parsing: An exploration. In COL- ING 1996 Volume 1: The 16th International Confer- ence on Computational Linguistics. [8]. Kevin Clark, Minh-Thang Luong, Urvashi Khandel- wal, Christopher D. Manning, and Quoc V. Le. 2019. BAM! born-again multi-task networks for natural language understanding. In Proceedings of the 57th Annual Meeting of the Association for Computa- tional Linguistics, pages 5931–5937, Florence, Italy. Association for Computational Linguistics. [9]. Thomas Wolf, Lysandre Debut, Victor Sanh, Julien Chaumond, Clement Delangue, Anthony Moi, Pier- ric Cistac, Tim Rault, Re ?mi Louf, Morgan Funtow- icz, Joe Davison, Sam Shleifer, Patrick von Platen, Clara Ma, Yacine Jernite, Julien Plu, Canwen Xu, Teven Le Scao, Sylvain Gugger, Mariama Drame, Quentin Lhoest, and Alexander M. Rush. 2019. Huggingface’s transformers: State-of-the-art natural language processing. ArXiv, abs/1910.03771. [10]. Timothy Dozat and Christopher D. Manning. 2017. Deep biaffine attention for neural dependency pars- ing. In 5th International Conference on Learning Representations, ICLR 2017, Toulon, France, April 24-26, 2017, Conference Track Proceedings. Open- Review.net. [11]. Wanxiang Che, Meishan Zhang, Yanqiu Shao, and Ting Liu. 2012. SemEval-2012 task 5: Chinese semantic dependency parsing. In **SEM 2012: The First Joint Conference on Lexical and Computational Seman- tics – Volume 1: Proceedings of the main conference and the shared task, and Volume 2: Proceedings of the Sixth International Workshop on Semantic Eval- uation (SemEval 2012)*, pages 378–384, Montre ?al, Canada. Association for Computational Linguistics. |
|