自然語言處理中常見的10個任務簡介及其資源

編程語言 機器學習 Word Python 數據學習DataLearner 數據學習DataLearner 2017-11-05

本篇博客來自與Analytics Vidhya的一篇文章的翻譯。文中主要說明了自然語言處理中十種常見的任務,並提供了實現方法和一些共參考的論文、數據集等資源。做自然語言處理不可或缺。

頭條無法放鏈接,但是這篇文章包含了大量的外鏈,可以去://www.datalearner.com/blog/1051509699533080 查看。

簡介

現在很多公司和組織每天都要處理大量的文本信息,包括郵件、評論、客戶的電話等。將這些數據變成有用的信息需要花費大量的時間。抽取這些信息的一個核心的技能就是自然語言處理(Natural Language Processing,NLP)。

自然語言處理在現階段變得越來越重要,不管你是做什麼的,這篇博客都能給你一點幫助。

自然語言處理中常見的10個任務簡介及其資源

為何寫這篇博客?

作者已經在NLP領域做過一段時間工作了。作者遇到過很多種情況,需要從各種資料如最新的論文、博客以及一些自然語言處理的任務中獲得幫助。因此,作者希望將這些資源都寫到一起來提供一站式的幫助。下面就是自然語言處理有關的一些資源。

一、詞幹抽取(Stemming)

詞幹抽取是去除詞語的形態等,將詞語變成它的詞幹形式的過程。它的目的是將不同形式的相同含義的詞語統一起來(數據學習網站提醒一下:中文中一般沒有詞幹抽取的工作,但是多了個分詞,這是中英文文本處理的不同)。例如,有下面兩個例子:

1. beautiful and beautifully are stemmed to beauti

2. good, better and best are stemmed to good, better and best respectively

這是來自於論文的例子,原文:https://tartarus.org/martin/PorterStemmer/def.txt

使用Python處理詞幹抽取:https://bitbucket.org/mchaput/stemming/src/5c242aa592a6d4f0e9a0b2e1afdca4fd757b8e8a/stemming/porter2.py?at=default&fileviewer=file-view-default

比如,我們可以用Porter2算法來實現詞幹抽取:

1. #!pip install stemming

2. from stemming.porter2 import stem

3. stem("casually")

二、詞形還原(Lemmatisation)

詞形還原是指將一組詞語變成他們詞幹的形式的過程。例如在會話識別任務中,我們需要考慮這個單詞在句子中的含義,也要考慮這個單詞在相鄰句子中的含義。例如,:

1. beautiful and beautifully are lemmatised to beautiful and beautifully respectively.

2. good, better and best are lemmatised to good, good and good respectively.

有兩篇論文討論了詞形還原:

論文1: //www.ijrat.org/downloads/icatest2015/ICATEST-2015127.pdf

論文2: https://academic.oup.com/dsh/article-abstract/doi/10.1093/llc/fqw034/2669790/Lemmatization-for-variation-rich-languages-using

數據集:https://catalog.ldc.upenn.edu/ldc99t42

在Python中可以使用Spacy來做詞形還原:

1. #!pip install spacy

2. #python -m spacy download en

3. import spacy

4. nlp=spacy.load("en")

5. doc="good better best"

6.

7. for token in nlp(doc):

8. print(token,token.lemma_)

三、詞嵌套(Word Embeddings)

詞嵌套是一種技術,它可以將自然語言變成實值向量的形式。由於計算機無法直接處理文本,所以這種轉換很有用。這類技術使用實值向量來表示自然語言中詞語的位置和相互關係(數據學習網站提醒一下:詞嵌套最有名的論文應當屬於word2vec這篇論文,它並沒有說提供了新方法,但是提供了一種新工具,可以很方便的從文本中獲取詞向量的結果。這也是谷歌提出來的,谷歌真是個不錯的公司)。例如,我們可以用100維向量表示詞語或者短語。

例如,用5-維的向量表示"男人"這個詞語:

自然語言處理中常見的10個任務簡介及其資源

這裡的每個數字都是在特定方向上的大小。

自然語言處理中常見的10個任務簡介及其資源

https://www.analyticsvidhya.com/blog/2017/06/word-embeddings-count-word2veec/ 詳細介紹了詞嵌套模型。

https://arxiv.org/pdf/1411.2738.pdf 詳細介紹了詞向量,對於深入理解詞嵌套模型必看。

https://ronxin.github.io/wevi/ 是一個基於瀏覽器的對詞向量進行可視化展示的。

https://github.com/facebookresearch/fastText/blob/master/pretrained-vectors.md 是一個對294種語言的詞向量的訓練結果。

實現方式:我們可以使用Python中gensim工具來訓練。下載使用谷歌新聞訓練好的詞向量:

1. #!pip install gensim

2. from gensim.models.keyedvectors import KeyedVectors

3. word_vectors=KeyedVectors.load_word2vec_format('GoogleNews-vectors-negative300.bin',binary=True)

4. word_vectors['human']

用自己的數據集訓練詞向量:

1. sentence=[['first','sentence'],['second','sentence']]

2. model = gensim.models.Word2Vec(sentence, min_count=1,size=300,workers=4)

四、詞性標註(Part-Of-Speech Tagging)

詞性標註就是將句子中的單詞標註成"名詞"、"動詞"等(數據學習網站提醒一下:中文的詞性標註工具可以使用結巴分詞或者是張華平分詞,都是帶有詞性標註的功能)。例如,句子:

"Ashok killed the snake with a stick"

詞性標註的結果是:

Ashok 代詞killed 動詞the DETsnake 名詞with 連詞a DETstick 名詞. 標點符號

