zoukankan      html  css  js  c++  java
  • Identifying Dialogue Act Type

    Natural Language Processing with Python

    Chapter  6.2

     1 import nltk
     2 from nltk.corpus import nps_chat as nchat
     3 
     4 def dialogue_act_features(post):
     5     features={}
     6     for word in nltk.word_tokenize(post):
     7         features['contains(%s)' % word.lower()] = True
     8     return features
     9     
    10 def test_dialogue_act_types():
    11     posts=nchat.xml_posts()[:10000]
    12     featuresets = [(dialogue_act_features(post.text),post.get('class')) 
    13                     for post in posts]
    14     size=int(len(featuresets)*0.1)
    15     train_set, test_set = featuresets[size:],featuresets[:size]
    16     classifier = nltk.NaiveBayesClassifier.train(train_set)
    17     print nltk.classify.accuracy(classifier,test_set)
    18     classifier.show_most_informative_features(5)

    运行结果:

    0.668
    Most Informative Features
    contains(hi) = True Greet : System = 408.2 : 1.0
    contains(>) = True Other : System = 384.6 : 1.0
    contains(empty) = True Other : System = 339.4 : 1.0
    contains(part) = True System : Statem = 302.0 : 1.0
    contains(no) = True nAnswe : System = 262.3 : 1.0

  • 相关阅读:
    移动端Rem布局注意事项
    手动添加kdump
    Linux 添加新磁盘,在线扩充空间
    virtualbox linux虚拟机相关
    CentOS7 重置root密码
    putty无密码登陆
    sublime text3 安装插件
    jsp常用代码
    jq鼠标移入移除
    ajax请求超时解决方案
  • 原文地址:https://www.cnblogs.com/gui0901/p/4454364.html
Copyright © 2011-2022 走看看