The data set the author works with in chapter 9 contains a long list of names. If you look more closely at the structure of the data file you will see that each row in the data file contains a name, a gender, and a count of how many times that name appeared.
In this assignment you are going to modify the author's transformer-based name generator into a transformer-based gender classifier. Given a person's name, your model will predict the gender of that person.
In the author's code for the name generator we ended up ignoring the frequency information in the data file. This lead the model to be biased toward generating names that were more typical of the large number of uncommon names in the data set.
For this assignment we will rebalance the data set back in favor of the most common names. To do this you will insert most of the names in the file into your data set multiple times to reflect their actual frequency in the population. Names with an original frequency of 5 will appear once in your data set, and names with an original frequency of n will appear n/5 times in your data set.
Your model should consist of the following layers:
Before you train your model you should prepare a separate training set and test set. Since many names will be repeated in your data set, don't worry too much about the fact that some names may be repeated in both subsets.
After training your model on the training set, pick a random sample of 50 names from your test set, run them through the model, and print both the actual and predicted genders for those people.
Here is an example that I generated from my solution:
name actual pred
natalie F F
octavia F F
carver M M
braxton M M
alexus F M
alessia F F
aidan M M
camden M M
brooklyn F F
willa F F
evan M M
bianca F F
sara F F
kailani F F
delaney F F
amina F F
jaxxon M M
calvin M M
emma F F
ayla F F
adam M M
kailyn F F
kingston M M
jocelyn F F
francisco M M
amelia F F
nicholas M M
isaac M M
ayub M M
ryder M M
lou F M
brooklyn F F
theo M M
vincent M M
mustafa M M
sebastian M M
brinley F F
charlotte F F
daxton M M
naomi F F
deziah F M
jazleen F F
mikayla F F
tilley F F
karter M M
yeilyn F F
franz M M
jacob M M
precious F M
shylo F M
Most of the examples that the model gets wrong are pretty tricky to get right: alexus, lou, deziah, precious, and shylo. Given this, you should probably declare success as soon as you get to an accuracy of 90%.