extremetext库的python接口
extremetext的Python项目详细描述
extremeText是 fastText的扩展 包含极端情况的多标签分类库 成千上万的标签。
extremeText实现:
- 极端多标签的概率标签树(PLT)损失 自上而下分层聚类(k-means)分类 树木建筑,
- 多标签分类的乙状结肠缺失,
- 所有损失的L2正则化和FOBOS更新,
- 带套袋的损失层集合
- 计算隐藏(文档)向量作为 词向量
- 词的tf-idf权重计算。
要求
extremeText基于 现代Mac OS和Linux发行版因为它使用C++ 11的特性,所以 需要有良好的C++ 11支持的编译器。其中包括:
- (gcc-4.8或更新版本)或(clang-3.3或更新版本)
你需要:
安装extremeText
最简单的方法 extremeText将使用 pip
$ pip install extremetext
在MacOS上安装可能需要设置 MACOSX_DEPLOYMENT_TARGET=10.9第一个:
$ export MACOSX_DEPLOYMENT_TARGET=10.9 $ pip install extremetext
最新版本的 extremeText可以生成 从使用pip或其他设置工具的源
$ git clone https://github.com/mwydmuch/extremeText.git $ cd extremeText $ pip install . (or) $ python setup.py install
现在您可以使用以下命令导入此库:
import extremeText
示例
一般认为读者已经对 快速文本/extremetext。为此,请考虑 README 以及the tutorials on fastText website。
我们建议您查看examples within the doc folder。
与任何包一样,您可以使用 帮助功能
例如:
+>>> import extremeText +>>> help(extremeText.ExtremeText) Help on module extremeText.ExtremeText in extremeText: NAME extremeText.ExtremeText DESCRIPTION # Copyright (c) 2017-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the BSD-style license found in the # LICENSE file in the root directory of this source tree. An additional grant # of patent rights can be found in the PATENTS file in the same directory. FUNCTIONS load_model(path) Load a model given a filepath and return a model object. tokenize(text) Given a string of text, tokenize it and return a list of tokens [...]
重要提示:预处理数据/编码约定
一般来说,正确地预处理数据是很重要的。例子 root folder中的脚本执行此操作。
像extremeText一样,fastText采用UTF-8编码的文本所有文本必须是 unicode for Python2 以及str for Python3。 传递的文本将是encoded as UTF-8 by pybind11 然后传递给极端主义C++库。这意味着它很重要 在构建模型时使用utf-8编码文本。在类unix系统上 您可以使用 iconv
extremeText将根据 以下是ascii字符(字节)。特别是,它没有意识到 UTF-8空白我们建议用户转换utf-8空白/字 以适当的方式划分为下列符号之一
- 空间
- 制表符
- 垂直选项卡
- 回车
- 模板馈送
- 空字符
换行符用于分隔文本行。特别地, 如果换行符是 遇到。唯一的例外是如果令牌数超过 最大行大小常量,如Dictionary header中所定义。 这意味着如果文本不是用换行符分隔的,比如 在fil9 dataset中,它将是 使用最大行大小的令牌分成块,EOS令牌是 没有附加。
令牌的长度是utf-8个字符的数量,通过考虑 要识别的leading two bits of a bytesubsequent bytes of a multi-byte sequence。 在选择最小值和 子字的最大长度。此外,eos令牌(如 Dictionary header) 被认为是一个字符,不会被分解成子单词。
参考
如果使用此软件包进行极端分类,请引用以下工作。
M.Wydmuch、K.Jasinska、M.Kuznetsov、R.Busa Fekete、K.Dembczy湫ski。 *A no-regret generalization of hierarchical softmax to extreme multi-label classification*。 神经信息处理系统进展31,2018。