fastText Python 教程

python3使用fasttext进行中文文本分类 本文完成在python3下,利用fasttext对中文文本进行分类。期间使用了jieba分词。 数据集 本文使用skdjfla在github上的头条新闻数据集.包括新闻数据382688条(只包含标题),共15个类别。 数据预处理 fastext包进行文本分类类似于sklearn,已经进行完整封装,只需要生成指定格式的文本文件即可以开始训练。文件格式如下(__labe__为类别标记) 2018 年... 阅读详情

1. 安装fastText

首先需要安装numpy、scipy和pybind11。

numpy我是在安装PyTorch的时候,顺带着安装的。我使用的命令行是conda install pytorch torchvision torchaudio cudatoolkit=10.2 -c pytorch。单独安装numpy可以参考使用conda install numpy。 安装SciPy:conda install scipy 或 pip install scipy 安装pybind11,参考官方文档:Installing the library — pybind11 documentation:conda install -c conda-forge pybind11 或 pip install pybind11

安装完前置包之后,安装fastText:pip install fasttext

2. 训练和调用词向量模型

以前我用gensim做过。以后可以比较一下两个包的不同之处。 此外fasttext词向量论文中用的baseline是谷歌官方的word2vec包:Google Code Archive - Long-term storage for Google Code Project Hosting.

2.1 代码实现

官方详细教程:Word representations · fastText(使用的是英文维基百科的语料,本文的实验用的是中文语料)

由于fasttext本身没有中文分词功能,因此需要手动对文本预先分词。处理数据的代码可参考:

import csv,jieba
with open('data/cls/ChnSentiCorp_htl_all.csv') as f:
    reader=csv.reader(f)
    header = next(reader)  #表头
    data = [[int(row[0]),row[1]] for row in reader]  #每个元素是一个由字符串组成的列表,第一个元素是标签(01),第二个元素是评论文本。

tofiledir='data/cls'
with open(tofiledir+'/corpus.txt','w') as f:
    f.writelines([' '.join(jieba.cut(row[1]))+'\n' for row in data])

文件效果:

学习词向量并展示的代码:

import fasttext
model=fasttext.train_unsupervised('data/cls/corpus.txt',model='skipgram')  #model入参可以更换为`cbow`
print(model.words[:10])  #打印前10个单词
print(model[model.words[9]])  #打印第10个单词的词向量

(展示词向量也可以使用get_word_vector(word),而且可以查找数据中未出现的data(事实上词向量是用子字符串总和来表示的))

输出:

Read 0M words
Number of words:  6736
Number of labels: 0
Progress: 100.0% words/sec/thread:   71833 lr:  0.000000 avg.loss:  2.396854 ETA:   0h 0m 0s
[',', '的', '。', ',', '了', '酒店', '是', '</s>', '很', '房间']
[ 1.44523270e-02 -1.14391923e-01 -1.31457284e-01 -1.59686044e-01
 -4.57017310e-02  2.04045177e-01  2.00106978e-01  1.63031772e-01
  1.71287894e-01 -2.93396801e-01 -1.01871997e-01  2.42363811e-01
  2.78942972e-01 -4.99058776e-02 -1.27043173e-01  2.87460908e-02
  3.73771787e-01 -1.69842303e-01  2.42533281e-01 -1.82482198e-01
  7.33817369e-02  2.21920848e-01  2.17794716e-01  1.68730497e-01
  2.16873884e-02 -3.15452456e-01  8.21631625e-02 -6.56387508e-02
  9.51113254e-02  1.69942483e-01  1.13980576e-01  1.15132451e-01
  3.28856230e-01 -4.43856061e-01 -5.13903908e-02 -1.74580872e-01
  4.39242758e-02 -2.22267807e-01 -1.09185934e-01 -1.62346154e-01
  2.11286068e-01  2.44934723e-01 -1.95910111e-02  2.33887792e-01
 -7.72107393e-02 -6.28366888e-01 -1.30844399e-01  1.01614185e-01
 -2.42928267e-02  4.28218693e-02 -3.78409088e-01  2.31552869e-01
  3.49486321e-02  8.70033056e-02 -4.75800633e-01  5.37340902e-02
  2.29140893e-02  3.87787819e-04 -5.77102527e-02  1.44286081e-03
  1.33415654e-01  2.14263964e-02  9.26891491e-02 -2.24226922e-01
  7.32692927e-02 -1.52607411e-01 -1.42978013e-01 -4.28122580e-02
  9.64387357e-02  7.77726322e-02 -4.48957413e-01 -6.19397573e-02
 -1.22236833e-01 -6.12100661e-02 -5.51685333e-01 -1.35704070e-01
 -1.66864052e-01  7.26311505e-02 -4.55838069e-02 -5.94963729e-02
  1.23811573e-01  6.13824800e-02  2.12341957e-02 -9.38200951e-02
 -1.40030123e-03  2.17677400e-01 -6.04508296e-02 -4.68601920e-02
  2.30288744e-01 -2.68855840e-01  7.73726255e-02  1.22143216e-01
  3.72817874e-01 -1.87924504e-01 -1.39104724e-01 -5.74962497e-01
 -2.42888659e-01 -7.35510439e-02 -6.01616681e-01 -2.18178451e-01]

