name2gender

Using character sequences in first names to predict gender.

In this approach, I feed characters in a name one by one through a character level long short-term memory (LSTM) network built in PyTorch in the hopes of learning the latent space of all character sequences that denote gender without having to define them a priori.

Dependencies and Installation

(optional for GPU training)

  1. Clone repo

    git clone https://github.com/wstmac/name2gender.git
  2. Install Dependencies

    cd name2gender
    pip install -r requirements.txt

    * If you cannot successfully install pytorch, you can install it with conda command, which you can find https://pytorch.org/get-started/previous-versions/ e.g.

    conda install pytorch==1.7.1 torchvision==0.8.2 torchaudio==0.7.2 cudatoolkit=11.0 -c pytorch

Dataset Preparation

  1. go the the data directory by typing:

    cd data
  2. clean the first name and split the whole data into train, val and testing. Defualt split ratio are 0.8, 0.1, 0.1 for train, val and test respectively.

    python clean_data.py

Train

All logging files in the training process, e.g., log message, checkpoints, and snapshots, will be saved to ./results and ./logging directory.

  1. Modify config files.

    configuration.py
  2. Run training code (I have tunned some hyperparameters and set them as the default value. You can just run below command to train the network).

    python train.py

Hyperparamter tuning

I implement grid search for the hyperparameter tuning. You can run multiple hyperparameter combination with the bash script.

bash gird_search.sh