NLP基础-wangdong

MediaEval 2015 “verifying multimedia use” 包含文本、图像/视频以及社交上下文信息。
任务是判别吗,媒体传输的图文是否一致等
NLP基础-wangdong_第1张图片
词形还原(Lemmatization)与词干提取(stemming)的区别
词形还原是把单词还原成本身的形式:比如将‘cars’还原成car,把‘ate’还原成‘eat’,把‘handling’还原成‘handle’
词干提取则是提取单词的词干,比如将‘cars’提取出‘car’,将‘handling’提取出来‘handl’(单纯的去掉ing),对于‘ate’使用词干提取则不会有任何的效

stopwords停用词处理

stop words是指自然语言处理当中会被过滤掉的一些单词,一般是指无意义的定冠词,不定冠词(a,an,the), 连接词(of,but…),这个并没有统一的标准,而是针对具体的任务和文档来说,那些高频经常出现的词语因为对具体任务来说其实没有帮助(比如文档分类,几乎每个文档都有上面提到的词语,对分类没有任何帮助),所以在处理的时候会去掉这些单词,来提升针对性任务的结果。虽然没有统一的stop word list,但是有很多小众使用的stop words

import nltk
from nltk.corpus import stopwords
from nltk.tokenize import word_tokenize
example_sent = "the respecting  Spasmodic SecondaryVenereal off from Fluids	portions partly Nerve Example	some Natives  Metacarpal Contracted Constitutions	Instance jat by severe double Appendix contained Joints Disorders  Tumour Vascular Tongue Bone case Liver Account Diseases History Explanation A  Soldiery Human Brain betweenHumor operation , cyst Tabular Radial attended situated Inflammation Puberty attached sawing evacuating Dissection DiseaseMouth Groin Some Bones cases circumstances posterior Cataract	intoStrangulatedAqueous Observations . was to which Aneurism Paralysis	beneficial	Eyes Opium Ossium Effects Hemorrhage Appearance succeeded On a with Synopsis Fon in successfully"
stop_words = set(stopwords.words('english'))
word_tokens = word_tokenize(example_sent)
filtered_sentence = [w for w in word_tokens if not w in stop_words]
filtered_sentence = []
for w in word_tokens:
     if w not in stop_words:
      filtered_sentence.append(w)
print(word_tokens)
print(filtered_sentence)

POS TAG(Part-Of-Speech 词性标签)

CC     coordinatingconjunction 并列连词
CD     cardinaldigit  纯数  基数
DT     determiner  限定词(置于名词前起限定作用,如 the、some、my 等)
EX     existentialthere (like:"there is"... think of it like "thereexists")   存在句;存现句
FW     foreignword  外来语;外来词;外文原词
IN     preposition/subordinating conjunction介词/从属连词;主从连词;从属连接词
JJ     adjective    'big'  形容词
JJR    adjective, comparative 'bigger' (形容词或副词的)比较级形式
JJS    adjective, superlative 'biggest'  (形容词或副词的)最高级
LS     listmarker  1)
MD     modal (could, will) 形态的,形式的 , 语气的;情态的
NN     noun, singular 'desk' 名词单数形式
NNS    nounplural  'desks'  名词复数形式
NNP    propernoun, singular     'Harrison' 专有名词
NNPS  proper noun, plural 'Americans'  专有名词复数形式
PDT    predeterminer      'all the kids'  前位限定词
POS    possessiveending  parent's   属有词  结束语
PRP    personalpronoun   I, he, she  人称代词
PRP$  possessive pronoun my, his, hers  物主代词
RB     adverb very, silently, 副词    非常  静静地
RBR    adverb,comparative better   (形容词或副词的)比较级形式
RBS    adverb,superlative best    (形容词或副词的)最高级
RP     particle     give up 小品词(与动词构成短语动词的副词或介词)
TO     to    go 'to' the store.
UH     interjection errrrrrrrm  感叹词;感叹语
VB     verb, baseform    take   动词
VBD    verb, pasttense   took   动词   过去时;过去式
VBG    verb,gerund/present participle taking 动词  动名词/现在分词
VBN    verb, pastparticiple     taken 动词  过去分词
VBP    verb,sing. present, non-3d     take 动词  现在
VBZ    verb, 3rdperson sing. present  takes   动词  第三人称
WDT    wh-determiner      which 限定词(置于名词前起限定作用,如 the、some、my 等)
WP     wh-pronoun   who, what 代词(代替名词或名词词组的单词)
WP$    possessivewh-pronoun     whose  所有格;属有词
WRB    wh-abverb    where, when 副词


