Doc2Vec Model (三)参数说明

Doc2Vec 参数说明 Parameters

class gensim.models.doc2vec.Doc2Vec(documents=None, corpus_file=None, vector_size=100, dm_mean=None, dm=1, 
dbow_words=0, dm_concat=0, dm_tag_count=1, dv=None, dv_mapfile=None, comment=None, trim_rule=None, 
callbacks=(), window=5, epochs=10, **kwargs)
  • documents:(iterable of list of TaggedDocument,optional) - 输入语料库,可以是一个简单的元素列表, 但是对于更大的语料库, 可以考虑一个可迭代的直接从磁盘/网络流式传输的 d o c u m e n t s documents documents。 如果不提供 d o c u m e n t s documents documents(或者语料库文件),模型将保持未初始化状态-你计划用其他的方式初始化该模型

  • corpus_file:(str, optional)- LineSentence格式语料库的路径。可以使用该参数替换 d o c u m e n t s documents documents来提高性能。只需要传递一个 d o c u m e n t s documents documents或者 c o r p u s _ f i l e s corpus\_files corpus_files参数(或者都没有,在这种情况下,模型将保持未初始化状态)。 d o c u m e n t s documents documents t a g s tags tags是自动分配的,并等于行号,如 TaggedDocument

  • dm:({1,0},optional) - 定义训练算法。如果 dm =1, 使用 d i s t r i b u t e d   m e m o r y distributed\ memory distributed memory (PV-DM)。否则,则使用 d i s t r i b u t e d   b a g   o f   w o r d s distributed\ bag\ of\ words distributed bag of words (PV-DBOW) 。

  • vector_size: (int, optional) - 特征向量的维数。

  • window::(int, optional) - 句子中当前单词和预测单词之间的最大距离。

  • alpha: (float, optional) - 初始学习速率。

  • min_alpha : (float, optional) - 随着训练的进行,学习速率将线性下降至 m i n _ a l p h a min\_alpha min_alpha

  • seed: (int, optional) - 随机数生成器的种子。每个 单词的初始向量使用 w o r d + word + word+str(seed)的连接哈希进行种子播种。注意,对于完全确定的可重复运行,还必须将模型限制为单个工作线程(workers=1), 从操作系统线程调度中消除排序抖动。在 P y t h o n 3 Python 3 Python3中,解释器启动之间的再现性还需要使用 PYTHONHASHSEED环境变量来控制散列随机化。

  • min_count:(int, optional) - 忽略总频率低于此值的所有单词。

  • max_vocab_size:(int, optional) - 在词汇构建过程中限制 R A M RAM RAM;如果有比这个更独特的单词,那么删掉不常见的单词。每1000万字类型需要大约1GB的内存。如果没有限制,则设置为 None

  • sample:(float, optional) - 配置高频字随机下采样的阈值,有效范围是 ( 0 , 1 e − 5 ) (0,1e-5) (01e5)。\

  • workers:(int, optional) - 使用多个工作线程来训练模型(=使用多核机器进行更快的训练)。

  • epochs:(int, optional) - 语料库上的迭代次数( e p o c h s epochs epochs)。

  • hs:({1,0}, optional) - 如果为1,则将使用 h i e r a r c h i c a l   s o f t m a x hierarchical\ softmax hierarchical softmax进行模型训练。
    如果设置为0,并且negative 为非零,则将使用负采样。

  • negative:(int, optional) - 如果大于0,将使用负采样,负的常数指定应绘制多少个“噪声字”(通常在5-20之间)。
    如果设置为0,则不使用负采样。

  • ns_exponent:(float, optional) - 用于形成负采样分布的指数。值1.0与频率完全成比例采样,0.0平均采样所有单词,而负值采样低频单词多于高频单词。最流行的默认值0.75是由Word2Vec的原始文件选择的。最近,在Word2Vec applied to Recommendation: Hyperparameters Matter中Caselles Dupré、Lesaint和Royo Letelier建议,对于推荐应用程序,其他值可能表现更好。

  • dm_mean:({1,0}, optional) - 如果为0,则使用上下文单词向量的和。如果为1,则使用平均数。dm只是在非串联模式下使用。

  • dm_concat:({1,0}, optional) - 如果为1,则使用上下文向量的连接,而不是 s u m / a v e r a g e sum/average sum/average;请注意,连接会导致更大的模型,因为输入不再是一个(采样或算术组合)词向量的大小,而是标签和上下文中串在一起的所有单词的大小。

  • dm_tag_count:(int, optional) - 使用dm_uconcat模式时,每个文档的文档标记的数量应为常量。

  • dbow_words:({1,0}, optional) - 如果设置为1,则与 D B O W   d o c   v e c t o r DBOW\ doc\ vector DBOW doc vector同时训练单词向量(以 s k i p   g r a m skip\ gram skip gram方式);如果设置为0,则只训练doc向量(更快)。

  • trim_rule:(function, optional) - 词汇表修剪规则,指定特定单词是应该保留还是删除,或者使用默认值(如果单词计数< min_count,则删除)。可以是None,(将使用min_count, 在keep_vocab_item()中查找),或者接收参数(word, count, min_count)
    并且返回gensim.utils.RULE_DISCARDgensim.utils.RULE_KEEP,或者gensim.utils.RULE_DEFAULT。该规则(如果给定)仅用于在当前方法调用期间修剪词汇表,而不是作为模型的一部分存储。
    输入参数有以下类型:

    • word (str) - 正在研究的单词
    • count (int) - 语料库中单词的频率计数
    • min_count (int) - 最小计数阈值
  • callbacks :训练期间需要在特定阶段执行/运行的回调列表。

  • 2
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Python Doc2Vec is an algorithm for generating vector representations of documents. It is an extension of the Word2Vec algorithm, which generates vector representations of words. Doc2Vec is used for tasks such as text classification, document similarity, and clustering. The basic idea behind Doc2Vec is to train a neural network to predict the probability distribution of words in a document. The network takes both the document and a context word as input, and predicts the probability of each word in the vocabulary being the next word in the document. The output of the network is a vector representation of the document. Doc2Vec can be implemented using the Gensim library in Python. The Gensim implementation of Doc2Vec has two modes: Distributed Memory (DM) and Distributed Bag of Words (DBOW). In DM mode, the algorithm tries to predict the next word in the document using both the context words and the document vector. In DBOW mode, the algorithm only uses the document vector to predict the next word. To use Doc2Vec with Gensim, you need to first create a corpus of documents. Each document should be represented as a list of words. You can then create a Doc2Vec model and train it on the corpus. Once the model is trained, you can use it to generate vector representations of new documents. Here's an example of training a Doc2Vec model using Gensim: ``` from gensim.models.doc2vec import Doc2Vec, TaggedDocument from nltk.tokenize import word_tokenize # create a corpus of documents doc1 = TaggedDocument(words=word_tokenize("This is the first document."), tags=["doc1"]) doc2 = TaggedDocument(words=word_tokenize("This is the second document."), tags=["doc2"]) doc3 = TaggedDocument(words=word_tokenize("This is the third document."), tags=["doc3"]) corpus = [doc1, doc2, doc3] # create a Doc2Vec model and train it on the corpus model = Doc2Vec(corpus, vector_size=100, window=5, min_count=1, workers=4, epochs=50) # generate vector representations of new documents new_doc = word_tokenize("This is a new document.") vector = model.infer_vector(new_doc) ``` In this example, we create a corpus of three documents and train a Doc2Vec model with a vector size of 100, a window size of 5, a minimum word count of 1, and 50 epochs. We then generate a vector representation of a new document using the `infer_vector` method.

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值