Name generator web app

Joe Bender
4 min readFeb 6, 2021

Creating a full web app for my fantasy name generator

(originally posted February 10th, 2019)

This week I was able to build a web app with my TensorFlow name generator and put it online using GitHub’s Pages feature. Since I ended last week with a functioning model in Python and a very simple web app that only worked locally, I needed to figure out a number of things to get the app to where it is now.

First, I needed to figure out how to actually get the web app on the web and not just on my own computer. The first step was finding web hosting, and I remembered hearing something about how GitHub does some form of hosting for free. I found that I could turn any repository into a public site just by turning on the feature in the settings. I made a new repository to hold the site’s files and turned on the hosting feature, and I was able to access the site using this URL.

I was worried that there might be a problem with putting the model’s weight files here and loading them with TensorFlowJS, but it worked as smoothly as on my own computer. I was very excited to have my app online and that it was so simple to do. This may be due to my initial frustration last week when using TensorFlowJS and not being able to figure out how to load the model weights. I thought I would need some kind of complicated server setup to get it working, but the setup I found is very simple. Now I had the app online, but the app was not doing much. It just output the same list of names every time and didn’t demonstrate anything except the ability to memorize a few names. I needed to show the versatility of the app.

The app needed some randomness in its name generation. If it just used the top prediction for each generated letter, it would always come up with the same name given the same starting letter. I had come up with a solution for this a few weeks ago using my PyTorch model which involved tuning the softmax values of the output layer and using them as probabilities to sample a letter. I could have implemented this again in JavaScript, but I wanted to try a new approach that allowed the user to choose some settings. I knew I wanted each generated letter to have some chance of being the top prediction and some chance of being a different letter so that the generated names felt like real names but also had some variety. This is essentially an epsilon-greedy approach, which I learned about from reinforcement learning and which you can read more about here.

I decided on a method that would allow the user to choose not only the chance of choosing a random letter but also which set of letters would be sampled from. To choose the top prediction, the model takes the argmax of the softmax layer. I wanted to be able to see not just the top prediction but all the predictions sorted from most likely to least likely. There is a built-in argmax function in TensorFlowJS but no “argmaxes” that would give me what I was looking for, so I had to build my own in JavaScript. I added a setting to the app called “Choice Pool Size” that would select how many argmaxes would be included in the pool of letters to sample from. This approach worked surprisingly well and allowed for settings that generate names ranging from common to bizarre.

The web app was able to generate names very well, but the process was somewhat slow, at least when I tried it on my phone. I coded a new inference method that only fed partial sequences of letters through the model instead of padded sequences, which I mistakenly wrote in an earlier post that I thought I couldn’t do with the Keras LSTM. I also trained a model with fewer weights so that the inference calculations would happen faster. Even a much simpler model was able to learn enough to generate good names.

Finally, I used Bootstrap to make the page look nicer and to make it more responsive to various devices with different screen sizes. It’s been a while since I’ve done web design so using this framework made it much faster to get a professional looking site.

I put the web app to work to generate a name for my character in the game Pillars of Eternity who I named Calia. Apparently this is also the name of a fitness apparel company, so maybe I should make a business naming app next.

You can try generating your own names here.

--

--

Joe Bender

I write about machine learning, natural language processing, and learning in general.