NLP之BoWNLTK:自然语言处理中常用的技术——词袋法Bow、NLTK库
生活随笔
收集整理的這篇文章主要介紹了
NLP之BoWNLTK:自然语言处理中常用的技术——词袋法Bow、NLTK库
小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
NLP之BoW&NLTK:自然語(yǔ)言處理中常用的技術(shù)——詞袋法Bow、NLTK庫(kù)
?
?
目錄
輸出結(jié)果
實(shí)現(xiàn)代碼
?
?
輸出結(jié)果
[[0 1 1 0 1 0 0 0 1 1 1 1 1 1 1 1 1 0 0 1 0 0 1 0 0][1 0 0 1 1 1 1 1 0 0 0 0 0 0 0 0 0 1 1 0 1 1 1 1 1]]BoW:輸出句子中的每個(gè)單詞(包括符號(hào))—按照順序: ['by', 'career', 'combined', 'congress', 'for', 'government', 'huawei', 'imposed', 'in', 'james', 'jordan', 'lebron', 'michael', 'passed', 'playoffs', 'points', 'regular', 'restrictions', 'sales', 'season', 'sues', 'the', 'today', 'unconstitutional', 'us']NLTK:輸出句子中的每個(gè)單詞(包括符號(hào)): ['Today', ',', 'LeBron', 'James', 'passed', 'Michael', 'Jordan', 'in', 'career', 'points', 'for', 'regular', 'season', ',', 'playoffs', 'combined', '.'] NLTK:輸出句子中的每個(gè)單詞(包括符號(hào)): ['Today', ',', 'Huawei', 'Sues', 'the', 'US', 'Government', 'for', 'Unconstitutional', 'Sales', 'Restrictions', 'Imposed', 'by', 'Congress', '.']NLTK:輸出句子中的每個(gè)單詞(包括符號(hào))—按照順序: [',', '.', 'James', 'Jordan', 'LeBron', 'Michael', 'Today', 'career', 'combined', 'for', 'in', 'passed', 'playoffs', 'points', 'regular', 'season'] NLTK:輸出句子中的每個(gè)單詞(包括符號(hào))—按照順序: [',', '.', 'Congress', 'Government', 'Huawei', 'Imposed', 'Restrictions', 'Sales', 'Sues', 'Today', 'US', 'Unconstitutional', 'by', 'for', 'the']['today', ',', 'lebron', 'jame', 'pass', 'michael', 'jordan', 'in', 'career', 'point', 'for', 'regular', 'season', ',', 'playoff', 'combin', '.'] ['today', ',', 'huawei', 'sue', 'the', 'US', 'govern', 'for', 'unconstitut', 'sale', 'restrict', 'impos', 'by', 'congress', '.']NLTK:輸出句子中的每個(gè)單詞(包括符號(hào))—及其對(duì)應(yīng)詞性: [('Today', 'NN'), (',', ','), ('LeBron', 'NNP'), ('James', 'NNP'), ('passed', 'VBD'), ('Michael', 'NNP'), ('Jordan', 'NNP'), ('in', 'IN'), ('career', 'NN'), ('points', 'NNS'), ('for', 'IN'), ('regular', 'JJ'), ('season', 'NN'), (',', ','), ('playoffs', 'NNS'), ('combined', 'VBD'), ('.', '.')] NLTK:輸出句子中的每個(gè)單詞(包括符號(hào))—及其對(duì)應(yīng)詞性: [('Today', 'NN'), (',', ','), ('Huawei', 'NNP'), ('Sues', 'NNP'), ('the', 'DT'), ('US', 'NNP'), ('Government', 'NNP'), ('for', 'IN'), ('Unconstitutional', 'NNP'), ('Sales', 'NNS'), ('Restrictions', 'NNS'), ('Imposed', 'VBN'), ('by', 'IN'), ('Congress', 'NNP'), ('.', '.')]?
實(shí)現(xiàn)代碼
測(cè)試的句子:來(lái)自今天的新聞
sent1 = 'Today, LeBron James passed Michael Jordan in career points for regular season, playoffs combined.'
sent2 = 'Today, Huawei Sues the US Government for Unconstitutional Sales Restrictions Imposed by Congress.'
sent1='今天,勒布朗·詹姆斯在常規(guī)賽和季后賽的總得分中超過(guò)了邁克爾·喬丹。
sent2='今天,華為起訴美國(guó)政府違反國(guó)會(huì)規(guī)定的銷售限制。'
?
?
?
?
總結(jié)
以上是生活随笔為你收集整理的NLP之BoWNLTK:自然语言处理中常用的技术——词袋法Bow、NLTK库的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: ML之SVM:利用SVM算法(超参数组合
- 下一篇: AI公开课:19.03.07雷鸣教授《人