1. 程式人生 > 其它 >執行 shenweichen 的 GraphEmbedding 時報錯的解決方法(Resolution of some errors when running GraphEmbedding of shenweichen)

執行 shenweichen 的 GraphEmbedding 時報錯的解決方法(Resolution of some errors when running GraphEmbedding of shenweichen)

在安裝和執行 shenweichen 的 GraphEmbedding 圖向量相關的程式碼中,因為版本問題出現了各種錯誤,現在針對 deepwalk 和 line 兩種演算法出現的錯誤總結如下:

1.  安裝執行 python setup.py install 的時候出現錯誤:UnicodeDecodeError: 'gbk' codec can't decode byte 0xac in position 2110: illegal multibyte sequence

分析:這種錯誤,一般在讀取檔案的時候要加上檔案的編碼方式,檔案編碼方式的檢視,可以通過把檔案另存為,然後通過其中編碼的選項來看。如下圖所示。

 解決方法: setup.py第4行改成

with open("README.md", "r", encoding='utf-8') as fh:

參考資料:https://github.com/shenweichen/GraphEmbedding/issues/26

 

2. 執行 deepwalk_wiki.py 的時候出現錯誤:TypeError: __init__() got an unexpected keyword argument 'size' 

分析:word2vec 版本問題,需要把 size 改成 vector_size

解決方法:把 GraphEmbedding-master\build\lib\ge\models\deepwalk.py 中的以下內容進行修改

kwargs["size"] = embed_size

改成:

kwargs["vector_size"] = embed_size

參考資料:https://blog.csdn.net/weixin_43820665/article/details/117572613

 

3. 執行 deepwalk_wiki.py 的時候出現錯誤:TypeError: __init__() got an unexpected keyword argument 'iter'

分析:word2vec 版本問題,需要把 iter 改成 epochs

解決方法:把 GraphEmbedding-master\build\lib\ge\models\deepwalk.py 中的以下內容進行修改

kwargs["iter"] = iter

改成:

kwargs["epochs"] = iter

參考資料:https://blog.csdn.net/Wuli_jiejie/article/details/118712379

 

4. 執行 line_wiki.py 的時候出現錯誤:TypeError: reduce_sum() got an unexpected keyword argument 'keep_dims'

分析:tensorflow 版本問題,需要把 keep_dims 改成 keepdims

解決方法:把 GraphEmbedding-master\ge\models\line.py 中的以下內容進行修改

    first = Lambda(lambda x: tf.reduce_sum(
        x[0]*x[1], axis=-1, keep_dims=False), name='first_order')([v_i_emb, v_j_emb])
    second = Lambda(lambda x: tf.reduce_sum(
        x[0]*x[1], axis=-1, keep_dims=False), name='second_order')([v_i_emb_second, v_j_context_emb])

改成:

    first = Lambda(lambda x: tf.reduce_sum(
        x[0]*x[1], axis=-1, keepdims=False), name='first_order')([v_i_emb, v_j_emb])
    second = Lambda(lambda x: tf.reduce_sum(
        x[0]*x[1], axis=-1, keepdims=False), name='second_order')([v_i_emb_second, v_j_context_emb])

參考資料:https://stackoverflow.com/questions/59451666/typeerror-reduce-sum-got-an-unexpected-keyword-argument-keep-dims-in-tf-2-0