如何在Huggingface预训练的ALBERT模型中添加更多层?

时间:2020-04-02 01:27:21

标签: tensorflow huggingface-transformers

我正在尝试在经过预训练的ALBERT模型之后添加一个层。我想使用ALBERT预训练模型来生成令牌。

import tensorflow as tf
from transformers import AlbertTokenizer, TFAlbertForMaskedLM


tokenizer = AlbertTokenizer.from_pretrained('albert-base-v2')
model = TFAlbertForMaskedLM.from_pretrained('albert-base-v2')
input_ids = tf.constant(tokenizer.encode("This is a test! Nice to meet you![MASK]love you"))[
    None, :]  # Batch size 1
print(input_ids)
outputs = model(input_ids)
prediction_scores = outputs[0]
outputTokens = tf.math.argmax(prediction_scores, axis=2)
outputTokens = tf.keras.backend.eval(outputTokens[0])
outputTokens = tokenizer.decode(outputTokens)
print(outputTokens)

tokenModel = tf.keras.Sequential([
    tf.keras.layers.Dense(128,input_shape=input_ids.shape),
    model(),
    tf.keras.layers.Softmax()
])
tokenModel.summary()

哪个输出:

/test.py", line 19, in <module>
    model(),
TypeError: __call__() missing 1 required positional argument: 'inputs'

模型应该是什么样的?我无法将ALBERT模型添加为TensorFlow中模型的第一层。

0 个答案:

没有答案