fastText简单介绍和使用

1. fastText的介绍

文档地址:https://fasttext.cc/docs/en/support.html

fastText is a library for efficient learning of word representations and sentence classification.

fastText是一个单词表示学习和文本分类的库

优点:在标准的多核CPU上, 在10分钟之内能够训练10亿词级别语料库的词向量,能够在1分钟之内给30万多类别的50多万句子进行分类。

fastText 模型输入一个词的序列(一段文本或者一句话),输出这个词序列属于不同类别的概率。

2. 安装和基本使用

2.1 安装步骤:

  1. 下载 git clone https://github.com/facebookresearch/fastText.git
  2. cd cd fastText
  3. 安装 python setup.py install

2.2 基本使用

  1. 把数据准备为需要的格式

  2. 进行模型的训练、保存和加载、预测

    #1. 训练
    model = fastText.train_supervised("./data/text_classify.txt",wordNgrams=1,epoch=20)
    #2. 保存
    model.save_model("./data/ft_classify.model")
    #3. 加载
    model = fastText.load_model("./data/ft_classify.model")
    
    textlist = [句子1,句子2]
    #4. 预测,传入句子列表
    ret = model.predict(textlist)
    

你可能感兴趣的:(机器学习,python)