You should iterate over entire dataset to create your unique list of tokens(i.e. the vocab) . And assign a unique id to all of them. Next map your text input to these ids before passing to your model. Also, at the start of the model you should have an Embedding layer. Lookup nn.Embedding.from_pretrained for that purpose.