无法运行gensims分布式LSI

时间:2019-06-13 09:58:31

标签: python python-3.6 gensim latent-semantic-indexing pyro4

问题描述

由于此failed to initialize distributed LSI (Failed to locate the nameserver)

,因此无法运行gensims分布式LSI

要复制的步骤/代码/语料库

from gensim.corpora import Dictionary
from gensim.models import TfidfModel, LsiModel
from gensim.similarities import Similarity
from gensim.test.utils import get_tmpfile
import sys
import time, traceback
import logging
logging.basicConfig(format='%(asctime)s : %(levelname)s : %(message)s', level=logging.INFO)

documents=['simple document','trying to reproduce lsi error','example document']
documents=[doc.split(' ') for doc in documents]    
dictionary = Dictionary(documents)
tfidf = TfidfModel(dictionary=dictionary)
corpus = [dictionary.doc2bow(doc) for doc in documents]
model = LsiModel(corpus, id2word=dictionary,num_topics=200,distributed=True)

日志跟踪:


2019-06-13 15:15:40,268 : INFO : adding document #0 to Dictionary(0 unique tokens: [])
2019-06-13 15:15:40,269 : INFO : built Dictionary(11 unique tokens: ['document', 'simple', 'error', 'lsi', 'reproduce']...) from 5 documents (total 17 corpus positions)
2019-06-13 15:15:40,292 : INFO : looking for dispatcher at PYRONAME:gensim.lsi_dispatcher
2019-06-13 15:15:42,414 : ERROR : failed to initialize distributed LSI (Failed to locate the nameserver)
---------------------------------------------------------------------------
ConnectionRefusedError                    Traceback (most recent call last)
~/anaconda3/lib/python3.6/site-packages/Pyro4/core.py in connect_and_handshake(conn)
    514                                                nodelay=config.SOCK_NODELAY,
--> 515                                                sslContext=sslContext)
    516                 conn = socketutil.SocketConnection(sock, uri.object)

~/anaconda3/lib/python3.6/site-packages/Pyro4/socketutil.py in createSocket(bind, connect, reuseaddr, keepalive, timeout, noinherit, ipv6, nodelay, sslContext)
    306         try:
--> 307             sock.connect(connect)
    308         except socket.error:

ConnectionRefusedError: [Errno 61] Connection refused

The above exception was the direct cause of the following exception:

CommunicationError                        Traceback (most recent call last)
~/anaconda3/lib/python3.6/site-packages/Pyro4/core.py in _locateNS(host, port, broadcast, hmac_key)
   2004     try:
-> 2005         proxy._pyroBind()
   2006         log.debug("located NS")

~/anaconda3/lib/python3.6/site-packages/Pyro4/core.py in _pyroBind(self)
    407         """
--> 408         return self.__pyroCreateConnection(True)
    409 

~/anaconda3/lib/python3.6/site-packages/Pyro4/core.py in __pyroCreateConnection(self, replaceUri, connected_socket)
    595             else:
--> 596                 connect_and_handshake(conn)
    597             if config.METADATA:

~/anaconda3/lib/python3.6/site-packages/Pyro4/core.py in connect_and_handshake(conn)
    548                         ce.__cause__ = x
--> 549                     raise ce
    550             else:

CommunicationError: cannot connect to ('localhost', 9090): [Errno 61] Connection refused

The above exception was the direct cause of the following exception:

NamingError                               Traceback (most recent call last)
~/anaconda3/lib/python3.6/site-packages/gensim/models/lsimodel.py in __init__(self, corpus, num_topics, id2word, chunksize, decay, distributed, onepass, power_iters, extra_samples, dtype)
    431                 logger.info("looking for dispatcher at %s", str(dispatcher._pyroUri))
--> 432                 dispatcher.initialize(
    433                     id2word=self.id2word, num_topics=num_topics, chunksize=chunksize, decay=decay,

~/anaconda3/lib/python3.6/site-packages/Pyro4/core.py in __getattr__(self, name)
    274             if not self._pyroMethods and not self._pyroAttrs:
--> 275                 self._pyroGetMetadata()
    276         if name in self._pyroAttrs:

~/anaconda3/lib/python3.6/site-packages/Pyro4/core.py in _pyroGetMetadata(self, objectId, known_metadata)
    614             try:
--> 615                 self.__pyroCreateConnection()
    616             except errors.PyroError:

~/anaconda3/lib/python3.6/site-packages/Pyro4/core.py in __pyroCreateConnection(self, replaceUri, connected_socket)
    587             else:
--> 588                 uri = _resolve(self._pyroUri, self._pyroHmacKey)
    589             # socket connection (normal or Unix domain socket)

~/anaconda3/lib/python3.6/site-packages/Pyro4/core.py in _resolve(uri, hmac_key)
   1909     if uri.protocol == "PYRONAME":
-> 1910         with _locateNS(uri.host, uri.port, hmac_key=hmac_key) as nameserver:
   1911             return nameserver.lookup(uri.object)

~/anaconda3/lib/python3.6/site-packages/Pyro4/core.py in _locateNS(host, port, broadcast, hmac_key)
   2011             e.__cause__ = x
-> 2012         raise e
   2013 

NamingError: Failed to locate the nameserver

During handling of the above exception, another exception occurred:

RuntimeError                              Traceback (most recent call last)
<ipython-input-5-d3777d1d3a97> in <module>()
     24 tfidf = TfidfModel(dictionary=dictionary)
     25 corpus = [dictionary.doc2bow(doc) for doc in documents]
---> 26 model = LsiModel(corpus, id2word=dictionary,num_topics=200,distributed=True)
     27 corpus = [model[tfidf[doc]] for doc in corpus]
     28 index_tmpfile = get_tmpfile("index")

~/anaconda3/lib/python3.6/site-packages/gensim/models/lsimodel.py in __init__(self, corpus, num_topics, id2word, chunksize, decay, distributed, onepass, power_iters, extra_samples, dtype)
    440                 # distributed version was specifically requested, so this is an error state
    441                 logger.error("failed to initialize distributed LSI (%s)", err)
--> 442                 raise RuntimeError("failed to initialize distributed LSI (%s)" % err)
    443 
    444         if corpus is not None:

RuntimeError: failed to initialize distributed LSI (Failed to locate the nameserver)

版本

Python 3.6.4
NumPy 1.15.4
SciPy 1.1.0
gensim 3.7.1
FAST_VERSION 1

0 个答案:

没有答案