我正在尝试为maxent分类器创建Java实现。我需要将句子分为n不同的类别。
我看了斯坦福maxent分类器中的ColumnDataClassifier。但是我不明白如何创建训练数据。我需要训练数据的形式,其中训练数据包括用于单词的POS标签,以便用于分类的功能将类似于上一个单词,下一个单词等。
我正在寻找带有POS TAGGING句子和句子类别的训练数据。例如:
我/(POS)名称/(POS)是/(POS)XYZ /(POS)类别
任何帮助将不胜感激。
当前文件组织如下所示:
Species_name1.asc
Species_name1.csv
Species_name1_Averages.csv
...
...
Species_name2.asc
Species_name2.csv
Species_name2_Averages.csv
我需要找出一个脚本,该脚本可以使用名称(Species_name1、Species_name2...等)创建新目录,并且可以将文件从基本目录移动到适当的新目录中。
import os
import glob
import shutil
base_directory = [CURRENT_WORKING_DIRECTORY]
with open("folder_names.txt", "r") as new_folders:
for i in new_folders:
os.mkdirs(base_directory+i)
Run Code Online (Sandbox Code Playgroud)
上面是我在基目录中创建新目录时可以想到的一个例子。
我知道如果我要使用 python,我将不得不使用 os、shutil 和/或 glob 模块中的工具。然而,确切的脚本正在逃避我,我的文件仍然没有组织。如果您有任何建议可以帮助我完成这项小任务,我将不胜感激。
此目录中还有许多文件类型和后缀,但 (species_name?) 部分始终保持一致。
以下是预期的层次结构:
Species_name1
-- Species_name1.asc
-- Species_name1.csv
-- Species_name1_Averages.csv
Species_name2
-- Species_name2.asc
-- Species_name2.csv
-- Species_name2_Averages.csv
先感谢您!
我一直在python中使用maxent分类器,它失败了,我不明白为什么.
我正在使用电影评论语料库.(总菜鸟)
import nltk.classify.util
from nltk.classify import MaxentClassifier
from nltk.corpus import movie_reviews
def word_feats(words):
return dict([(word, True) for word in words])
negids = movie_reviews.fileids('neg')
posids = movie_reviews.fileids('pos')
negfeats = [(word_feats(movie_reviews.words(fileids=[f])), 'neg') for f in negids]
posfeats = [(word_feats(movie_reviews.words(fileids=[f])), 'pos') for f in posids]
negcutoff = len(negfeats)*3/4
poscutoff = len(posfeats)*3/4
trainfeats = negfeats[:negcutoff] + posfeats[:poscutoff]
classifier = MaxentClassifier.train(trainfeats)
Run Code Online (Sandbox Code Playgroud)
这是错误(我知道我做错了,请链接到Maxent如何工作)
警告(来自警告模块):文件"C:\ Python27\lib\site-packages \nltk\classify\maxent.py",第1334行sum1 = numpy.sum(exp_nf_delta*A,axis = 0)运行时警告:遇到无效值乘以
警告(来自警告模块):文件"C:\ Python27\lib\site-packages \nltk\classify\maxent.py",第1335行sum2 = numpy.sum(nf_exp_nf_delta*A,axis = 0)运行时警告:遇到无效值乘以
警告(来自警告模块):文件"C:\ Python27\lib\site-packages \nltk\classify\maxent.py",第1341行deltas - =(ffreq_empirical - sum1)/ -sum2 …