使用 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'