zoukankan      html  css  js  c++  java
  • TextGrocery中文文本分类处理

    详细使用说明:http://textgrocery.readthedocs.io/zh/latest/index.html

    TextGrocery是一个基于LibLinear结巴分词的短文本分类工具,特点是高效易用,同时支持中文和英文语料。

    GitHub项目链接

    需要安装:

    pip install classifier

     过程:

    >>> from tgrocery import Grocery
    # 新开张一个杂货铺(别忘了取名)
    >>> grocery = Grocery('sample')
    # 训练文本可以用列表传入
    >>> train_src = [
            ('education', '名师指导托福语法技巧:名词的复数形式'),
    ...     ('education', '中国高考成绩海外认可 是“狼来了”吗?'),
    ...     ('sports', '图文:法网孟菲尔斯苦战进16强 孟菲尔斯怒吼'),
    ...     ('sports', '四川丹棱举行全国长距登山挑战赛 近万人参与')
    ... ]
    >>> grocery.train(train_src)
    Building prefix dict from the default dictionary ...
    Dumping model to file cache /tmp/jieba.cache
    Loading model cost 1.125 seconds.
    Prefix dict has been built succesfully.
    *
    optimization finished, #iter = 3
    Objective value = -1.092381
    nSV = 8
    <tgrocery.Grocery object at 0x7f23cf243b50>
    >>> grocery.save()
    >>> new_grocery = Grocery('sample')
    >>> new_grocery.load()
    >>> new_grocery.predict('考生必读:新托福写作考试评分标准')
    <tgrocery.base.GroceryPredictResult object at 0x4490d50>
    >>> new_grocery.predict('考生必读:新托福写作考试评分标准')
    <tgrocery.base.GroceryPredictResult object at 0x4490d90>
    >>> result = new_grocery.predict('考生必读:新托福写作考试评分标准')
    >>> print result
    education

    完毕。

  • 相关阅读:
    【Docker】 CentOS7 安装 Docker 及其使用方法 ( 一 )
    js加密解密
    JSON.parse和eval()的区别
    复选框(全选/全不选/反选)
    圆形进度条
    C# JToken类,实现解析动态json数据、遍历、查找
    使IIS服务器支持下载 apk/ipa 安装包
    Python关键字
    C#泛型(二)泛型类
    C#泛型(一)泛型方法
  • 原文地址:https://www.cnblogs.com/zl0372/p/6045065.html
Copyright © 2011-2022 走看看