This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import sys | |
from collections import defaultdict | |
from tqdm import tqdm | |
import spotipy | |
from spotipy.oauth2 import SpotifyClientCredentials | |
CLIENT_ID = "9f64faf742764cf48d556ecc64ea2b1e" | |
CLIENT_SECRET = "56c58af2d3d845beb7102a466dd4f8a7" | |
USERNAME = "" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def name_to_tensor(name, cuda=False): | |
"""converts a name to a vectorized numerical input for use with a nn | |
each character is converted to a one hot (n, 1, 26) tensor | |
Args: | |
name (string): first name (e.g., "Ellis") | |
Return: | |
tensor (torch.tensor) | |
""" | |
name = clean_str(name) | |
tensor = torch.cuda.FloatTensor if cuda else torch.FloatTensor |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RNN(nn.Module): | |
"""Recurrent Neural Network | |
original source: https://goo.gl/12wiKB | |
Simple implementation of an RNN with two linear layers and a LogSoftmax | |
layer on the output | |
Args: | |
input_size: (int) size of data | |
hidden_size: (int) number of hidden units | |
output_size: (int) size of output | |
""" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def gender_features(name): | |
features = {} | |
features["last_letter"] = name[-1].lower() | |
features["first_letter"] = name[0].lower() | |
# names ending in -yn are mostly female, names ending in -ch are mostly male, so add 3 more features | |
features["suffix2"] = name[-2:] | |
features["suffix3"] = name[-3:] | |
features["suffix4"] = name[-4:] | |
return features |
NewerOlder