Show HN: Shakespeare in your browser – minimal AI in JavaScript

by logicalleeon 3/7/2025, 6:11 PMwith 0 comments

Want to train your own AI model? You've gotta start somewhere. If you've never tried it before, here is your chance!

Running an AI model has two parts, during the training phase you set weights, and during the inference phase you use the weights to predict words and other tokens (such as punctuation).

This minimal implementation in pure javascript runs right in your browser:

https://taonexus.com/mini-transformer-in-js.html

You can provide your own training data if you want: words.txt is a dictionary of punctuation and output tokens each on their own line and input.txt is a text corpus to train on.

If you load them from the server, you get words.txt from the top 2000 or so words that appear in in the Project Gutenberg free public domain corpus (as well as a few punctuation marks). For input.txt we've used a selection of 2000 lines of Shakespeare text.

After you finish training (you can stop early if you are impatient), on the Inference tab you can write a few words to have the model complete it for you.

Congratulations! After completing these steps you can now boast that you have trained your own AI model.