检查词向量的效果:搜索其最近邻居(nearest neighbor (nn)),给出向量捕获语义信息的直觉观感(在教程中英文拼错了也能用,但是中文这咋试,算了) (向量距离用余弦相似度计算得到)

print(model.get_nearest_neighbors('房间'))

输出:[(0.804237425327301, '小房间'), (0.7725597023963928, '房屋'), (0.7687026858329773, '尽头'), (0.7665393352508545, '第一间'), (0.7633816599845886, '但床'), (0.7551409006118774, '成旧'), (0.7520463466644287, '屋子里'), (0.750516414642334, '压抑'), (0.7492958903312683, '油漆味'), (0.7476236820220947, '知')]

word analogies(预测跟第三个词组成与前两个词之间关系的词):

print(model.get_analogies('房间','压抑','环境'))

输出:[(0.7665581703186035, '优越'), (0.7352521419525146, '地理位置'), (0.7330452799797058, '安静'), (0.7157530784606934, '周边环境'), (0.7050396800041199, '自然环境'), (0.6963807344436646, '服务到位'), (0.6960451602935791, '也好'), (0.6948464512825012, '优雅'), (0.6906660795211792, '地点'), (0.6869651079177856, '地理')]

其他函数:

  • model.save_model(path)
  • fasttext.load_model(path) 返回model

fasttext.train_unsupervised()其他参数:

  • dim 向量维度(默认值是100,100-300都是常用值)
  • minn maxn 最大和最小的subword子字符串(默认值是3-6)
  • epoch(默认值是5)
  • lr 学习率高会更快收敛,但是可能过拟合(默认值是0.05,常见选择范围是 [0.01, 1] )
  • thread(默认值是12)
    input             # training file path (required)
    model             # unsupervised fasttext model {cbow, skipgram} [skipgram]
    lr                # learning rate [0.05]
    dim               # size of word vectors [100]
    ws                # size of the context window [5]
    epoch             # number of epochs [5]
    minCount          # minimal number of word occurences [5]
    minn              # min length of char ngram [3]
    maxn              # max length of char ngram [6]
    neg               # number of negatives sampled [5]
    wordNgrams        # max length of word ngram [1]
    loss              # loss function {ns, hs, softmax, ova} [ns]
    bucket            # number of buckets [2000000]
    thread            # number of threads [number of cpus]
    lrUpdateRate      # change the rate of updates for the learning rate [100]
    t                 # sampling threshold [0.0001]
    verbose           # verbose [2]

fastText官方提供已训练好的300维多语言词向量:Wiki word vectors · fastText 新版:Word vectors for 157 languages · fastText

2.2 原理介绍

在论文中如使用词向量,需要引用这篇文献:Enriching Word Vectors with Subword Information

skipgram和cbow应该不太需要介绍,这是NLP的常识知识。skipgram用一个随机选择的邻近词预测目标单词,cbow用上下文(在一个window内,比如加总向量)预测目标单词。 fasttext所使用的词向量兼顾了subword信息(用子字符串表征加总,作为整体的表征),比单使用word信息能获得更丰富的语义,运算速度更快,而且可以得到原语料中不存在的词语。

3. 文本分类

3.1 代码实现

官方详细教程:Text classification · fastText(官方教程使用的数据集是英文烹饪领域stackexchange数据集)

