gensim中word2vec

from gensim.models import Word2Vec
Word2Vec(self, sentences=None, size=100, alpha=0.025, window=5, min_count=5,
                 max_vocab_size=None, sample=1e-3, seed=1, workers=3, min_alpha=0.0001,
                 sg=0, hs=0, negative=5, cbow_mean=1, hashfxn=hash, iter=5, null_word=0,
                 trim_rule=None, sorted_vocab=1, batch_words=MAX_WORDS_IN_BATCH, compute_loss=False, callbacks=()):
        """
        Initialize the model from an iterable of `sentences`. Each sentence is a
        list of words (unicode strings) that will be used for training.

        Parameters
        ----------
        sentences : iterable of iterables
           待分析的语料,可以是一个列表,或者从文件中遍历读出。对于大语料集,建议使用BrownCorpus,Text8Corpus或lineSentence构建。
        sg : int {1, 0}
           定义训练算法. sg=1:skip-gram(输入word输出上下文); sg=0:CBOW(输入上下文输出word),默认sg=0,即CBOW模型
        size : int
           特征向量或词向量的维度,默认值是100
        window : int
            词向量上下文最大距离,skip-gram和cbow算法是基于滑动窗口来做预测。默认值为5。在实际使用中,可以根据实际的需求来动态调整这个window的大小。对于一般的语料这个值推荐在[5,10]之间。
        alpha : float
           是初始的学习速率,在训练过程中会线性地递减到min_alpha.
        min_alpha : float
            算法支持在迭代的过程中逐渐减小步长,min_alpha给出了最小的迭代步长值.
        seed : int
           用于随机数发生器, word + `str(seed)`的哈希值作为每个词的初始向量
        min_count : int
           最小截断值, 词频少于min_count次数的单词会被丢弃掉,默认值为5.
        max_vocab_size : int
           设置词向量构建期间的RAM限制,设置成None则没有限制。 Every 10 million word types need about 1GB of RAM.
        sample : float
            高频词汇的随机降采样的配置阈值,默认为1e-3,范围是(0,1e-5)。
        workers : int
           用于控制训练的并行数
        hs : int {1,0}
           word2vec两个解法的选择:如果是0, 则是Negative Sampling;如果是1并且负采样个数negative大于0, 则是Hierarchical Softmax。默认是0即Negative Sampling。
        negative : int
           如果大于0,则会采用negativesampling,用于设置多少个noise words(一般是5-20)。
        cbow_mean : int {1,0}
           仅用于CBOW在做投影的时候,为0,则采用上下文的词向量之和;为1则为上下文的词向量的平均值。默认值也是1,不推荐修改默认值。
        hashfxn : function
            hash函数来初始化权重,默认使用python的hash函数。
        iter : int
           随机梯度下降法中迭代的最大次数,默认是5。对于大语料,可以增大这个值。
        trim_rule : function
            用于设置词汇表的整理规则,指定那些单词要留下,哪些要被删除。可以设置为None(min_count会被使用)。
        sorted_vocab : int {1,0}
           如果为1(默认),则在分配word index 的时候会先对单词基于频率降序排序。
        batch_words : int
            每一批的传递给线程的单词的数量,默认为10000。
       
        Examples
        --------
        Initialize and train a `Word2Vec` model

       from gensim.models import Word2Vec
       sentences = [["cat", "say", "meow"], ["dog", "say", "woof"]]
       model = Word2Vec(sentences, min_count=1)
       say_vector = model['say']  # get vector for word

猜你喜欢

转载自www.cnblogs.com/jeshy/p/11434241.html