Transformers is a Hugging Face software library for using pretrained transformer models and tokenizers. It can turn multilingual text into subword tokens or provide pretrained parameters for a model implemented in PyTorch. section 10.1.1 section 11.3.1
Common applications include:
- Tokenize English and French with XLMTokenizer, including subword pieces such as “fr” and “ench,” then map tokens to vocabulary indexes. section 10.1.1
- Load GPT-2XL through GPT2LMHeadModel.from_pretrained and extract its state dictionary for a compatible model. section 11.3.1
Loading a pretrained tokenizer
Install the library, create an XLM tokenizer with XLMTokenizer.from_pretrained("xlm-clm-enfr-1024"), and call tokenizer.tokenize("I don't speak French."). The result separates words and punctuation into reusable subword tokens.
Loading GPT-2XL parameters
Create GPT2LMHeadModel.from_pretrained('gpt2-xl'), obtain model_hf.state_dict(), and transpose selected Conv1d weights before copying them into a separately implemented linear-layer model.





