1

我是 Julia 的新手,所以请原谅任何无知。

我希望能够在 Julia 中使用 Python 的 gensim 模块中的 Doc2Vec。但是,我遇到了一个问题,即来自 TaggedDocument python 对象的名称在分配给 Julia 中的变量时无法在自动转换中幸存下来。

这似乎是一个已知问题,但并不是我可以清楚地看到如何实施解决方案的问题。https://github.com/JuliaPy/PyCall.jl/issues/175

# import modules
gensim = pyimport("gensim")
Doc2Vec = pyimport("gensim.models.doc2vec")

# create simple "taggedDocuments"
a = Doc2Vec.TaggedDocument(words=gensim.utils.simple_preprocess("This is some text"), tags = ["tag01"])
# setup the Doc2Vec model
model = Doc2Vec.Doc2Vec(size= 100, min_count = 1, dm = 1)
# use the "taggedDocument" to populate the vocab attributes.
model.build_vocab(a)
# This results in - AttributeError("'tuple' object has no attribute 'words'")
# one idea i had was to try to re-add the names to the julia object
tnames = (:words, :tags);
c = (;zip(tnames, a)...)
# However when these get passed back into python the names are lost again
model.build_vocab(c)
# and again - AttributeError("'tuple' object has no attribute 'words'")

我目前的假设是,如果我可以强制来自的输出Doc2Vec.TaggedDocument()不被自动转换并存储为 PyObject,那么名称不应该丢失。对我来说,这似乎是 PyCall 的一部分,但在这里阅读类型部分:https ://github.com/JuliaPy/PyCall.jl并没有帮助。所以想知道是否有人有潜在的解决方案。

提前致谢。

4

0 回答 0