Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

句向量特征提取的最佳实践 #160

Open
RingoD opened this issue Mar 26, 2021 · 0 comments
Open

句向量特征提取的最佳实践 #160

RingoD opened this issue Mar 26, 2021 · 0 comments

Comments

@RingoD
Copy link

RingoD commented Mar 26, 2021

我想通过 albert_chinese_tiny 对一句话进行特征提取,再用提取的向量做我自己的训练。
由于 albert_chinese_tiny 的输出是 (none, 512, 21148),因此我对其进行了 max pooling,输出为 (none, 512)
想请教这样的实践是否正确

if __name__ == '__main__':
    import keras_albert_model
    import keras_bert
    import numpy as np
    from tensorflow import keras
    model = keras_albert_model.load_brightmart_albert_zh_checkpoint('./albert_tiny_489k/')
    tokenizer = keras_bert.Tokenizer(keras_bert.load_vocabulary('./albert_tiny_489k/vocab.txt'))

    outputs = keras.layers.GlobalMaxPool1D(name='MaxPooling', data_format='channels_first')(model.outputs[0])

    model = keras.models.Model(inputs=model.inputs, outputs=outputs)
    model.summary()
    token, segment = tokenizer.encode('I like it', max_len=512)
    prediction = model.predict([np.array([token]), np.array([segment])])[0]
    print(prediction, prediction.shape)
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant