Apply fastBPE to text data

I want to no how to learn bpe codes from text files and apply it to a text file (train, valid and test data)