title: Plot Confusion Matrix from Roberta Model
body: <p>I wrote the text classification code with two classes using the Roberta model and now I want to draw the confusion matrix.
  How to go about plotting the confusion matrix based of a Roberta model?</p>
  <pre><code>RobertaTokenizer = RobertaTokenizer.from_pretrained('roberta-base',do_lower_case=False)
  roberta_model = TFRobertaForSequenceClassification.from_pretrained('roberta-base',num_labels=2)
  
  input_ids=[]
  attention_masks=[]
  
  for sent in sentences:
      bert_inp=RobertaTokenizer.encode_plus(sent,add_special_tokens = True,max_length =128,pad_to_max_length = True,return_attention_mask = True)
      input_ids.append(bert_inp['input_ids'])
      attention_masks.append(bert_inp['attention_mask'])
      
  
  input_ids=np.asarray(input_ids)
  attention_masks=np.array(attention_masks)
  labels=np.array(labels)
  #split
  train_inp,val_inp,train_label,val_label,train_mask,val_mask=train_test_split(input_ids,labels,attention_masks,test_size=0.5)
  print('Train inp shape {} Val input shape {}\nTrain label shape {} Val label shape {}\nTrain attention mask shape {} Val attention mask shape {}'.format(train_inp.shape,val_inp.shape,train_label.shape,val_label.shape,train_mask.shape,val_mask.shape))
  #
  log_dir='tensorboard_data/tb_roberta'
  model_save_path='/usr/local/lib/python3.6/dist-packages/tensorflow/python/keras/callbacks.py'
  
  callbacks = [tf.keras.callbacks.ModelCheckpoint(filepath=model_save_path,save_weights_only=True,monitor='val_loss',mode='min',save_best_only=True),keras.callbacks.TensorBoard(log_dir=log_dir)]
  
  print('\nBert Model',roberta_model.summary())
  
  loss = tf.keras.losses.SparseCategoricalCrossentropy(from_logits=True)
  metric = tf.keras.metrics.SparseCategoricalAccuracy('accuracy')
  optimizer = tf.keras.optimizers.Adam(learning_rate=2e-5,epsilon=1e-08)
  
  roberta_model.compile(loss=loss,optimizer=optimizer,metrics=[metric])
  
  history=roberta_model.fit([train_inp,train_mask],train_label,batch_size=16,epochs=2,validation_data=([val_inp,val_mask],val_label),callbacks=callbacks)
  </code></pre>