N-Grammer: Augmenting Transformers with latent n-grams

Transformer models have recently emerged as one of the foundational models in natural language processing, and as a byproduct, there is significant recent interest and investment in scaling these models. However, the training and inference costs of these large Transformer language models are prohibitive, thus necessitating more research in identifying more efficient variants. In this work, we propose a simple yet effective modification to the Transformer architecture inspired by the literature in statistical language modeling, by augmenting the model with n-grams that are constructed from a discrete latent representation of the text sequence. We evaluate our model, the N-Grammer on language modeling on the C4 data-set as well as text classification on the SuperGLUE data-set, and find that it outperforms several strong baselines such as the Transformer and the Primer. We open-source our model for reproducibility purposes in Jax.

PDF Abstract

Results from the Paper


Task Dataset Model Metric Name Metric Value Global Rank Result Benchmark
Question Answering BoolQ N-Grammer 343M Accuracy 65 # 42
Language Modelling C4 N-Grammer 343M Perplexity 14.79 # 7
Language Modelling C4 N-Grammer 288M Perplexity 15.01 # 8
Natural Language Inference CommitmentBank N-Grammer 343M F1 59.7 # 8
Accuracy 67.9 # 14
Question Answering COPA N-Grammer 343M Accuracy 60.0 # 56
Question Answering MultiRC N-Grammer 343M F1 62 # 19
EM 11.3 # 12
Common Sense Reasoning ReCoRD N-Grammer 343M F1 29.9 # 34
EM 28.9 # 35
Natural Language Inference RTE N-Grammer 343M Accuracy 59.2% # 73
Coreference Resolution Winograd Schema Challenge N-Grammer 343M Accuracy 68.3 # 37
Word Sense Disambiguation Words in Context N-Grammer 343M Accuracy 56.1 # 22

Methods