当前位置:  开发笔记 > 编程语言 > 正文

安装gensim时大量警告

如何解决《安装gensim时大量警告》经验,为你挑选了2个好方法。

我在Python中安装了gensim(通过pip).安装结束后,我收到以下警告:

C:\ Python27\lib\site-packages\gensim\utils.py:855:UserWarning:检测到Windows; 别名chunkize到chunkize_serial warnings.warn("检测到Windows;别名chunkize到chunkize_serial")

我怎么能纠正这个?

由于此警告,我无法从gensim.models导入word2vec.

我有以下配置:Python 2.7,gensim-0.13.4.1,numpy-1.11.3,scipy-0.18.1,pattern-2.6.



1> Roland Pihla..:

导入gensim 之前,您可以使用此代码禁止显示消息:

import warnings
warnings.filterwarnings(action='ignore', category=UserWarning, module='gensim')

import gensim


谁知道警告的重点是什么?它还会在安装后第一次在代码中导入gensim时弹出.

2> 小智..:

我认为这不是一个大问题.Gensim只是让你知道它会将chunkize别名化为不同的函数,因为你使用了特定的操作系统.

从gensim.utils查看此代码

if os.name == 'nt':
    logger.info("detected Windows; aliasing chunkize to chunkize_serial")

    def chunkize(corpus, chunksize, maxsize=0, as_numpy=False):
        for chunk in chunkize_serial(corpus, chunksize, as_numpy=as_numpy):
            yield chunk
else:
    def chunkize(corpus, chunksize, maxsize=0, as_numpy=False):
    """
    Split a stream of values into smaller chunks.
    Each chunk is of length `chunksize`, except the last one which may be smaller.
    A once-only input stream (`corpus` from a generator) is ok, chunking is done
    efficiently via itertools.

    If `maxsize > 1`, don't wait idly in between successive chunk `yields`, but
    rather keep filling a short queue (of size at most `maxsize`) with forthcoming
    chunks in advance. This is realized by starting a separate process, and is
    meant to reduce I/O delays, which can be significant when `corpus` comes
    from a slow medium (like harddisk).

    If `maxsize==0`, don't fool around with parallelism and simply yield the chunksize
    via `chunkize_serial()` (no I/O optimizations).

    >>> for chunk in chunkize(range(10), 4): print(chunk)
    [0, 1, 2, 3]
    [4, 5, 6, 7]
    [8, 9]

    """
    assert chunksize > 0

    if maxsize > 0:
        q = multiprocessing.Queue(maxsize=maxsize)
        worker = InputQueue(q, corpus, chunksize, maxsize=maxsize, as_numpy=as_numpy)
        worker.daemon = True
        worker.start()
        while True:
            chunk = [q.get(block=True)]
            if chunk[0] is None:
                break
            yield chunk.pop()
    else:
        for chunk in chunkize_serial(corpus, chunksize, as_numpy=as_numpy):
            yield chunk

推荐阅读
360691894_8a5c48
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有