使用roberta模型无法定义模型.compile或summary

Using roberta model cannot define the model .compile or summary

使用roberta模型进行情感分析无法定义模型.compile或summary

from transformers import RobertaTokenizer, RobertaForSequenceClassification
from transformers import  BertConfig
tokenizer = RobertaTokenizer.from_pretrained('roberta-base')
robertamodel = RobertaForSequenceClassification.from_pretrained('roberta-base',num_labels=7)
print('\nBert Model',robertamodel.summary())
loss = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
metric = tf.keras.metrics.SparseCategoricalAccuracy('0accuracy')
optimizer = tf.keras.optimizers.Adam(learning_rate=1e-5,epsilon=1e-08)

robertamodel.compile(loss=loss,optimizer=optimizer,metrics=[metric])
print(robertamodel.summary())

我遇到了这些错误 'RobertaForSequenceClassification' 对象没有属性 'summary' 'RobertaForSequenceClassification' 对象没有属性 'compile'

Roberta 基于 pytorch。查看辅助函数 TFRobertaModel 将其转换为张量流模型。