tensorflow-deep-learning icon indicating copy to clipboard operation
tensorflow-deep-learning copied to clipboard

Error in calculating most_wrong in 08_introduction_to_nlp_in_tensorflow.ipynb (its in video notebook also)

Open rkrish999 opened this issue 4 years ago • 1 comments

CURRENT CODE

#Create dataframe with validation sentences and best performing model predictions
val_df = pd.DataFrame({"text": val_sentences,
                       "target": val_labels,
                       "pred": model_6_pretrained_preds,
                       "pred_prob": tf.squeeze(model_6_pretrained_pred_probs)})
val_df.head()

# Find the wrong predictions and sort by prediction probabilities
most_wrong = val_df[val_df["target"] != val_df["pred"]].sort_values("pred_prob", ascending=False)
most_wrong[:10]

SUGGESTED NEW CODE

# Create dataframe with validation sentences and best performing model predictions, and prediction errors
val_df = pd.DataFrame({"text": val_sentences,
                       "target": val_labels,
                       "pred": model_6_pretrained_preds,
                       "pred_prob":tf.squeeze(model_6_pretrained_pred_probs), 
                       "pred_error":tf.abs(tf.squeeze(model_6_pretrained_pred_probs)-val_labels)})     #### FIX (need comma on prev line too)
val_df.head()   

# Find the wrong predictions and sort by prediction error
most_wrong = val_df[val_df["target"] != val_df["pred"]].sort_values("pred_error", ascending=False)
most_wrong.head(30)      #### FIX look at 30 so we see some cases on wrong 1s and wrong 0s
# Check from the bottom as well - we should see least wrong cases  - predictions just a little on the wrong side of 0.50
most_wrong[-10:]

rkrish999 avatar Nov 29 '21 23:11 rkrish999

thank you for this, will fix this week!

mrdbourke avatar Dec 06 '21 20:12 mrdbourke