我在gensim中有一个word2vec模型,训练超过98892个文档.对于句子数组中不存在的任何给定句子(即我训练模型的集合),我需要用该句子更新模型,以便下次查询它会给出一些结果.我是这样做的:
new_sentence = ['moscow', 'weather', 'cold']
model.train(new_sentence)
Run Code Online (Sandbox Code Playgroud)
并将其打印为日志:
2014-03-01 16:46:58,061 : INFO : training model with 1 workers on 98892 vocabulary and 100 features
2014-03-01 16:46:58,211 : INFO : reached the end of input; waiting to finish 1 outstanding jobs
2014-03-01 16:46:58,235 : INFO : training on 10 words took 0.1s, 174 words/s
Run Code Online (Sandbox Code Playgroud)
现在,当我使用类似的new_sentence查询大多数肯定(as model.most_similar(positive=new_sentence))时,它会发出错误:
Traceback (most recent call last):
File "<pyshell#220>", line 1, in <module>
model.most_similar(positive=['moscow', 'weather', 'cold'])
File "/Library/Python/2.7/site-packages/gensim/models/word2vec.py", line 405, in most_similar
raise KeyError("word '%s' not …Run Code Online (Sandbox Code Playgroud) 我使用Gensim的文档语料库训练了一个word2vec模型.一旦模型正在训练,我正在编写以下代码以获得单词的原始特征向量说"视图".
myModel["view"]
Run Code Online (Sandbox Code Playgroud)
但是,我得到了一个单词的KeyError,这可能是因为它不存在作为word2vec索引的键列表中的键.在尝试获取原始特征向量之前,如何检查索引中的键是否退出?
在使用python gensim训练word2vec模型后,你如何找到模型词汇中的单词数量?
我是Tensorflow的新手我在iPython笔记本上运行Udacity的深度学习作业. 链接
它有一个错误.
AttributeError Traceback (most recent call last)
`<ipython-input-18-3446420b5935>` in `<module>`()
2
3 with tf.Session(graph=graph) as session:
----> 4 tf.global_variables_initializer().run()
AttributeError: 'module' object has no attribute 'global_variables_initializer'
Run Code Online (Sandbox Code Playgroud)
请帮忙!我怎样才能解决这个问题?谢谢.
受以下git和视频的启发,我正在尝试为我的域创建概念搜索,使用word2vec我的查询作为同义词过滤器.
给出以下文档结构:
{
"_index": "conversations",
"_type": "conversation",
"_id": "103130",
"_score": 0.97602403,
"_source": {
"context": "Welcome to our service, how can I help? do you offer a free trial",
"answer": "Yes we do. Here is a link for our trial account."
}
}
Run Code Online (Sandbox Code Playgroud)
我想迭代整个索引并提取"更高有效"(tf-idf?)的单词.
一旦我将拥有前100个单词列表,我将使用创建一个同义词过滤器word2vec.
我的问题是:如何使用ES Node JS客户端完成这项工作?
Word2vec似乎主要是针对原始语料库数据进行培训.然而,词形还原是许多语义相似性任务的标准预处理.我想知道是否有人在训练word2vec之前有使词库语法化的经验,以及这是否是一个有用的预处理步骤.
我刚开始使用Word2vec,我想知道如何才能找到最接近向量的单词.我有这个向量,它是一组向量的平均向量:
array([-0.00449447, -0.00310097, 0.02421786, ...], dtype=float32)
Run Code Online (Sandbox Code Playgroud)
是否有直接的方法在我的训练数据中找到与此向量最相似的单词?
或者唯一的解决方案是计算此向量与训练数据中每个单词的向量之间的余弦相似度,然后选择最接近的一个?
谢谢.
我想定义一个新词,其中包含来自两个(或更多)不同词的计数值。例如:
Words Frequency
0 mom 250
1 2020 151
2 the 124
3 19 82
4 mother 81
... ... ...
10 London 6
11 life 6
12 something 6
Run Code Online (Sandbox Code Playgroud)
我想将母亲定义为mom + mother:
Words Frequency
0 mother 331
1 2020 151
2 the 124
3 19 82
... ... ...
9 London 6
10 life 6
11 something 6
Run Code Online (Sandbox Code Playgroud)
这是一种替代定义具有某种含义的单词组的方法(至少对于我的目的而言)。
任何建议将不胜感激。
LSTM/RNN可用于文本生成. 这显示了为Keras模型使用预先训练的GloVe字嵌入的方法.
尝试了示例方法:
# Sample code to prepare word2vec word embeddings
import gensim
documents = ["Human machine interface for lab abc computer applications",
"A survey of user opinion of computer system response time",
"The EPS user interface management system",
"System and human system engineering testing of EPS",
"Relation of user perceived response time to error measurement",
"The generation of random binary unordered trees",
"The intersection graph of paths in trees",
"Graph minors …Run Code Online (Sandbox Code Playgroud) 我一直试图通过https://www.tensorflow.org/tutorials/recurrent来了解示例代码 ,您可以在https://github.com/tensorflow/models/blob/master/tutorials/rnn/ptb找到它./ptb_word_lm.py
(使用tensorflow 1.3.0.)
我总结(我认为是)关键部分,对于我的问题,如下:
size = 200
vocab_size = 10000
layers = 2
# input_.input_data is a 2D tensor [batch_size, num_steps] of
# word ids, from 1 to 10000
cell = tf.contrib.rnn.MultiRNNCell(
[tf.contrib.rnn.BasicLSTMCell(size) for _ in range(2)]
)
embedding = tf.get_variable(
"embedding", [vocab_size, size], dtype=tf.float32)
inputs = tf.nn.embedding_lookup(embedding, input_.input_data)
inputs = tf.unstack(inputs, num=num_steps, axis=1)
outputs, state = tf.contrib.rnn.static_rnn(
cell, inputs, initial_state=self._initial_state)
output = tf.reshape(tf.stack(axis=1, values=outputs), [-1, size])
softmax_w = tf.get_variable(
"softmax_w", [size, vocab_size], dtype=data_type()) …Run Code Online (Sandbox Code Playgroud) word2vec ×10
python ×6
gensim ×4
nlp ×3
lstm ×2
tensorflow ×2
javascript ×1
keras ×1
node.js ×1
text-mining ×1
wordnet ×1