https://aclweb.org/anthology/N16-1031.pdf 使用了Dynamic Feature Induction來得到高精度的詞性標註結果。

https://transacl.org/ojs/index.php/tacl/article/viewFile/837/192 使用Anchor Hidden Markove模型來訓練無監督的詞性標註結果。

實現:我們可以使用spacy來實現詞性標註:

1. #!pip install spacy

2. #!python -m spacy download en

3. nlp=spacy.load('en')

4. sentence="Ashok killed the snake with a stick"

5. for token in nlp(sentence):

6. print(token,token.pos_)

五、命名實體消歧(Named Entity Disambiguation)

命名實體消岐是值識別句子中的實體的過程。例如,句子:"Apple earned a revenue of 200 Billion USD in 2016"命名實體消歧的目標是認出Apple是一個公司名字而不是水果名。命名實體一般需要一個實體庫,它可以將句子中的實體鏈接到實體庫中。

https://arxiv.org/pdf/1504.07678.pdf 使用了基於深度神經網絡的Deep Semantic Relatedness技術來進行命名實體消歧。效果不錯。它使用了知識庫。

https://arxiv.org/pdf/1704.04920.pdf 則利用了詞向量模型,使用 Local Neural Attention 來進行命名實體消歧。

六、命名實體識別(Named Entity Recognition)

命名實體識別是要識別出句子中的實體,並將實體劃分到某個類別中,例如人、組織、日期等。例如,句子:

"Ram of Apple Inc. travelled to Sydney on 5th October 2017"

返回的結果是:

RamofApple ORGInc. ORGtravelledtoSydney GPEon5th DATEOctober DATE2017 DATE2017 DATE

ORG表示組織,GPE表示地點。目前命名實體識別最大的問題是,當數據變了,即使是最好的NER技術也會表現不好。

自然語言處理中常見的10個任務簡介及其資源

https://arxiv.org/pdf/1603.01360.pdf 使用了二向LSTM模型,在4種語言上,聯合了有監督、無監督的模型實現了比較好的命名實體識別的效果。我們可以使用Spacy來實現這個技術:

1. import spacy

2. nlp=spacy.load('en')sentence="Ram of Apple Inc. travelled to Sydney on 5th October 2017"

3. for token in nlp(sentence):

4. print(token, token.ent_type_)

七、情感分析

情感分析的任務涉及的主題較多,一般是利用自然語言處理技術識別如客戶評論中正向或者負向的情感等,或者是通過語音分析、寫作分析得到情緒判別結果。例如:

1. "I did not like the chocolate ice-cream" – 對冰激淋做負向的評價

2. "I did not hate the chocolate ice-cream" – 可能是一箇中立的評價

情感分析的方法很多,開始的時候可以用LSTM模型與詞向量模型一起,數一數句子中正負向情感詞的個數得到。資源有:

博客 1: 電影推文的情感分析

博客 2: Chennai 洪水的情感分析

論文 1: 使用樸素貝葉斯方法對IMDB評論的情感分類.

論文 2: 使用LDA獲得用戶文本的主題,然後基於無監督的方法識別情感.

Repository: 這裡總結了大量的關於不同語言的情感處理的論文和實現方法.

Dataset 1: Multi-Domain sentiment dataset version 2.0

Dataset 2: Twitter Sentiment analysis Dataset

Competition: A very good competition where you can check the performance of your models on the sentiment analysis task of movie reviews of rotten tomatoes.

八、文本語義相似性(Semantic Text Similarity)

計算文本語義相似性就是計算兩段文本之間含義相似性的任務。

論文 1:詳細說明了多種計算文本相似性的方法,必讀

論文 2:介紹如何使用CNN獲得短文本之間相似性

論文 3:使用基於樹的LSTM方法獲取語義分類

九、語言識別

就是識別出文本是什麼語言寫的,是文本分類的一種特殊情況。

博客:給了一個新工具,可以識別170多種語言

論文1:討論了7種方法,識別285種語言

論文2:討論瞭如何使用深度神經網絡獲得語言識別結果

十、文本摘要(Text Summarisation)

文本摘要是通過識別文本重要的內容將一段文本縮減,並變成對這些點的總結。文本摘要的目標是最大限度保留原始文本的含義。

論文1:使用 Neural Attention Model 獲取文本摘要

論文2:使用sequence-to-sequence的RNN獲取摘要

Repository:谷歌大腦團隊提供的可以自動文本摘要的代碼,基於Gigaword數據集訓練

應用:Reddit’s autotldr bot 使用文本摘要將帖子的評論總結成短文,這個特性在Reddit用戶中很有名

我們可以使用gensim來獲取文本摘要:

1. from gensim.summarization import summarize

2.

3. sentence="Automatic summarization is the process of shortening a text document with software, in order to create a summary with the major points of the original document. Technologies that can make a coherent summary take into account variables such as length, writing style and syntax.Automatic data summarization is part of machine learning and data mining. The main idea of summarization is to find a subset of data which contains the information of the entire set. Such techniques are widely used in industry today. Search engines are an example; others include summarization of documents, image collections and videos. Document summarization tries to create a representative summary or abstract of the entire document, by finding the most informative sentences, while in image summarization the system finds the most representative and important (i.e. salient) images. For surveillance videos, one might want to extract the important events from the uneventful context.There are two general approaches to automatic summarization: extraction and abstraction. Extractive methods work by selecting a subset of existing words, phrases, or sentences in the original text to form the summary. In contrast, abstractive methods build an internal semantic representation and then use natural language generation techniques to create a summary that is closer to what a human might express. Such a summary might include verbal innovations. Research to date has focused primarily on extractive methods, which are appropriate for image collection summarization and video summarization."

4.

5. summarize(sentence)

相關推薦

推薦中...