短文本分类
haiku-lst的Python项目详细描述
这个项目已被否决。也许需要深入学习。
安装
git clone https://gitlab.com/hansroh/haiku
cd haiku
python setup.py build install
基本用法
importhaikumodel_path="./golforbed"analyzer=haiku.StandardAnalyzer(max_term=200,stem_level=2,make_lower_case=1)trainset=[('Golf',"cloudy cold calm"),('Golf',"sunny warm"),('Bed',"rainy hot"),('Golf',"sunny hot windy"),('Bed',"windy cloudy cold"),('Bed',"rainy cloudy cold"),]# trainingh=haiku.Haiku(model_path,haiku.CL_L2,analyzer)# pruning by document frequency and scoring by meth (FS_CF means category frequency)h.select(data,mindf=0,maxdf=0,top=0,meth=haiku.FS_CF)# set training options: uni/bigram and feature representationh.train(haiku.BIGRAM,haiku.FT_BIN)h.close()# guessingh=haiku.Haiku(model_path,haiku.CL_L2,analyzer)h.load()print(h.guess("sunny cold windy"))h.close()
通过Skitai应用程序引擎导出API
将模型数据放入app_root/resources/haikus/golfebed。
importhaikuimportskitaiif__name__=="__main__":pref=skitai.pref()pref.config.resource_dir=skitai.joinpath('resources')skitai.mount("/",haiku,"app",pref)skitai.run(port=5005)
转到http://127.0.0.1:5000/haiku/golforbed/guess?q=sunny%20cold%20windy。