()
得到实体名字的嵌入
    :return:
得到实体名字的嵌入
    :return:
得到实体名字的嵌入 : return :
def entity_embedding():
    '''
    得到实体名字的嵌入
    :return:
    '''
    entity_id=get_entity_id()
    print(len(entity_id))
    id_embedding = pd.read_pickle('data/id_embedding.pkl')
    entity_index = {}
    embedding_matrix = np.random.normal(size= (len(entity_id)+1, 768))
    for i, en in enumerate(entity_id):
        entity_index[en] = i+1
        vec=[]
        for id in entity_id[en]:
            vec.append(id_embedding[id])
        vec=np.mean(vec,axis=0)
        embedding_matrix[i+1]=vec
    pd.to_pickle(entity_index,'data/ER_entity_index.pkl')
    np.save('data/ER_entity_embedding.npy',embedding_matrix)
    print(embedding_matrix.shape)
def entity_embedding ( ) : entity_id = get_entity_id ( ) print ( len ( entity_id ) ) id_embedding = pd . read_pickle ( 'data/id_embedding.pkl' ) entity_index = { } embedding_matrix = np . random . normal ( size = ( len ( entity_id ) + 1 , 768 ) ) for i , en in enumerate ( entity_id ) : entity_index [ en ] = i + 1 vec = [ ] for id in entity_id [ en ] : vec . append ( id_embedding [ id ] ) vec = np . mean ( vec , axis = 0 ) embedding_matrix [ i + 1 ] = vec pd . to_pickle ( entity_index , 'data/ER_entity_index.pkl' ) np . save ( 'data/ER_entity_embedding.npy' , embedding_matrix ) print ( embedding_matrix . shape )