import nltk
words=word_tokenize(‘i hate study on monday. Jim like rabbit.’)

sentiment word lists 情感词表

https://blog.csdn.net/sinat_36972314/article/details/79621591

情感分析器模块——nltk.sentiment.vader
它可以分析一段文字或句子下情绪的正面、负面和中性极性分类。其中,compound表示复杂程度,neu表示中性,neg表示负面情绪,pos表示正面情绪。


import nltk
from nltk.sentiment.vader import SentimentIntensityAnalyzer
# nltk.download('vader_lexicon')
view = ["Great place to be when you are in Bangalore",
        "The place was being renovated when I visited so the seating was limited",
        "Loved the ambience, loved the food",
        "The place is not easy to locate"]
sid = SentimentIntensityAnalyzer()
for sen in view:
    print(sen)
    ss = sid.polarity_scores(sen)
    for k in ss:
        print('{0}:{1},'.format(k, ss[k]), end='')
    print()

lists of respected news organizations受人尊敬的新闻机构名单

实际上这个对应的是NLP中的专有名词(名称和组织)解析技术

做文本分类:

整体思路:
1、先把没用的词干掉(之前你也做了),比如去掉停止词(你又加了一些特殊符合等等),冠词(通过识别词性)。得到一个“干货”数据集。
2、从这些中找出最常见的若干的单词(比如2k个词),最常见的单词可以是TF,对于不同的类分别找出
3、用朴素贝叶斯分类器对特征进行分类

[
({'单词1':0.2, '单词2': 0.1}, label1),
......
]

训练集首先是一个list,每个item是一个训练样本。每个是一个元组,第一个item是dict,dict的每个item是一个维度,key-value。第二个item是label

classifier = nltk.NaiveBayesClassifier.train(training_set)
nltk.classify.accuracy(classifier, testing_set)
# 找出最能够区分分类的特征值
classifier.show_most_informative_features(2)
Most Informative Features
             last_letter = u'a'           cls1 : cls2   =     35.6 : 1.0
             last_letter = u'k'             cls2 : cls1 =     30.7 : 1.0

类别名是设置
labeled_names = ([(name, ‘cls1’) for word in cls1_words] + [(name, ‘cls2’) for name in cls2_words])

预测:

classifier.prob_classify({'单词1':0.5, '单词2': 0.71}).prob('cls1')
#0.994878529146
classifier.classify({'单词1':0.5, '单词2': 0.71})
#cls1

有什么:
1、将每个文档类别的前N个TF词频-IDF逆文本频率指数特征汇总起来
TF表示词条在文档d中出现的频率。IDF的主要思想是:如果包含词条t的文档越少,也就是n越小,IDF越大,则说明词条t具有很好的类别区分能力。

TF-IDF用以评估一字词对于一个文件集或一个语料库中的其中一份文件的重要程度。字词的重要性随着它在文件中出现的次数成正比增加,但同时会随着它在语料库中出现的频率成反比下降。如果某个词或短语在一篇文章中出现的频率TF高,并且在其他文章中很少出现,则认为此词或者短语具有很好的类别区分能力。TF-IDF=TF * IDF

你可能感兴趣的:(授课,自然语言处理,人工智能)