FastText Python绑定
fasttext-github的Python项目详细描述
fastText是一个高效学习的库 词汇表征和句子分类。
要求
fastText构建在现代mac os和linux上 分配。因为它使用C++ 11个特性,所以需要编译器 良好的C++ 11支持。其中包括:
- (GCC-4.8或更新版本)或(Clang-3.3或更新版本)
您需要
生成快速文本
获取最新版本fastText is to use pip的最简单方法。
$ pip install fasttext
如果你想使用最新的不稳定版本,你需要建立 从源代码使用setup.py
现在您可以使用
import fastText
示例
一般认为读者已经对 快速文本。为此,请考虑 README 尤其是the tutorials on our website。
我们建议您查看examples within the doc folder。
与任何包一样,您可以使用 帮助功能。
例如
+>>> import fastText +>>> help(fastText.FastText) Help on module fastText.FastText in fastText: NAME fastText.FastText DESCRIPTION # Copyright (c) 2017-present, Facebook, Inc. # All rights reserved. # # This source code is licensed under the MIT license found in the # LICENSE file in the root directory of this source tree. 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中的示例脚本。
FastText采用UTF-8编码文本。所有文本必须是unicode for Python2 以及str for Python3。 传递的文本将是encoded as UTF-8 by pybind11 在传递到FASTTEXC++库之前。这意味着 在构建模型时使用utf-8编码文本。在类unix系统上 无法使用iconv转换文本。
FastText将根据以下内容进行标记(将文本分割成多个片段) ASCII字符(字节)。特别是,它不知道utf-8 空白我们建议用户转换utf-8空白/字 以适当的方式划分为下列符号之一。
- 空间
- 选项卡
- 垂直选项卡
- 回车
- formfeed
- 空字符
换行符用于分隔文本行。特别地, 如果换行符是 遇到。唯一的例外是如果令牌数超过 最大行大小常量,如Dictionary header中所定义。 这意味着如果文本不是用换行符分隔的,比如 在fil9 dataset,它将是 使用最大行大小的令牌分成块,eos令牌是 没有附加。
令牌的长度是utf-8个字符的数量,通过考虑 要识别的leading two bits of a bytesubsequent bytes of a multi-byte sequence。 在选择最小值和 最大长度。此外,eos令牌(如 Dictionary header) 被认为是一个字符,不会被分解成子单词。