本文中介绍的是one-label的情况,如果想使用multi-label的范式,可参考官方教程中的相应部分:fasttext.cc/docs/en/sup…,以及我撰写的另一篇博文:multi-class分类模型评估指标的定义、原理及其Python实现

首先将原始数据处理成fasttext分类格式(需要手动对中文分词,标签以__label__为开头)(由于fasttext只有训练代码和测试代码,所以我只分了训练集和测试集),代码可参考:

import csv,jieba,random
with open('data/cls/ChnSentiCorp_htl_all.csv') as f:
    reader=csv.reader(f)
    header = next(reader)  #表头
    data = [[row[0],row[1]] for row in reader]  #每个元素是一个由字符串组成的列表,第一个元素是标签(01),第二个元素是评论文本。

tofiledir='data/cls'
#随机抽取80%训练集,20%测试集
random.seed(14560704)
random.shuffle(data)
split_point=int(len(data)*0.8)
with open(tofiledir+'/train.txt','w') as f:
    train_data=data[:split_point]
    f.writelines([' '.join(jieba.cut(row[1]))+' __label__'+row[0]+'\n' for row in train_data])
with open(tofiledir+'/test.txt','w') as f:
    test_data=data[split_point:]
    f.writelines([' '.join(jieba.cut(row[1]))+' __label__'+row[0]+'\n' for row in test_data])

文件示例:
训练分类模型,并进行测试,打印测试结果:

import fasttext
model=fasttext.train_supervised('data/cls/train.txt')
print(model.words[:10])
print(model.labels)

print(model.test('data/cls/test.txt'))

print(model.predict('酒店 环境 还 可以 , 服务 也 很 好 , 就是 房间 的 卫生 稍稍 马虎 了 一些 , 坐便器 擦 得 不是 十分 干净 , 其它 方面 都 还好 。 尤其 是 早餐 , 在 我 住 过 的 四星 酒店 里 算是 花样 比较 多 的 了 。 因为 游泳池 是 在 室外 , 所以 这个 季节 去 了 怕冷 的 人 就 没有 办法 游泳 。 补充 点评 2007 年 11 月 16 日 : 服务 方面 忘 了 说 一点 , 因为 我落 了 一样 小东西 在 酒店 , 还 以为 就算 了 , 没想到 昨天 离开 , 今天 就 收到 邮件 提醒 我 说 我 落 了 东西 , 问 我 需要 不 需要 他们 给 寄 回来 , 这 一点 比 有些 酒店 要 好 很多 。'))

输出:

Read 0M words
Number of words:  26133
Number of labels: 2
Progress: 100.0% words/sec/thread:  397956 lr:  0.000000 avg.loss:  0.353336 ETA:   0h 0m 0s
[',', '的', '。', ',', '了', '酒店', '是', '</s>', '很', '房间']
['__label__1', '__label__0']
(1554, 0.8783783783783784, 0.8783783783783784)
(('__label__1',), array([0.83198541]))

test()函数的输出依次是:样本数,precision@1,recall@1 (这个P@1大概意思是得分最高的标签属于正确标签的比例,可以参考:IR-ratio: Precision-at-1 and Reciprocal Rank。R@1是正确标签被预测到的概率)

predict()函数也可以传入字符串列表。

test()和predict()的入参k可以指定返回的标签数量,默认为1。

储存和加载模型文件的方式与第二节中词向量模型的类似。

