有两种方法可以加载预训练的单词嵌入,一种是用C编译的,另一种是用python编译的。我在python中有自我训练的嵌入,这些嵌入有:
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Client Name*</label>
<div class="col-md-9 col-sm-9 col-xs-12">
<?php
$sql = "select vname from vendor";
// NEW LINE (selects the number that was sent in the form)
$sql += !empty($_POST['rno']) && is_numeric($_POST['rno'])?" and rno={$_POST['rno']}":'';
$stmt = $conn->prepare ( $sql );
$result = $stmt->execute();
?>
<select class="select2_single form-control" tabindex="-1" name="vname" id="vname" onChange="getinfo(this.value)" required>
<option value=""></option>
<?php
foreach($stmt as $row){
?>
<option value="<?php echo $row['vname'];?>"><?php echo $row['vname'];?></option>
<?php
}
?>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-md-3 col-sm-3 col-xs-12">Return No</label>
<div class="col-md-9 col-sm-9 col-xs-12">
<input type="number" class="form-control" placeholder="Return No" name="rno" id = "rno" required="required">
</div>
但是,当我将它们加载到单词词典中时(与从第三方进行预训练的嵌入方法相同),由于与其他加载方法不同,因此会出错。
model = gensim.models.Word2Vec.load('transcript-vectors.pickle')
答案 0 :(得分:1)
我阅读了一些其他使用预训练的笔记本的笔记本,如果它们没有经过C语言训练,则需要使用model.wv [word]作为索引,而不是word_vec()函数。
正确的循环:
embeddings_index = dict()
for word in model.wv.vocab: #model.wv[word] | model.word_vec(word)
embeddings_index[word] = model.wv[word]
print('Loaded %s vectors' % len(embeddings_index))
@Soumitri Chilakamarri在他的评论中进一步证实了这一点。