def load_with_vocab(fin, vocab, dtype=np.float32):
    """
    Refer to :func:`word_embedding_loader.loader.glove.load_with_vocab` for the API.
    """
    line = next(fin)
    data = line.strip().split(b' ')
    assert len(data) == 2
    size = int(data[1])
    arr = np.empty((len(vocab), size), dtype=dtype)
    arr.fill(np.NaN)
    for line in fin:
        token, v = _load_line(line, dtype, size)
        if token in vocab:
            arr[vocab[token], :] = v
    if np.any(np.isnan(arr)):
        raise ParseError(b"Some of vocab was not found in word embedding file")
    return arr
def load_with_vocab ( fin , vocab , dtype = np . float32 ) : line = next ( fin ) data = line . strip ( ) . split ( b' ' ) assert len ( data ) == 2 size = int ( data [ 1 ] ) arr = np . empty ( ( len ( vocab ) , size ) , dtype = dtype ) arr . fill ( np . NaN ) for line in fin : token , v = _load_line ( line , dtype , size ) if token in vocab : arr [ vocab [ token ] , : ] = v if np . any ( np . isnan ( arr ) ) : raise ParseError ( b"Some of vocab was not found in word embedding file" ) return arr
Refer to :func:`word_embedding_loader.loader.glove.load_with_vocab` for the API.