Part of Speech Tagging
Natural Language Processing with Python
Charpter 6.1
suffix_fdist处代码稍微改动。
import nltk
from nltk.corpus import brown def common_suffixes_fun():
suffix_fdist=nltk.FreqDist()
for word in brown.words():
word=word.lower()
suffix_fdist[word[-1:]] +=1
suffix_fdist[word[-2:]] +=1
suffix_fdist[word[-3:]] +=1
most_freqent_items=[it for it in sorted(suffix_fdist.items(),key=lambda x:(-x[1],x[0]))[:100]]
return [su[0] for su in most_freqent_items] common_suffixes = common_suffixes_fun() def pos_features(word):
features={}
for su in common_suffixes:
features['endswith(%s)' % su]=word.lower().endswith(su)
return features def test_pos():
tagged_words = brown.tagged_words(categories='news')[:5000]
featuresets=[(pos_features(word),tag) for (word,tag) in tagged_words] size= int(len(tagged_words)*0.1)
train_set, test_set = featuresets[size:],featuresets[:size]
classifier=nltk.NaiveBayesClassifier.train(train_set) print nltk.classify.accuracy(classifier,test_set)
classifier.show_most_informative_features(5)
运行结果为:
0.652
Most Informative Features
endswith(o) = True TO : NN = 423.2 : 1.0
endswith(es) = True DOZ : NN = 319.5 : 1.0
endswith(om) = True WPO : NN = 319.5 : 1.0
endswith(as) = True BEDZ : IN = 303.3 : 1.0
endswith(s) = True BEDZ : IN = 303.3 : 1.0
Part of Speech Tagging的更多相关文章
- 自然语言15.1_Part of Speech Tagging 词性标注
QQ:231469242 欢迎喜欢nltk朋友交流 https://en.wikipedia.org/wiki/Part-of-speech_tagging In corpus linguistics ...
- 自然语言15_Part of Speech Tagging with NLTK
https://www.pythonprogramming.net/part-of-speech-tagging-nltk-tutorial/?completed=/stemming-nltk-tut ...
- 词性标注 parts of speech tagging
In corpus linguistics, part-of-speech tagging (POS tagging or POST), also called grammatical tagging ...
- 常用python机器学习库总结
开始学习Python,之后渐渐成为我学习工作中的第一辅助脚本语言,虽然开发语言是Java,但平时的很多文本数据处理任务都交给了Python.这些年来,接触和使用了很多Python工具包,特别是在文本处 ...
- 自然语言14_Stemming words with NLTK
https://www.pythonprogramming.net/stemming-nltk-tutorial/?completed=/stop-words-nltk-tutorial/ # -*- ...
- 自然语言12_Tokenizing Words and Sentences with NLTK
https://www.pythonprogramming.net/tokenizing-words-sentences-nltk-tutorial/ # -*- coding: utf-8 -*- ...
- 大数据分析与机器学习领域Python兵器谱
http://www.thebigdata.cn/JieJueFangAn/13317.html 曾经因为NLTK的缘故开始学习Python,之后渐渐成为我工作中的第一辅助脚本语言,虽然开发语言是C/ ...
- ML 05、分类、标注与回归
机器学习算法 原理.实现与实践 —— 分类.标注与回归 1. 分类问题 分类问题是监督学习的一个核心问题.在监督学习中,当输出变量$Y$取有限个离散值时,预测问题便成为分类问题. 监督学习从数据中学习 ...
- Python 网页爬虫 & 文本处理 & 科学计算 & 机器学习 & 数据挖掘兵器谱(转)
原文:http://www.52nlp.cn/python-网页爬虫-文本处理-科学计算-机器学习-数据挖掘 曾经因为NLTK的缘故开始学习Python,之后渐渐成为我工作中的第一辅助脚本语言,虽然开 ...
随机推荐
- IIS express 7.5 设置默认文档
在C:\Users\[电脑用户名]\Documents\IISExpress\config 下面有个applicationhost.config文件,打开文件找到<system.webServe ...
- 2.1 实践篇:使用ping来检测网速
1. Windows功能键+R ,打开cmd窗口 2. ping -n 200 www.baidu.com #ping网站www.baidu.com ,连续200次.验证连接. 可以ctrl+C 强制 ...
- OpenGL--------纹理处理
我们可以将像素数据按照矩形进行缩小和放大,但是还不足以满足我们的要求.例如要将一幅世界地图绘制到一个球体表面,只使用glPixelZoom这样的函数来进行缩放显然是不够的.OpenGL纹理映射功能支持 ...
- Spring Boot 系列教程4-JDBC
JDBC Java Data Base Connectivity,是一种用于执行SQL语句的Java API,可以为多种关系数据库提供统一访问,它由一组用Java语言编写的类和接口组成.不管是Hibe ...
- VJ16216/RMQ/线段树单点更新
题目链接 /* 单点更新,用RMQ维护最大值,add对c[i]修改,或加,或减. 求[l,r]的和,用sum(r)-sum(l-1).即可. */ #include<cmath> #inc ...
- HTML一些小细节
这里主要是记录一些看起来不重要,但是其实作用不小或者使用起来某种情况下好用的东西,又或者是重要的但容易忽略的基础知识 1. HTML5之后的第一个标签是<!DOCTYPE html> 这个 ...
- java 文件字节输入流
Example10_4.java import java.io.*; public class Example10_4 { public static void main(String args[]) ...
- java 面向抽象编程的思想
SIM.java public abstract class SIM { public abstract void setNumber(String n); public abstract Strin ...
- Android与路由器连接服务
界面UI: package my.work.Library; import java.util.Timer; import java.util.TimerTask; import java.util. ...
- ZOJ 2872 Binary Partitions
先写一个完全背包,然后找规律,然后打表. #include<cstdio> #include<cstring> #include<cmath> #include&l ...