train_supervised()其他入参:

  • epoch(默认值为5)
  • lr(效果好的范围为0.1-1)
  • wordNgrams 用n-gram而不是unigram(当使用语序很重要的分类任务(如情感分析)时很重要)
  • bucket
  • dim
  • loss
    • 使用hs (hierarchical softmax) 代替标准softmax,可以加速运行 hierarchical softmax:看了一下没太看懂,总之大概来说是用二叉树来表示标签,这样复杂度就不呈线性增长而是呈对数增长了。fasttext中用的是哈夫曼树,平均查询时间最优。fasttext官方介绍:fasttext.cc/docs/en/sup… 此外还给出了一个YouTube讲解视频:Neural networks [10.7] : Natural language processing - hierarchical output layer - YouTube
    • one-vs-all或ova:multi-label范式,将每个标签都单独建模成一个one-label分类任务(相比其他损失函数,建议调低学习率。predict()时指定k=-1输出尽量多的预测结果,threshold规定输出大于阈值的标签。test()时直接指定k=-1)
    input             # training file path (required)
    lr                # learning rate [0.1]
    dim               # size of word vectors [100]
    ws                # size of the context window [5]
    epoch             # number of epochs [5]
    minCount          # minimal number of word occurences [1]
    minCountLabel     # minimal number of label occurences [1]
    minn              # min length of char ngram [0]
    maxn              # max length of char ngram [0]
    neg               # number of negatives sampled [5]
    wordNgrams        # max length of word ngram [1]
    loss              # loss function {ns, hs, softmax, ova} [softmax]
    bucket            # number of buckets [2000000]
    thread            # number of threads [number of cpus]
    lrUpdateRate      # change the rate of updates for the learning rate [100]
    t                 # sampling threshold [0.0001]
    label             # label prefix ['__label__']
    verbose           # verbose [2]
    pretrainedVectors # pretrained word vectors (.vec file) for supervised learning []

3.2 原理介绍

在论文中如使用文本分类功能需引用该文献:Bag of Tricks for Efficient Text Classification

感觉是个比较直觉的简单模型,计算词向量后求平均值,计算输出标签。具体细节待补。

4. 量化实现模型压缩

# with the previously trained `model` object, call :
model.quantize(input='data.train.txt', retrain=True)

# then display results and save the new model :
print_results(*model.test(valid_data))
model.save_model("model_filename.ftz")

5. 模型的属性和方法

方法:

    get_dimension           # Get the dimension (size) of a lookup vector (hidden layer).
                            # This is equivalent to `dim` property.
    get_input_vector        # Given an index, get the corresponding vector of the Input Matrix.
    get_input_matrix        # Get a copy of the full input matrix of a Model.
    get_labels              # Get the entire list of labels of the dictionary
                            # This is equivalent to `labels` property.
    get_line                # Split a line of text into words and labels.
    get_output_matrix       # Get a copy of the full output matrix of a Model.
    get_sentence_vector     # Given a string, get a single vector represenation. This function
                            # assumes to be given a single line of text. We split words on
                            # whitespace (space, newline, tab, vertical tab) and the control
                            # characters carriage return, formfeed and the null character.
    get_subword_id          # Given a subword, return the index (within input matrix) it hashes to.
    get_subwords            # Given a word, get the subwords and their indicies.
    get_word_id             # Given a word, get the word id within the dictionary.
    get_word_vector         # Get the vector representation of word.
    get_words               # Get the entire list of words of the dictionary
                            # This is equivalent to `words` property.
    is_quantized            # whether the model has been quantized
    predict                 # Given a string, get a list of labels and a list of corresponding probabilities.
    quantize                # Quantize the model reducing the size of the model and it's memory footprint.
    save_model              # Save the model to the given path
    test                    # Evaluate supervised model using file given by path
    test_label              # Return the precision and recall score for each label.    

model.words         # equivalent to model.get_words()
model.labels        # equivalent to model.get_labels()

model['king']       # equivalent to model.get_word_vector('king')
'king' in model     # equivalent to `'king' in model.get_words()`

---------------------------END---------------------------

题外话

感谢你能看到最后,给大家准备了一些福利!

感兴趣的小伙伴,赠送全套Python学习资料,包含面试题、简历资料等具体看下方。


👉优快云大礼包🎁:全网最全《Python学习资料》免费赠送🆓!(安全链接,放心点击)

一、Python所有方向的学习路线

Python所有方向的技术点做的整理,形成各个领域的知识点汇总,它的用处就在于,你可以按照下面的知识点去找对应的学习资源,保证自己学得较为全面。

img

二、Python兼职渠道推荐*

学的同时助你创收,每天花1-2小时兼职,轻松稿定生活费.
在这里插入图片描述

三、最新Python学习笔记

当我学到一定基础,有自己的理解能力的时候,会去阅读一些前辈整理的书籍或者手写的笔记资料,这些笔记详细记载了他们对一些技术点的理解,这些理解是比较独到,可以学到不一样的思路。

img

四、实战案例

纸上得来终觉浅,要学会跟着视频一起敲,要动手实操,才能将自己的所学运用到实际当中去,这时候可以搞点实战案例来学习。

img

👉 优快云大礼包:gift::[全网最全《Python学习资料》免费赠送:free:!](https://blog.youkuaiyun.com/weixin_68789096/article/details/132275547?spm=1001.2014.3001.5502) (安全链接,放心点击)

若有侵权,请联系删除

PyCharm集成NLP相关fasttext、jieba模块 近期应公司业务需求,要开发一个AI助手。找个一个NLP相关python代码,下载并安装PyCharm编译器后,总是遇到编译运行报错问题。以下是导入NLP相关模块的配置说明。 阅读详情

相关推荐

fastText Python实战:从安装到文本分类的完整指南

本文详细介绍了fastText在Python中的实战应用,从安装到文本分类的完整指南。fastText作为Facebook开发的高效文本处理库,特别适合处理社交媒体文本等非规范用语场景。文章涵盖了词向量训练、文本分类实战及模型优化技巧,帮助开发者快速掌握这一强大工具。

weixin_29035147的博客 405

fasttext安装

方式一、使用pip install fastText 命令安装 这种方式报错: 目前本人不知道怎么解决 故采用了方式二来进行安装 git clone https://github.com/facebookresearch/fastText.git cd fastText pip install . 安装成功!! ...

霜叶的博客 2894

【NLP入门教程】十五、FastText保姆教程

FastText是一种基于词袋模型和n-gram特征的文本分类算法。相比于传统的词袋模型,FastText引入了子词(subword)的概念,从而更好地处理未登录词(out-of-vocabulary)和模糊词(morphologically rich word)。快速训练速度,适用于大规模文本数据集;能够处理未登录词和模糊词;支持多分类任务;简单易用。

m0_68629936的博客 908

python模块fasttext安装教程

fastText是一个用于高效学习词向量和文本分类的库,由 Facebook AI Research 开发。通过预编译的 whl 文件安装fastText可以简化安装过程,特别是在编译时可能会遇到依赖问题的情况下。

2401_85863780的博客 3909

手把手教你用CH582的USB0/1双接口玩转CherryUSB协议栈(附完整代码)

本文深入解析CH582双USB接口硬件架构,详细讲解如何通过CherryUSB协议栈实现双接口协同工作,包括中断处理设计、端点资源分配和复合设备描述符配置。提供HID+CDC复合设备实战案例,并分享高级调试技巧与性能优化方法,帮助开发者充分利用CH582的USB0/1双接口潜力。

weixin_42525637的博客 264

5G R18标准:AI/ML如何重塑空口优化与网络架构

人工智能与机器学习正逐步成为通信网络优化的核心技术。其核心原理在于通过数据驱动模型,从海量网络数据中学习信道变化、用户行为等统计规律,替代传统的基于固定规则的优化方法。这一技术范式能显著提升网络性能与效率,尤其在空口资源管理、干扰协调和能耗控制等场景中价值突出。在5G Advanced(R18)标准化框架下,AI/ML被系统性地引入空口设计,聚焦于信道状态信息反馈增强、波束管理与预测等关键用例。通过定义网络侧AI、终端侧AI及联合学习的标准化接口与流程,R18旨在实现跨厂商设备的智能协同,推动无线网络向自适

weixin_35671843的博客 244

python 使用fasttext 分词算法 基础使用思路篇

fasttext 基础使用方式

ShorttubeLy的博客 1180

VCU128开发板上手记:搞定100G以太网IP核与QSFP光模块的那些坑

本文详细介绍了在VCU128开发板上实现100G以太网IP核与QSFP光模块调试的实战经验。从硬件准备、IP核配置到QSFP模块控制信号处理,文章揭示了数据手册中未提及的关键细节,并提供了优化参数和压力测试方案,帮助开发者快速解决UltraScale+平台下的高速以太网部署难题。

weixin_30740295的博客 520

fasttext-language-identification 快速开始教程:3行Python代码,30秒完成任意语言检测

fasttext-language-identification 是 Meta 官方托管在 HuggingFace 上的**语言识别(Language Identification)模型**,基于轻量级 fastText 库训练,能自动判断任意文本的语言,支持多达 **217 种语言**。无论你是想给博客自动打语言标签,还是做多语言内容审核,用它都能在 30 秒内完成检测。 ## 📦 这是什么

gitblog_00780的博客 367

Unity获取透明物体深度数据

Unity获取透明物体深度数据前言透明&景深需求模型透明度部分带透明通道图片/视频部分半透明模型获取深度的具体实现方法带透明度图片/视频获取深度的具体实现方法结束语 前言 最近在做的项目有很多奇怪的需求,甚至之前在unity里用插件写了一个类似于蓝图的行为树插件,之后有时间给大家讲一讲相关的实现方法,今天刚解决了unity里透明物体无法获得深度数据的问题。所以分享给大家。 透明&景...

可以吃的妙脆角的博客 2631

保姆级教程:用Anaconda+PyCharm搞定YOLOv8本地部署(附避坑指南)

本文提供了一份详细的YOLOv8本地部署指南,涵盖Anaconda环境配置、PyCharm集成到模型部署的全过程。特别针对国内开发者需求,整合了镜像加速和常见报错解决方案,帮助快速完成目标检测模型的本地部署与实战应用。

weixin_42528090的博客 433

FastText日语训练教程

FastText日语训练教程 1. 项目基础介绍及主要编程语言 本项目是一个开源项目,旨在提供一个使用FastText对日语语料进行训练的教程。FastText是一种流行的文本分类和嵌入表示工具,本项目通过详细的步骤指导,帮助用户利用Python语言和FastText库来训练自己的日语文本模型。主要使用的编程语言是Python。 2. 项目的核心功能 项目的核心功能是指导用户如何准备日语语料库、进...

gitblog_00665的博客 478

基于Abaqus的横向各向同性线弹性理想塑性材料模型的umat子程序实现——以Fortran为例,带您揭秘弹性塑性模型编程之道

通过以上步骤,我们已经在Abaqus中使用Fortran实现了横向各向同性线弹性理想塑性材料模型的umat子程序。在实际应用中,我们需要根据具体的材料特性和加载条件来调整模型参数和计算过程。尽管我在这篇文章中尽力提供了详细的教程,但由于我自身的知识限制和经验不足,可能会有误解或错误。我希望大家在学习过程中能多思考,多实践,多交流,以更好地理解和掌握这个主题。

qq_38334677的博客 1690

问题随记 —— Python3.8 fasttext 安装

Python 安装 fasttext输入以下命令安装即可。 如果报错,需要事先安装 C++ 11 环境,否则将编译不成功,C++ 11 环境安装方式在下面的链接https://blog.youkuaiyun.com/qq_21484461/article/details/125417122

繁依Fanyi的博客 1433

C# 实现 Modbus 通信全教程(支持 TCP 和 RTU,含完整错误处理)

环境准备:安装 NModbus4 库,明确设备参数(IP/串口、地址、数据类型);连接设备:TCP 用 TcpClient,RTU 用 SerialPort,注意超时和参数匹配;读写数据:根据数据类型调用对应方法(读保持寄存器用 ReadHoldingRegisters);错误处理:捕获连接、超时、协议等异常,针对性排查问题。掌握这些后,即可轻松实现与工业设备的 Modbus 通信,为上位机开发提供稳定的数据交互能力。

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 2067

21、二维卷积层(convolution2dLayer)的全面解析

本文全面解析了二维卷积层(convolution2dLayer)的原理、属性和应用,详细介绍了其在深度学习中的作用及实现方法。文章涵盖创建卷积层的语法、参数设置、算法原理、输入输出格式、优化策略以及实际应用案例,旨在帮助读者更好地理解和应用二维卷积层构建高效的深度学习模型。

red88的博客 319

【亲测免费】 Pyfasttext 使用教程

Pyfasttext 使用教程 1. 项目介绍 pyfasttext 是一个用于 fastText 的 Python 绑定库。fastText 是由 Facebook 开发的一个用于高效学习词向量和文本分类的库。pyfasttext 提供了对 fastText 的 Python 接口,使得用户可以在 Python 环境中直接使用 fastText 的功能。 注意:pyfasttext 已经不再维护...

gitblog_00794的博客 480

迈瑞BS系列全自动生化分析仪LIS协议接口手册(内含HL7和ASTM)

迈瑞BS系列全自动生化分析仪LIS协议接口手册,内含HL7和ASTM)

