学习使用bilstm

    技术2022-07-11  82

    1. TypeError: Tensors in list passed to 'values' of 'ConcatV2' Op have types [bool, float32] that don't all match.

    出现地方:

    bilstm_crf_model = Embedding(input_dim=n_words + 1, output_dim=20, input_length=max_len, mask_zero=True)(input) # 20-dim embedding

    解决:删掉mask_zero=True

    bilstm_crf_model = Embedding(input_dim=n_words + 1, output_dim=20, input_length=max_len)(input) # 20-dim embedding

    2.TensorFlow与Keras,CUDA版本问题

    2.1 AttributeError: module 'keras.backend' has no attribute 'slice'

    2.2 attributeerror: 'node' object has no attribute 'output_masks'

    2.3 typeerror: __init__() got an unexpected keyword argument 'ragged'

    2.4 keras_contrib attributeerror: module 'tensorflow' has no attribute 'get_default_graph'

    2.5 importerror: cannot import name 'saving'

    2.6 futurewarning: from version 0.24, get_params will raise an attributeerror if a parameter cannot be retrieved as an instance attribute. previously it would return none. futurewarning)

    TensorFlow与Keras,CUDA,CUDNN,Python相应版本相对应很重要

    我这边目前是:CUDA Version 10.0.130,CUDNN:7.5 ,Python 3.6.10,GCC 7.3.0

    我安装的: TensorFlow:2.0.0,Keras:2.3.1

    查看CUDA的方法:

    第一种.:nvidia-smi

    第二种:

    cat /usr/local/cuda/version.txt

    查看CUDNN的方法:

    cat /usr/local/cuda/include/cudnn.h | grep CUDNN_MAJOR -A 2

    查看python,GCC版本:

    python 

    CUDA,CUDNN与TensorFlow版本对应:https://tensorflow.google.cn/install/source

    TensorFlow与Keras版本对应:https://docs.floydhub.com/guides/environments/

    3.KeyError: 'accuracy'

    出现地方:

    model.compile(optimizer="rmsprop", loss=crf.loss_function, metrics=["accuracy"]) history = model.fit(X_train, np.array(y_train), batch_size=32, epochs=5, validation_split=0.1, verbose=1) hist = pd.DataFrame(history.history) plt.figure(figsize=(12,12)) plt.plot(hist["acc"]) plt.plot(hist["val_acc"]) plt.show()

    解决:列名要注意

     

    plt.plot(hist["accuracy"]) plt.plot(hist["val_accuracy"])

     4.typeerror: load_model() missing 1 required positional argument: 'filepath'

    出现地方: model=load_model(filepath="../result/bi-lstm.h5")

    解决:

    filepath = "result/bi-lstm.h5" model = load_model(filepath)

    5.attributeerror: 'float' object has no attribute 'lower'

    出现原因:遇到了数据为NaN的情况

    解决:用空格去填充缺失值

    data=data.fillna('')

     

     

     

    Processed: 0.011, SQL: 9