我是Julia编程语言的新手。我正在尝试在我的计算机上安装自适应跳过语法(AdaGram)模型。我面临以下问题。在训练模型之前,我们需要标记化文件和字典文件。现在我的问题是,tokenize.sh和dictionary.sh应该输入什么?请让我知道生成输出文件的实际方式以及其扩展名。
这是我指的网站链接:https : //github.com/sbos/AdaGram.jl。这与https://code.google.com/p/word2vec/完全相似
我想在我的 Spark 集群上训练关于 10G 新闻语料库的 word2vec 模型。下面是我的spark集群的配置?
但是我发现使用 Spark Mllib 训练 Word2vec 并没有充分利用集群的资源。例如: ubuntu中top命令的图片
如上图所示,一个worker只使用了100%的cpu,其他三个worker没有使用(所以不贴他们的图片),刚才我是如何训练一个关于2G新闻语料的word2vec模型,大约需要6h ,所以我想知道如何更有效地训练模型?提前谢谢大家:)
UPDATE1:以下命令是我在 spark-shell 中使用的
spark-shell \
--master spark://ip:7077 \
--executor-memory 70G \
--driver-memory 70G \
--conf spark.akka.frameSize=2000 \
--conf spark.driver.maxResultSize=0 \
--conf spark.default.parallelism=180
//import related packages
import org.apache.spark._
import org.apache.spark.mllib.linalg.{Vector, Vectors}
import org.apache.spark.mllib.feature.{Word2Vec, Word2VecModel}
//read about 10G newsdata corpus
val newsdata = sc.textFile("hdfs://ip:9000/user/bd/newsdata/*",600).map(line => line.split(" ").toSeq)
//Configure word2vec parameters
val word2vec = new Word2Vec()
word2vec.setMinCount(10)
word2vec.setNumIterations(10) …在gensim中,当我提供一个字符串作为训练doc2vec模型的输入时,我收到此错误:
TypeError('不知道如何处理uri%s'%repr(uri))
我提到了这个问题Doc2vec:TaggedLineDocument() 但仍然对输入格式有疑问.
documents = TaggedLineDocument('myfile.txt')
myFile.txt是否应该将令牌作为列表列表,或者每个文档或字符串的每行中都有单独的列表?
For eg - 我有2份文件.
Doc 1:机器学习是从模式识别研究演变而来的计算机科学的一个子领域.
Doc 2:Arthur Samuel将机器学习定义为"让计算机具备学习能力的研究领域".
那么,它应该是myFile.txt什么样的?
案例1:每行中每个文档的简单文本
机器学习是从模式识别研究演变而来的计算机科学的一个子领域
Arthur Samuel将机器学习定义为一个让计算机具备学习能力的研究领域
案例2:列表中包含每个文档的标记
[ ["Machine", "learning", "is", "a", "subfield", "of", "computer", "science", "that", "evolved", "from", "the", "study", "of", "pattern", "recognition"],
["Arthur", "Samuel", "defined", "machine", "learning", "as", "a", "Field", "of", "study", "that", "gives", "computers" ,"the", "ability", "to", "learn"] ]
Run Code Online (Sandbox Code Playgroud)
案例3:单独行中每个文档的标记列表
["Machine", "learning", "is", "a", "subfield", "of", "computer", "science", "that", "evolved", "from", "the", "study", "of", "pattern", "recognition"]
["Arthur", …Run Code Online (Sandbox Code Playgroud) 我一直在尝试运行一个示例,说明如何从 python 的 gensim 库中使用 word2vec,但我不断收到此错误
ValueError: The truth value of an array with more than one element is ambiguous. Use a.any() or a.all()
Run Code Online (Sandbox Code Playgroud)
这是我的代码,它只是一个简单的例子:
from gensim.models import Word2Vec
sentences = [['first', 'sentence'], ['second', 'sentence']]
# train word2vec on the two sentences
model = Word2Vec(sentences, min_count=1)
Run Code Online (Sandbox Code Playgroud)
注意:我已经确保安装了 gensim 及其所有依赖项。
当我使用GoogleNews-vectors-negative300.bin或尝试使用带有维基百科数据集语料库(1 GB)的 Gensim 训练模型时,出现内存错误。我的系统中有 4GB RAM。有没有办法绕过这个。
我们可以将它托管在像 AWS 这样的云服务上以获得更好的速度吗?
我正在尝试通过 Gensim 在波斯语上制作一个 word2vec 模型,它以“空格”作为字符分隔符,我使用 python 3.5。我遇到的问题是我提供了一个文本文件作为输入,它返回一个模型,该模型仅包含每个字符而不是单词。我还将输入作为推荐的单词列表提供:
它对我不起作用,我认为它不考虑句子中的单词序列,所以它是不正确的。
我对我的输入做了一些预处理,其中包括:
将多个空格合并为一个,
通过拆分空格来标记化
删除少于 3 个字符的单词删除停用词
我把文本给了 word2vec,它给了我正确的结果,但我在 python 上需要它,所以我的选择仅限于使用 Gensim。
此外,我尝试在 gensim 上加载由 word2vec 源创建的模型,但出现错误,因此我需要通过 Gensim 创建 word2vec 模型。
我的代码是:
wfile = open('aggregate.txt','r')
wfileRead = wfile.read()
model = word2vec.Word2Vec(wfileRead , size=100)
model.save('Word2Vec.txt')
Run Code Online (Sandbox Code Playgroud) 我正在使用 Gensim 加载我的 fasttext.vec文件,如下所示。
m=load_word2vec_format(filename, binary=False)
Run Code Online (Sandbox Code Playgroud)
不过,我只是困惑,如果我需要加载.bin的文件来执行的命令一样m.most_similar("dog"),m.wv.syn0,m.wv.vocab.keys()等?如果是这样,该怎么做?
或者 .bin文件对于执行这种余弦相似度匹配并不重要?
请帮我!
在Python 3.7中实现Word2Vec时,我遇到了与折旧有关的意外情况。我的问题是,word2vec gensim python中关于“ most_like”的折旧警告到底是什么?
目前,我遇到以下问题。
DeprecationWarning:调用已弃用most_similar(方法将在4.0.0中删除,改用self.wv.most_similar())。model.most_similar('hamlet')FutureWarning:不建议将issubdtype的第二个参数从from int转换np.signedinteger为。将来,它将被视为np.int32 == np.dtype(int).type。如果np.issubdtype(vec.dtype,np.int):
请帮忙解决这个问题?任何帮助表示赞赏。我是python的新手。
我尝试过的代码如下。
import re
from gensim.models import Word2Vec
from nltk.corpus import gutenberg
sentences = list(gutenberg.sents('shakespeare-hamlet.txt'))
print('Type of corpus: ', type(sentences))
print('Length of corpus: ', len(sentences))
for i in range(len(sentences)):
sentences[i] = [word.lower() for word in sentences[i] if re.match('^[a-zA-Z]+', word)]
print(sentences[0]) # title, author, and year
print(sentences[1])
print(sentences[10])
model = Word2Vec(sentences=sentences, size = 100, sg = 1, window = 3, min_count = 1, iter …Run Code Online (Sandbox Code Playgroud) 我有一个半结构化的数据集,每一行都属于一个用户:
id, skills
0,"java, python, sql"
1,"java, python, spark, html"
2, "business management, communication"
Run Code Online (Sandbox Code Playgroud)
之所以半结构化是因为只能从580个唯一值的列表中选择以下技能。
我的目标是聚集用户,或根据相似的技能组找到相似的用户。我尝试使用Word2Vec模型,该模型为识别相似的技能组提供了很好的结果-例如。
model.most_similar(["Data Science"])
Run Code Online (Sandbox Code Playgroud)
给我 -
[('Data Mining', 0.9249375462532043),
('Data Visualization', 0.9111810922622681),
('Big Data', 0.8253220319747925),...
Run Code Online (Sandbox Code Playgroud)
这为我提供了一个很好的模型,用于识别个人技能而不是技能组。如何利用Word2Vec模型提供的向量来成功地对相似用户的组进行聚类?
我正在使用Jupyter Notebook和word2vec模型在Google Cloud Platform上运行VM。我有以下代码片段:
from gensim.models import Word2Vec
amazon_word2vec = Word2Vec(model, min_count=1, size=100)
Run Code Online (Sandbox Code Playgroud)
并导致错误:
AttributeError: module 'boto' has no attribute 'plugin'
Run Code Online (Sandbox Code Playgroud)
以上问题的解决方法是什么?
python google-compute-engine google-cloud-platform word2vec jupyter-notebook
word2vec ×10
gensim ×6
python ×5
nlp ×2
apache-spark ×1
data-mining ×1
doc2vec ×1
fasttext ×1
julia ×1
python-2.7 ×1
python-3.x ×1