fastText Python 教程

article/2025/8/26 19:37:43

诸神缄默不语-个人CSDN博文目录

fastText Python官方GitHub文件夹网址:fastText/python at main · facebookresearch/fastText
本文介绍fastText Python包的基本教程,包括安装方式和简单的使用方式。

我看gensim也有对fasttext算法的支持(https://radimrehurek.com/gensim/models/fasttext.html),那个我以后可能会在写gensim相关博文的时候写吧。

本文所使用的示例中文文本分类数据来自https://raw.githubusercontent.com/SophonPlus/ChineseNlpCorpus/master/datasets/ChnSentiCorp_htl_all/ChnSentiCorp_htl_all.csv。除文中所做的工作外,还可以做停用词处理等其他工作。
其他fasttext Python示例代码可参考:fastText/python/doc/examples at master · facebookresearch/fastText

文章目录

  • 1. 安装fastText
  • 2. 训练和调用词向量模型
    • 2.1 代码实现
    • 2.2 原理介绍
  • 3. 文本分类
    • 3.1 代码实现
    • 3.2 原理介绍
  • 4. 量化实现模型压缩
  • 5. 模型的属性和方法
  • 6. 忽略警告
  • 7. 其他在正文及脚注中未提及的参考资料

1. 安装fastText

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

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

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

我安装过两次fasttext,第一次就非常正常地走完上述所有环节就安装成功了;第二次我用阿里云服务器安装(因为觉得是个很简单的分类任务,不需要大动干戈上GPU,凑合用CPU就完了),结果先是报RuntimeError: Unsupported compiler -- at least C++11 support is needed!,我根据1用root运行了yum install gcc-c++,然后我一pip install fasttext就直接给我卡死了,IO直接满了,我设置命令行的IO权限最低也没用。
解决方案是改为下载wheel:pip install fasttext-wheel(这个包的pypi主页:https://pypi.org/project/fasttext-wheel/)

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-011.71287894e-01 -2.93396801e-01 -1.01871997e-01  2.42363811e-012.78942972e-01 -4.99058776e-02 -1.27043173e-01  2.87460908e-023.73771787e-01 -1.69842303e-01  2.42533281e-01 -1.82482198e-017.33817369e-02  2.21920848e-01  2.17794716e-01  1.68730497e-012.16873884e-02 -3.15452456e-01  8.21631625e-02 -6.56387508e-029.51113254e-02  1.69942483e-01  1.13980576e-01  1.15132451e-013.28856230e-01 -4.43856061e-01 -5.13903908e-02 -1.74580872e-014.39242758e-02 -2.22267807e-01 -1.09185934e-01 -1.62346154e-012.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-013.49486321e-02  8.70033056e-02 -4.75800633e-01  5.37340902e-022.29140893e-02  3.87787819e-04 -5.77102527e-02  1.44286081e-031.33415654e-01  2.14263964e-02  9.26891491e-02 -2.24226922e-017.32692927e-02 -1.52607411e-01 -1.42978013e-01 -4.28122580e-029.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-021.23811573e-01  6.13824800e-02  2.12341957e-02 -9.38200951e-02-1.40030123e-03  2.17677400e-01 -6.04508296e-02 -4.68601920e-022.30288744e-01 -2.68855840e-01  7.73726255e-02  1.22143216e-013.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的范式,可参考官方教程中的相应部分:https://fasttext.cc/docs/en/supervised-tutorial.html#multi-label-classification,以及我撰写的另一篇博文: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。

将训练好的模型储存到本地:model.save_model(saved_bin)
从本地加载训练好的模型:model=fasttext.load_model(saved_bin)
在加载时会报一个警告,可以忽略。可参考:Warning : load_model does not return WordVectorModel or SupervisedModel any more(fasttext 0.9.2) · Issue #1056 · facebookresearch/fastText

train_supervised()其他入参:

  • epoch(默认值为5)
  • lr(效果好的范围为0.1-1)
  • wordNgrams 用n-gram而不是unigram(当使用语序很重要的分类任务(如情感分析)时很重要)
  • bucket
  • dim
  • loss
    • 使用hs (hierarchical softmax) 代替标准softmax,可以加速运行
      hierarchical softmax:看了一下没太看懂,总之大概来说是用二叉树来表示标签,这样复杂度就不呈线性增长而是呈对数增长了。fasttext中用的是哈夫曼树,平均查询时间最优。fasttext官方介绍:https://fasttext.cc/docs/en/supervised-tutorial.html#advanced-readers-hierarchical-softmax 此外还给出了一个YouTube讲解视频:Neural networks [10.7] : Natural language processing - hierarchical output layer - YouTube
    • one-vs-allova: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 quantizedpredict                 # 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 pathtest                    # Evaluate supervised model using file given by pathtest_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()`

6. 忽略警告

在调用本地存储的文本分类模型checkpoint(model=fasttext.load_model(model_path))时会报这个警告:

Warning : `load_model` does not return WordVectorModel or SupervisedModel any more, but a `FastText` object which is very similar.

解决方案是:

try:# silences warnings as the package does not properly use the python 'warnings' package# see https://github.com/facebookresearch/fastText/issues/1056fasttext.FastText.eprint = lambda *args,**kwargs: None
except:pass

7. 其他在正文及脚注中未提及的参考资料

  1. NLP实战之Fasttext中文文本分类_vivian_ll的博客-CSDN博客_fasttext 中文:这一篇去除了停用词,此外还介绍了gensim包中计算词向量的方法。
  2. [原创]《使用 fastText 做中文文本分类》文章合集 – 编码无悔 / Intent & Focused:这一篇是使用Java做的,因为数据量很大,所以想用map-reduce实现。数据标签是通过腾讯云文本分类免费API来调取得到的……
  3. 关于文本分类(情感分析)的中文数据集汇总_樱与刀的博客-CSDN博客_情感分析数据集
  4. Python3读取CSV数据_柿子镭的博客-CSDN博客_python3读取csv文件
  5. python读取csv时skipinitialspace参数的使用_vanlywang的博客-CSDN博客
  6. Warning : load_model does not return WordVectorModel or SupervisedModel any more, but a FastText_GodGump的博客-CSDN博客:这篇解决方案跟我文中提及的参考资料是相同的

  1. Cannot install fastText because gcc 7.3.1 does not support C++11 on Amazon Linux - Stack Overflow
    Python 编译错误 Unsupported compiler – at least C++11 support is needed! 解决方案 - 码农教程 ↩︎


http://chatgpt.dhexx.cn/article/vLqmSPi7.shtml

相关文章

玩转Fasttext

Fasttext是Facebook AI Research最近推出的文本分类和词训练工具&#xff0c;其源码已经托管在Github上。Fasttext最大的特点是模型简单&#xff0c;只有一层的隐层以及输出层&#xff0c;因此训练速度非常快&#xff0c;在普通的CPU上可以实现分钟级别的训练&#xff0c;比深度…

FastText详解

词向量对比word2vec https://zhuanlan.zhihu.com/p/75391062 0、实战经验 word2vec vs fastText区别&#xff1f; 思想&#xff1a;将整篇文档的词及n-gram向量叠加平均得到文档向量&#xff0c;然后使用文档向量做softmax多分类。 word2vec vs fastText区别&#xff1f; …

FastText原理

一、简介 fasttext是facebook开源的一个词向量与文本分类工具&#xff0c;在2016年开源&#xff0c;典型应用场景是“带监督的文本分类问题”。提供简单而高效的文本分类和表征学习的方法&#xff0c;性能比肩深度学习而且速度更快。 fastText结合了自然语言处理和机器学习中最…

Fasttext

Fasttext Paper Fasttext特点 模型简单&#xff0c;只有一层的隐层以及输出层&#xff0c;因此训练速度非常快不需要训练词向量&#xff0c;Fasttext自己会训练两个优化&#xff1a;Hierarchical Softmax、N-gram Fasttext模型架构 fastText模型架构和word2vec中的CBOW很相…

[NLP]文本分类之fastText详解

Word2vec, Fasttext, Glove, Elmo, Bert, Flair pre-train Word Embedding 一、fastText简介 fastText是一个快速文本分类算法&#xff0c;与基于神经网络的分类算法相比有两大优点&#xff1a; 1、fastText在保持高精度的情况下加快了训练速度和测试速度 2、fastText不需要预…

FastText:高效的文本分类工具

❤️觉得内容不错的话&#xff0c;欢迎点赞收藏加关注&#x1f60a;&#x1f60a;&#x1f60a;&#xff0c;后续会继续输入更多优质内容❤️ &#x1f449;有问题欢迎大家加关注私戳或者评论&#xff08;包括但不限于NLP算法相关&#xff0c;linux学习相关&#xff0c;读研读博…

FastText的简单介绍

0、引言 FastText是facebook开源的一款集word2vec、文本分类等一体的机器学习训练工具。在之前的论文中&#xff0c;作者用FastText和char-CNN、deepCNN等主流的深度学习框架&#xff0c;在同样的公开数据集上进行对比测试&#xff0c;在保证准确率稳定的情况下&#xff0c;Fa…

快速文本分类(FastText)

&#x1f50e;大家好&#xff0c;我是Sonhhxg_柒&#xff0c;希望你看完之后&#xff0c;能对你有所帮助&#xff0c;不足请指正&#xff01;共同学习交流&#x1f50e; &#x1f4dd;个人主页&#xff0d;Sonhhxg_柒的博客_CSDN博客 &#x1f4c3; &#x1f381;欢迎各位→点赞…

FastText:快速的文本分类器

转载请注明作者和出处&#xff1a;http://blog.csdn.net/john_bh/ 一、简介二、FastText原理 2.1 模型架构2.2 层次SoftMax2.3 N-gram特征 三、 基于fastText实现文本分类 3.1 fastText有监督学习分类3.2 fastText有监督学习分类 三、总结 3.1 fastText和word2vec的区别3.2 小…

DCGAN的PyTorch实现

DCGAN 1.什么是GAN GAN是一个框架&#xff0c;让深度模型可以学习到数据的分布&#xff0c;从而通过数据的分布生成新的数据(服从同一分布)。 其由一个判别器和一个生成器构成&#xff0c;生成器负责生成“仿造数据”&#xff0c;判别器负责判断“仿造数据”的质量。两者一起…

GAN论文阅读——DCGAN

论文标题&#xff1a;Unsupervised Representation Learning with Deep Convolutional Generative Adversarial Networks 论文链接&#xff1a;https://arxiv.org/abs/1511.06434 参考资料&#xff1a;http://blog.csdn.net/liuxiao214/article/details/73500737      …

DCGAN整理总结

DCGAN整理总结 GAN什么是GAN&#xff1f;GAN重要参数及损失函数 DCGAN什么是DCGAN&#xff1f;DCGAN结构TensorFlow版本MINIST手写体生成模型Pytorch版本人脸生成模型 GAN 什么是GAN&#xff1f; GAN是一个教深度学习模型捕捉训练数据的布局来从该布局中生成新数据的框架。最早…

DCGAN论文翻译

UNSUPERVISED REPRESENTATION LEARNING WITH DEEP CONVOLUTIONAL GENERATIVE ADVERSARIAL NETWORKS &#xff08;使用DCGAN的无监督表示学习&#xff09; ABSTRACT&#xff08;摘要&#xff09; In recent years, supervised learning with convolutional networks (CNNs) h…

机器学习中的DCGAN-Tensorflow:用于更稳定的训练

https://www.toutiao.com/a6666031263536644621/ 自从Ian Goodfellow的论文以来&#xff0c;GAN已应用于许多领域&#xff0c;但其不稳定性一直存在问题。GAN必须解决极小极大&#xff08;鞍点&#xff09;问题&#xff0c;因此这个问题是固有的。 马鞍点的滑稽表示 许多研究人…

DCGAN 源码解析

为什么写Blog现在还没找到理由。不过用心看下去你会觉得更有意义。 我们以生成图片为例子: G就是一个生成图片的网络&#xff0c;它接受一个随机的噪声z&#xff0c;然后通过这个噪声生成图片&#xff0c;生成的数据记做G(z)。D是一个判别网络&#xff0c;判别一张图片是不是…

pytorch搭建DCGAN

我们知道gan的过程是对生成分布拟合真实分布的一个过程&#xff0c;理想目标是让判别器无法识别输入数据到底是来源于生成器生成的数据还是真实的数据。 当然这是一个博弈的过程并且相互促进的过程&#xff0c;其真实的过程在于首先判别器会先拟合真实数据的分布&#xff0c;然…

tensorflow实现DCGAN

1、DCGAN的简单总结 【Paper】 &#xff1a; http://arxiv.org/abs/1511.06434 【github】 : https://github.com/Newmu/dcgan_code theano https://github.com/carpedm20/DCGAN-tensorflow tensorflow https://github.com/jacobgil/keras-dcgan keras https://github.c…

DCGAN TUTORIAL

Introduction 本教程将通过一个示例对DCGAN进行介绍。在向其展示许多真实名人的照片之后&#xff0c;我们将训练一个生成对抗网络&#xff08;GAN&#xff09;来产生新名人。此处的大多数代码来自pytorch / examples中的dcgan实现 &#xff0c;并且本文档将对该实现进行详尽的…

DCGAN原文讲解

DCGAN的全称是Deep Convolution Generative Adversarial Networks(深度卷积生成对抗网络)。是2014年Ian J.Goodfellow 的那篇开创性的GAN论文之后一个新的提出将GAN和卷积网络结合起来&#xff0c;以解决GAN训练不稳定的问题的一篇paper. 关于基本的GAN的原理&#xff0c;可以…

DCGAN

转自&#xff1a;https://blog.csdn.net/liuxiao214/article/details/74502975 首先是各种参考博客、链接等&#xff0c;表示感谢。 1、参考博客1&#xff1a;地址 ——以下&#xff0c;开始正文。 2017/12/12 更新 解决训练不收敛的问题。 更新在最后面部分。 1、DCGAN的…