Giải thích văn bản và ảnh với LIME

Explainable AI trong Python

Fouad Trad

Machine Learning Engineer

Mô hình dựa trên văn bản

  • Xử lý và hiểu ngôn ngữ viết
  • Ví dụ: Phân tích cảm xúc
  • Mô hình hộp đen
  • LimeTextExplainer giải thích các mô hình này
    • Tìm tác động của từng từ lên dự đoán

Mô hình phân tích cảm xúc nhận đánh giá người dùng và dự đoán cảm xúc tương ứng (“Tích cực” hoặc “Tiêu cực”).

Explainable AI trong Python

Trình giải thích văn bản LIME

from lime.lime_text import LimeTextExplainer

text_instance = "This product has great features but a poor design."
def model_predict(instance): ... return class_probabilities
explainer = LimeTextExplainer()
exp = explainer.explain_instance(
text_instance,
model_predict
)
exp.as_pyplot_figure()

output_sentiment.png

Explainable AI trong Python

Mô hình dựa trên ảnh

  • Rất phức tạp
  • Diễn giải dữ liệu hình ảnh
  • Ví dụ: Phân loại món ăn
  • LimeImageExplainer giải thích các mô hình này
    • Tìm phần ảnh ảnh hưởng đến dự đoán

Mô hình phân loại món ăn nhận ảnh pizza và dự đoán loại món ăn trong ảnh.

Explainable AI trong Python

Trình giải thích ảnh LIME

from lime.lime_image import LimeImageExplainer

explainer = LimeImageExplainer()
explanation = explainer.explain_instance(
image,
model_predict,
num_samples=50
)
temp, _ = explanation.get_image_and_mask(
explanation.top_labels[0],
hide_rest=True
)

Ảnh kem.

Explainable AI trong Python

Trình giải thích ảnh LIME

from lime.lime_image import LimeImageExplainer

explainer = LimeImageExplainer()
explanation = explainer.explain_instance(
  image, 
  model_predict,  
  num_samples=50
)

temp, _ = explanation.get_image_and_mask(
  explanation.top_labels[0], 
  hide_rest=True
)

plt.imshow(temp)

Ảnh kem với các phần ít liên quan bị che đen.

Explainable AI trong Python

Luyện tập nào!

Explainable AI trong Python

Preparing Video For Download...