安装fasttext-fasttextxxxxx.whl is not a supported wheel on this platform问题解决

一、下载(windows 版本下可以通过whl安装) 1. 地址:https://www.lfd.uci.edu/~gohlke/pythonlibs/#fasttext **2.**在我安装的环境下Lib\site-packages新建一个文件夹fastText 把下载好的whl文件放进去 注意: 确保下载合适的whl文件,否则可能出现fasttextxxxxx.whl is not a supported wheel on this platform错误 二、安装 切换到有whl文件的文件夹上

Mirrorystal 1862

NTscan扫描工具

ntscan是一个扫描器,可以扫描没有密码和弱密码的共享,先到配置文件中填写猜测的用户名和密码,扫描过程中右侧出现的是扫描日志。

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

floret: fastText + Bloom embeddings 的使用教程

floret: fastText + Bloom embeddings 的使用教程 1. 项目介绍 floret 是一个开源项目,基于 fastText 实现,通过引入 Bloom embeddings 来提供更加紧凑且全面的向量表示。它可以生成任意单词的词向量,结合了 fastText 的子词技术和 Bloom embeddings 的哈希技巧,大大减少了存储空间,同时保持了向量的准确性和速度。...

gitblog_00553的博客 590

蓝牙模块HM-10手册

蓝牙模块HM-10手册,该手册对蓝牙模块HM-10进行了详细的介绍和使用方法以及一些AT指令。

