Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CHAPTER-4] Mistake in code #124

Open
10 tasks
kasrahabib opened this issue Oct 11, 2023 · 0 comments
Open
10 tasks

[CHAPTER-4] Mistake in code #124

kasrahabib opened this issue Oct 11, 2023 · 0 comments

Comments

@kasrahabib
Copy link

Information

I think there is a small mistake in the code while calling the function for plot_confusion_matrix(y_preds, y_true, labels)

The problem arises in chapter:

  • Introduction
  • Text Classification
  • Transformer Anatomy
  • [0 ] Multilingual Named Entity Recognition
  • Text Generation
  • Summarization
  • Question Answering
  • Making Transformers Efficient in Production
  • Dealing with Few to No Labels
  • Training Transformers from Scratch
  • Future Directions

Describe the bug

from sklearn.metrics import ConfusionMatrixDisplay, confusion_matrix

def plot_confusion_matrix(y_preds, y_true, labels):
    cm = confusion_matrix(y_true, y_preds, normalize="true")
    fig, ax = plt.subplots(figsize=(6, 6))
    disp = ConfusionMatrixDisplay(confusion_matrix=cm, display_labels=labels)
    disp.plot(cmap="Blues", values_format=".2f", ax=ax, colorbar=False)
    plt.title("Normalized confusion matrix")
    plt.show()

Here is the next line that, I think, contains the mistake, where you call the function:

plot_confusion_matrix(df_tokens["labels"], df_tokens["predicted_label"],
                      tags.names)

As you can you, while calling the function, you pass the true labels as predicted and predicted as true.

Expected behavior

I think the intended usage is as follows:

plot_confusion_matrix(df_tokens["predicted_label"], df_tokens["labels"]
                      tags.names)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant