用python将语料转化为可计算的形式,python语料,自然语言处理领域 用途:
用python将语料转化为可计算的形式,python语料,自然语言处理领域 用途:
自然语言处理领域 用途:用python将语料转化为可计算的形式
1.[用python将语料转化为可计算的形式代码]语料向量化
#-*- coding:utf-8 -*-#语料向量化表示方法#以下代码参考 Natural Language Processing with Python 一书# www.iplaypy.comfeatures = ['春天','冬天','雪','温暖'] #抽取的特征(用来表示文档的具有代表性的词语)neg_tweetList = [['我','爱','春天'],['最','喜欢','春天']] #积极情感语料示例pos_tweetList = [['我','喜欢','冬天'],['最','爱','冬天']] #消极情感语料示例feature_dict ={} #特征词典for i in range(len(features)): feature_dict[i] = features[i] documents=([(tweet, '-1') for tweet in neg_tweetList]+ [(tweet, '1') for tweet in pos_tweetList])vectorList=[]for tweetPolarity in documents: tweet = ' '.join(i.decode('utf-8') for i in tweetPolarity[0]) word_id_presence_dict={} for word in features: index_id = features.index(word) if word in tweetPolarity[0]: word_id_presence_dict[index_id]=1 category, vector = tweetPolarity[-1], word_id_presence_dict vectorDict = {} vectorDict[tweet] = category, vector vectorList.append(vectorDict) print vectorList
编橙之家文章,
相关内容
- 简单的筛选格式 python工具,筛选python工具,自己写的简
- 使用python重命名指定目录文件,,使用python重命名指
- python数据结构快速排序,python数据结构,<python数据结
- pyton清空当前目录下当前文件以外的所有文件,pyton当前
- 我使用Python计算日志文件中IP的次数,python日志文件,我
- Python方法求水仙花数原码实例,python水仙花,用Python编程
- 数据包分析ascii转码操作方法,ascii操作方法,关于数据
- 下载百度空间文章python源码,百度文章python源码,纯py
- 显示压缩文件内容Python源码,压缩文件python源码,zip压缩
- Python判断统计每个月天数源码示例,python源码,如何利用
评论关闭