7. Assignment VII: Deep Learning#

7.1. Question 1#

Use the dataset, DEMO_DATA/chinese_name_gender.txt and create a Chinese name gender classifier using the deep learning method. You need to include a few important considerations in the creation of the deep learning classifer.

  1. Please consult the lecture notes and experiment with different architectures of neural networks. In particular, please try combinations of the following types of network layers:

    • dense layer

    • embedding layer

    • RNN layer

    • bidirectional layer

  2. Please include regularizations and dropbouts to avoid the issue of overfitting.

  3. Please demonstrate how you find the optimal hyperparameters for the neural network using keras-tuner.

  4. Please perform post-hoc analyses on a few cases using LIME for more interpretive results.

Hide code cell source
plot_model(model1, show_shapes=True)
../_images/e72f4b4f72ddd7b810efc1d61e71fb5c7a9d35aea3c4beaf8f9a65cbd005711d.png
Hide code cell source
plot_model(model2, show_shapes=True)
../_images/98f42d3676f0be2951f34ea63b47f03c053d4951239d8ac6fc29ceb761fabf6a.png
Hide code cell source
plot_model(model3)
../_images/97564f1242025b40055dda47ae090c24926b638fac17a9a3ed6b472f833efa0f.png
plot_model(model4)
Hide code cell output
../_images/9af9f31ca09e2e98bcedd53b14ed881408a50f137ab92abea94775021a080a2b.png
Hide code cell source
plot_model(model5)
../_images/1b687f45b3f10d561e3fc4d8605977ea656d213dc0daef7fd04f8d0e9c715bd4.png
from lime.lime_text import LimeTextExplainer

explainer = LimeTextExplainer(class_names=['Male'], char_level=True)
Hide code cell source
exp = explainer.explain_instance(
X_test_texts[text_id], model_predict_pipeline, num_features=100, top_labels=1)
exp.show_in_notebook(text=True)
Hide code cell source
exp = explainer.explain_instance(
'陳宥欣', model_predict_pipeline, num_features=100, top_labels=1)
exp.show_in_notebook(text=True)
Hide code cell source
exp = explainer.explain_instance(
'李安芬', model_predict_pipeline, num_features=2, top_labels=1)
exp.show_in_notebook(text=True)
Hide code cell source
exp = explainer.explain_instance(
'林月名', model_predict_pipeline, num_features=2, top_labels=1)
exp.show_in_notebook(text=True)
Hide code cell source
exp = explainer.explain_instance(
'蔡英文', model_predict_pipeline, num_features=2, top_labels=1)
exp.show_in_notebook(text=True)