win7 python3.6安装fasttext

对应的链接是:https://www.lfd.uci.edu/~gohlke/pythonlibs/#fasttext里面有Python的各种第三方安装包。因为当前笔记本配置为win7(64bit) + py3.6.2,所以选择了fasttext-0.8.3-cp36-cp36m-win_amd64.whlPython如何安装.whl 文件?cmd进入当whl文件所在的文件夹下,然后Pip ins...

qq_22162795的博客 3250

探索日语自然语言处理的利器:fastText Japanese Tutorial

探索日语自然语言处理的利器:fastText Japanese Tutorial 在自然语言处理(NLP)的广阔领域中,日语的处理一直是一个挑战。然而,随着技术的进步,我们现在有了更强大的工具来应对这一挑战。今天,我们要介绍的是一个专为日语设计的开源项目——fastText Japanese Tutorial。 项目介绍 fastText Japanese Tutorial 是一个基于Facebo...

gitblog_01015的博客 414

【已解决】在windows系统安装fasttext库,解决安装fasttext报错问题

【已解决】在windows系统安装fasttext库,解决安装fasttext报错问题

weixin_56319483的博客 583

fast-langdetect 的安装和配置教程

fast-langdetect 的安装和配置教程 1. 项目的基础介绍和主要的编程语言 fast-langdetect 是一个开源的语言检测库,它基于快速文本分类算法,能够准确快速地识别文本的语言。该项目的主要编程语言是 Python,它提供了简单易用的接口,使得开发者在处理多语言文本数据时,可以轻松地检测出文本的语言类型。 2. 项目使用的关键技术和框架 该项目的核心技术是基于 n-gram 模...

gitblog_00114的博客 565

TextClassification-Keras环境配置与安装教程:从零开始的深度学习文本分类

TextClassification-Keras是一个基于Keras实现的文本分类模型集合,包含FastText、TextCNN、TextRNN、TextBiRNN、TextAttBiRNN、HAN、RCNN和RCNNVariant等多种经典算法,为自然语言处理研究者和开发者提供了便捷的模型实现与测试平台。 ## 📋 环境准备:系统与依赖要求 ### 基础系统要求 - **操作系统**:Li

gitblog_00688的博客 1064

深入解析 Macro Agent Harness 的 CodingPreferencesBody:用两个布尔开关定制编码会话行为

`CodingPreferencesBody` 是 Macro Agent Harness 中一个只有两个布尔字段的请求/响应体,却直接决定了每次新建编码会话“在任务书之外还要做什么”。本文以生成的 SDK 类型文档为骨架,结合 Rust 服务端实现、数据库迁移、SDK 封装与测试,讲清它的字段语义、HTTP 契约、持久化方式和提示词注入链路,帮助你在 SDK 或自建客户端中正确读写这份偏好。

gitblog_00308的博客 266
上一篇: Python爬虫超详细讲解(零基础入门,包教包会)
下一篇: 为什么Python是数据科学家的首选语言
Python_P叔
博客等级 码龄3年 5451粉丝 827原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值