[FastText in Text Classification]论文实现:Bag of Tricks for Efficient Text Classification

简介: [FastText in Text Classification]论文实现:Bag of Tricks for Efficient Text Classification

Bag of Tricks for Efficient Text Classification

论文:Bag of Tricks for Efficient Text Classification

作者:Armand Joulin,Edouard Grave,Piotr Bojanowski,Tomas Mikolov

时间:2016

地址:https://cs.brown.edu/people/pfelzens/segment

一、完整代码

直接调用fastext库就好,很快就能搞定!

import fasttext
# data.train.txt是一个文本文件,每行包含一个训练句和标签。默认情况下,我们假设标签是以  __label__ 为前缀的单词
model = fasttext.train_supervised('data.train.txt')
# 返回概率最高的三个结果,由于预测两个,一共会返回6个结果
model.predict(["Which baking dish is best to bake a banana bread ?", "Why not put knives in the dishwasher?"], k=3)

api中的label是前缀,默认为__label__

二、论文解读

2.1 模型架构

A simple and efficient baseline for sentence classification is to represent sentences as bag of words (BoW) and train a linear classifier, e.g., a logistic regression or an SVM (Joachims, 1998; Fan et al., 2008). However, linear classifiers do not share parameters among features and classes. This possibly limits their generalization in the context of large output space where some classes have very few examples. Common solutions to this problem are to factorize the linear classifier into low rank matrices (Schutze, 1992; Mikolov et al., 2013) or to use multilayer neural networks (Collobert and Weston, 2008; Zhang et al., 2015).

       由于线性分类器不会在类别和特征之间共享参数,所以我们不需要计算每一个类别的softmax值;即可以使用Hierarchical Softmax 或者 Negative Sampling 来加快训练速度;

       同时,由于各个词的内部特征也可以进行考虑,根据论文Enriching Word Vectors with Subword Information,我们可以使用论文的subwords方法进行映射;

       模型架构如下:

与论文Enriching Word Vectors with Subword Information不同的是,那里的output是词向量,而这里是类别(class or label);完毕!

三、过程实现

在论文中Enriching Word Vectors with Subword Information详细讲了;这里只需要softmax就可以了

四、整体总结

实现难度远不如Enriching Word Vectors with Subword Information


目录
打赏
0
2
2
0
14
分享
相关文章
【提示学习】HPT: Hierarchy-aware Prompt Tuning for Hierarchical Text Classification
本文是较早把Prompt应用到层级多标签文本分类领域的论文。思路是把层级标签分层编入到Pattern中,然后修改损失函数以适应多标签的分类任务。
273 0
【小样本图像分割-3】HyperSegNAS: Bridging One-Shot Neural Architecture Search with 3D Medical Image Segmentation using HyperNet
本文介绍了一种名为HyperSegNAS的新方法,该方法结合了一次性神经架构搜索(NAS)与3D医学图像分割,旨在解决传统NAS方法在3D医学图像分割中计算成本高、搜索时间长的问题。HyperSegNAS通过引入HyperNet来优化超级网络的训练,能够在保持高性能的同时,快速找到适合不同计算约束条件的最优网络架构。该方法在医疗分割十项全能(MSD)挑战的多个任务中展现了卓越的性能,特别是在胰腺数据集上的表现尤为突出。
47 0
【小样本图像分割-3】HyperSegNAS: Bridging One-Shot Neural Architecture Search with 3D Medical Image Segmentation using HyperNet
[FastText in Word Representations]论文实现:Enriching Word Vectors with Subword Information*
[FastText in Word Representations]论文实现:Enriching Word Vectors with Subword Information*
53 2
【提示学习】Exploiting Cloze Questions for Few Shot Text Classification and Natural Language Inference
目前流行的第四大范式Prompt的主流思路是PVP,即Pattern-Verbalizer-Pair,主打的就是Pattern(模板)与Verbalizer(标签映射器)。   本文基于PVP,提出PET与iPET,但是关注点在利用半监督扩充自己的数据集,让最终模型学习很多样本,从而达到好效果。
142 0
【论文精读】AAAI 2022 - Unified Named Entity Recognition as Word-Word Relation Classification
到目前为止,命名实体识别(NER)已经涉及三种主要类型,包括扁平、重叠(又名嵌套)和不连续NER,它们大多是单独研究的。
273 0
【论文精读】AAAI 2022 - Unified Named Entity Recognition as Word-Word Relation Classification
【论文解读】Co-attention network with label embedding for text classification
华南理工出了一篇有意思的文章,将标签和文本进行深度融合,最终形成带标签信息的文本表示和带文本信息的标签表示。
289 1
DeIT:Training data-efficient image transformers & distillation through attention论文解读
最近,基于注意力的神经网络被证明可以解决图像理解任务,如图像分类。这些高性能的vision transformer使用大量的计算资源来预训练了数亿张图像,从而限制了它们的应用。
593 0
SimCSE: Simple Contrastive Learning of Sentence Embeddings论文解读
本文介绍了SimCSE,一个简单的对比学习框架,极大地推进了最先进的句子嵌入。我们首先描述了一种无监督方法,该方法采用一个输入句子,并在一个对比目标中预测自己
343 0
【论文解读】Dual Contrastive Learning:Text Classification via Label-Aware Data Augmentation
北航出了一篇比较有意思的文章,使用标签感知的数据增强方式,将对比学习放置在有监督的环境中 ,下游任务为多类文本分类,在低资源环境中进行实验取得了不错的效果
518 0

热门文章

最新文章

AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等