Word2Vec-如何摆脱“ TypeError:不可哈希类型:'list'”和“ AttributeError:dlsym(0x7fa8c57be020,AttachDebuggerTracing):未找到符号”?

基于TypeError: unhashable type: 'list'模块的AttributeError: dlsym(0x7fa8c57be020,AttachDebuggertracing): symbol not found实现创建模型时,遇到Word2Vecgensim错误。

每个条目都有三个部分,它们在列表中显示。而且,该模型包含三个条目,以进行演示。

这是我尝试过的:

model = Word2Vec(sentences=features,size=100,sg=1,window=3,min_count=1,iter=10,workers=Pool()._processes)

model.build_vocab(features)

model.train(features)

features的值为:

  [
    [
      ['permission.accESS_WIFI_STATE','permission.accESS_NETWORK_STATE','permission.READ_PHONE_STATE','permission.INTERNET','permission.CHANGE_WIFI_STATE'],['intent.action.MAIN','intent.action.BATTERY_CHANGED_actION','intent.action.SIG_STR','intent.action.BOOT_COMPLETED'],[]
    ],[
      ['permission.WRITE_EXTERNAL_STORAGE','permission.INSTALL_PACKAGES','permission.SEND_SMS','permission.DELETE_PACKAGES'],['intent.action.BOOT_COMPLETED','intent.action.USER_PRESENT','intent.action.PHONE_STATE','intent.action.MAIN'],'permission.accESS_FINE_LOCATION','permission.accESS_COARSE_LOCATION','permission.CALL_PHONE','permission.READ_CONTactS','permission.READ_SMS'],['intent.action.PHONE_STATE',[]
    ]
  ]

编辑:根据@gojomo的注释更正了特征向量的形式之后的错误堆栈跟踪。

Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py",line 1631,in settrace
Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py",in settrace
2019-12-13 12:24:34,519:gensim.models.base_any2vec:INFO - worker thread finished; awaiting finish of 3 more threads
2019-12-13 12:24:34,519:gensim.models.base_any2vec:INFO - worker thread finished; awaiting finish of 2 more threads
2019-12-13 12:24:34,519:gensim.models.base_any2vec:INFO - worker thread finished; awaiting finish of 1 more threads
Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py",519:gensim.models.base_any2vec:INFO - worker thread finished; awaiting finish of 0 more threads
2019-12-13 12:24:34,520:gensim.models.base_any2vec:INFO - EPOCH - 10 : training on 6 raw words (0 effective words) took 0.0s,0 effective words/s
    stop_at_frame,File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py",line 1711,in _locked_settrace
2019-12-13 12:24:34,520:gensim.models.base_any2vec:INFO - training on a 60 raw words (2 effective words) took 0.1s,21 effective words/s
    stop_at_frame,520:gensim.models.base_any2vec:WARNING - under 10 jobs per worker: consider setting a smaller `batch_words' for smoother alpha decay
    stop_at_frame,in _locked_settrace
    debugger.enable_tracing(apply_to_all_threads=True)
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py",line 482,in enable_tracing
    debugger.enable_tracing(apply_to_all_threads=True)
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py",in enable_tracing
    pydevd_tracing.set_trace_to_threads(self.dummy_trace_dispatch)
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd_tracing.py",line 241,in set_trace_to_threads
2019-12-13 12:24:34,521:gensim.utils:INFO - saving Word2Vec object under model/word2vec_model,separately None
    pydevd_tracing.set_trace_to_threads(self.dummy_trace_dispatch)
    debugger.enable_tracing(apply_to_all_threads=True)  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd_tracing.py",in set_trace_to_threads

  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py",in set_trace_to_threads
    result = lib.AttachDebuggertracing(
      File "/library/Developer/CommandLineTools/library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/ctypes/__init__.py",line 361,in __getattr__
result = lib.AttachDebuggertracing(
  File "/library/Developer/CommandLineTools/library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/ctypes/__init__.py",in __getattr__
    result = lib.AttachDebuggertracing(
  File "/library/Developer/CommandLineTools/library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/ctypes/__init__.py",in __getattr__
2019-12-13 12:24:34,521:gensim.utils:INFO - not storing attribute vectors_norm
        func = self.__getitem__(name)func = self.__getitem__(name)
  File "/library/Developer/CommandLineTools/library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/ctypes/__init__.py",line 366,in __getitem__
    func = self.__getitem__(name)
  File "/library/Developer/CommandLineTools/library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/ctypes/__init__.py",in __getitem__

2019-12-13 12:24:34,522:gensim.utils:INFO - not storing attribute cum_table
  File "/library/Developer/CommandLineTools/library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/ctypes/__init__.py",in __getitem__
    func = self._FuncPtr((name_or_ordinal,self))
    func = self._FuncPtr((name_or_ordinal,self))AttributeError: dlsym(0x7fed18f247e0,AttachDebuggertracing): symbol not found

AttributeError: dlsym(0x7fed18f247e0,AttachDebuggertracing): symbol not found
func = self._FuncPtr((name_or_ordinal,self))
Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py",in settrace
AttributeError: dlsym(0x7fed18d2ff70,AttachDebuggertracing): symbol not found
    stop_at_frame,524:gensim.utils:INFO - saved model/word2vec_model
    debugger.enable_tracing(apply_to_all_threads=True)
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py",in set_trace_to_threads
    result = lib.AttachDebuggertracing(
  File "/library/Developer/CommandLineTools/library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/ctypes/__init__.py",in __getattr__
    func = self.__getitem__(name)
  File "/library/Developer/CommandLineTools/library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/ctypes/__init__.py",self))
AttributeError: dlsym(0x7fed18a163b0,AttachDebuggertracing): symbol not found
Traceback (most recent call last):
  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd.py",in settrace
    stop_at_frame,in _locked_settrace
    stop_at_frame,in set_trace_to_threads
        pydevd_tracing.set_trace_to_threads(self.dummy_trace_dispatch)
result = lib.AttachDebuggertracing(  File "/Applications/PyCharm.app/Contents/plugins/python/helpers/pydev/pydevd_tracing.py",in set_trace_to_threads

  File "/library/Developer/CommandLineTools/library/Frameworks/Python3.framework/Versions/3.7/lib/python3.7/ctypes/__init__.py",self))
AttributeError: dlsym(0x7fed15fd5850,AttachDebuggertracing): symbol not found
    func = self._FuncPtr((name_or_ordinal,self))
AttributeError: dlsym(0x7fed18b09320,AttachDebuggertracing): symbol not found
wmpdh2007 回答:Word2Vec-如何摆脱“ TypeError:不可哈希类型:'list'”和“ AttributeError:dlsym(0x7fa8c57be020,AttachDebuggerTracing):未找到符号”?

Gensim的Word2Vec期望其语料库sentences是一个序列,其中每个单独的项都是一个字符串令牌列表。 (也就是说,这些字符串标记是单词。)

相反,您有一个列表(可以接受为序列),其中每个项目都是一个列表(也可以接受),但是每个列表都具有另一个 list –在进行Word2Vec培训时,这些项目中的每一项都应为字符串标记(单词)。

(我已将您的示例数据编辑为结构紧凑,以使嵌套级别更清晰。)

如果这些最里面的字符串列表是您真正的个人“句子”,则需要确保它们是您最外面的列表中的项目。

(另一方面,如果您确实希望将['intent.action.PHONE_STATE','intent.action.MAIN']之类的集群作为模型中的单个“单词”,则需要将该列表更改为单个字符串标记,以便可以Word2Vec和Python看起来像一个单词-因此是可哈希的密钥。)

本文链接:https://www.f2er.com/2931292.html

大家都在问