{"about":{"site":"https://codewithpapers.app","non_affiliation":"Code with Papers and Syntology are not affiliated with, endorsed by, or sponsored by Papers with Code, Meta, or the pwc-archive mirror.","licence":"CC BY-SA 4.0","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","attribution":"https://codewithpapers.app/attribution","modified":"archive material modified by Syntology; see the attribution page"},"url":"/paper/charformer-fast-character-transformers-via","title":"Charformer: Fast Character Transformers via Gradient-based Subword Tokenization","arxiv_id":"2106.12672","date":"2021-06-23","proceeding":"ICLR 2022 4","authors":["Yi Tay","Vinh Q. Tran","Sebastian Ruder","Jai Gupta","Hyung Won Chung","Dara Bahri","Zhen Qin","Simon Baumgartner","Cong Yu","Donald Metzler"],"abstract":"State-of-the-art models in natural language processing rely on separate rigid subword tokenization algorithms, which limit their generalization ability and adaptation to new settings. In this paper, we propose a new model inductive bias that learns a subword tokenization end-to-end as part of the model. To this end, we introduce a soft gradient-based subword tokenization module (GBST) that automatically learns latent subword representations from characters in a data-driven fashion. Concretely, GBST enumerates candidate subword blocks and learns to score them in a position-wise fashion using a block scoring network. We additionally introduce Charformer, a deep Transformer model that integrates GBST and operates on the byte level. Via extensive experiments on English GLUE, multilingual, and noisy text datasets, we show that Charformer outperforms a series of competitive byte-level baselines while generally performing on par and sometimes outperforming subword-based models. Additionally, Charformer is fast, improving the speed of both vanilla byte-level and subword-level Transformers by 28%-100% while maintaining competitive quality. We believe this work paves the way for highly performant token-free models that are trained completely end-to-end.","url_abs":"https://arxiv.org/abs/2106.12672v3","url_pdf":"https://arxiv.org/pdf/2106.12672v3.pdf","source":{"archive":"pwc-archive (Hugging Face), CC BY-SA 4.0","snapshot":"2025-07-28","licence_url":"https://creativecommons.org/licenses/by-sa/4.0/legalcode","row_kind":"abstracts"},"code_links":[{"paper_slug":"charformer-fast-character-transformers-via","repo_url":"https://github.com/google-research/google-research","is_official":1,"mentioned_in_paper":1,"mentioned_in_github":0,"framework":"tf","reach":null},{"paper_slug":"charformer-fast-character-transformers-via","repo_url":"https://github.com/lucidrains/charformer-pytorch","is_official":0,"mentioned_in_paper":0,"mentioned_in_github":1,"framework":"pytorch","reach":null}],"tasks":[{"task_slug":"inductive-bias","task_name":"Inductive Bias"},{"task_slug":"linguistic-acceptability","task_name":"Linguistic Acceptability"},{"task_slug":"natural-language-inference","task_name":"Natural Language Inference"},{"task_slug":"paraphrase-identification","task_name":"Paraphrase Identification"},{"task_slug":"semantic-textual-similarity","task_name":"Semantic Textual Similarity"},{"task_slug":"sentiment-analysis","task_name":"Sentiment Analysis"}],"methods":[{"method_slug":"absolute-position-encodings","method_name":"Absolute Position Encodings"},{"method_slug":"adam","method_name":"Adam"},{"method_slug":"attention","method_name":"Attention"},{"method_slug":"bpe","method_name":"BPE"},{"method_slug":"charformer","method_name":"Charformer"},{"method_slug":"dense-connections","method_name":"Dense Connections"},{"method_slug":"dropout","method_name":"Dropout"},{"method_slug":"gradient-based-subword-tokenization","method_name":"GBST"},{"method_slug":"gradient-based-subword-tokenization","method_name":"Gradient-Based Subword Tokenization"},{"method_slug":"label-smoothing","method_name":"Label Smoothing"},{"method_slug":"layer-normalization","method_name":"Layer Normalization"},{"method_slug":"linear-layer","method_name":"Linear Layer"},{"method_slug":"multi-head-attention","method_name":"Multi-Head Attention"},{"method_slug":"position-wise-feed-forward-layer","method_name":"Position-Wise Feed-Forward Layer"},{"method_slug":"residual-connection","method_name":"Residual Connection"},{"method_slug":"softmax","method_name":"Softmax"},{"method_slug":"transformer","method_name":"Transformer"}],"datasets_introduced":[],"methods_introduced":[{"slug":"charformer","name":"Charformer","full_name":"Charformer"},{"slug":"gradient-based-subword-tokenization","name":"Gradient-Based Subword Tokenization","full_name":"GBST"}],"results":[{"leaderboard":"/sota/linguistic-acceptability-on-cola","task":"Linguistic Acceptability","dataset":"CoLA","model":"Charformer-Tall","rank_in_archive_order":36,"of":43,"metrics":{"Accuracy":"51.8%"},"uses_additional_data":false},{"leaderboard":"/sota/natural-language-inference-on-multinli","task":"Natural Language Inference","dataset":"MultiNLI","model":"Charformer-Tall","rank_in_archive_order":35,"of":67,"metrics":{"Matched":"83.7","Mismatched":"84.4"},"uses_additional_data":false},{"leaderboard":"/sota/natural-language-inference-on-qnli","task":"Natural Language Inference","dataset":"QNLI","model":"Charformer-Tall","rank_in_archive_order":31,"of":43,"metrics":{"Accuracy":"91.0%"},"uses_additional_data":false},{"leaderboard":"/sota/paraphrase-identification-on-quora-question","task":"Paraphrase Identification","dataset":"Quora Question Pairs","model":"Charformer-Tall","rank_in_archive_order":3,"of":31,"metrics":{"Accuracy":"91.4","F1":"88.5"},"uses_additional_data":false},{"leaderboard":"/sota/semantic-textual-similarity-on-mrpc","task":"Semantic Textual Similarity","dataset":"MRPC","model":"Charformer-Tall","rank_in_archive_order":25,"of":45,"metrics":{"Accuracy":"87.5%","F1":"91.4"},"uses_additional_data":false},{"leaderboard":"/sota/semantic-textual-similarity-on-sts-benchmark","task":"Semantic Textual Similarity","dataset":"STS Benchmark","model":"Charformer-Tall","rank_in_archive_order":24,"of":66,"metrics":{"Pearson Correlation":"0.873"},"uses_additional_data":false},{"leaderboard":"/sota/sentiment-analysis-on-sst-2-binary","task":"Sentiment Analysis","dataset":"SST-2 Binary classification","model":"Charformer-Base","rank_in_archive_order":51,"of":87,"metrics":{"Accuracy":"91.6"},"uses_additional_data":false}],"syntology":{"atlas_url":"https://app.syntology.ai/?focus=2106.12672","mcp":{"get_harvested_code_for_paper":{"arxiv_id":"2106.12672"}},"developers":"https://syntology.ai/developers","read_at":"2026-09-24T18:15:14+00:00","read_at_is":"when the build read Syntology's graph, not when any sample ran","claim":"Per-sample execution status on synthesized fixtures; not a correctness claim about the paper. Samples come from repositories linked to the paper, official or community; repo_kind says which.","repos":[{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/google-research/google-research","reach":null},{"provenance":"external:paperswithcode_snapshot_2025-07-28","url":"https://github.com/lucidrains/charformer-pytorch","reach":null}],"summary":{"ran":3,"ran_draft_wrong":3,"ran_honours":1,"unverified":3},"by_repo_kind":{"listed":{"samples":10,"ran":7,"repositories":1}},"repo_kind_vocabulary":{"official":"The archive marks this repository official for the paper","named_in_paper":"The archive records that the paper mentions this repository; it is not marked official","listed":"In the archive's code links for this paper, not marked official and not recorded as mentioned in the paper","found_in_text":"Syntology found this repository in the paper's own text; whether it is the authors' implementation is not asserted","community":"Not in the archive's code links for this paper; a community repository Syntology harvested"},"n_pointer_only_for_licence":0,"samples":[{"code_sha256_prefix":"c943760822a257f4","entry":"DepthwiseConv1d","repo":"lucidrains/charformer-pytorch","repo_kind":"listed","path":"charformer_pytorch/charformer_pytorch.py","file_url":"https://github.com/lucidrains/charformer-pytorch/blob/HEAD/charformer_pytorch/charformer_pytorch.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"c943760822a257f4"}},{"code_sha256_prefix":"6b018c0bea889c94","entry":"GBST","repo":"lucidrains/charformer-pytorch","repo_kind":"listed","path":"charformer_pytorch/charformer_pytorch.py","file_url":"https://github.com/lucidrains/charformer-pytorch/blob/HEAD/charformer_pytorch/charformer_pytorch.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"6b018c0bea889c94"}},{"code_sha256_prefix":"72d15a97b98b8f2d","entry":"Pad","repo":"lucidrains/charformer-pytorch","repo_kind":"listed","path":"charformer_pytorch/charformer_pytorch.py","file_url":"https://github.com/lucidrains/charformer-pytorch/blob/HEAD/charformer_pytorch/charformer_pytorch.py","link_basis":"first_harvest_node","language":"python","status":"ran","verification_level":1,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"72d15a97b98b8f2d"}},{"code_sha256_prefix":"830a1e254dcbecbe","entry":"masked_mean","repo":"lucidrains/charformer-pytorch","repo_kind":"listed","path":"charformer_pytorch/charformer_pytorch.py","file_url":"https://github.com/lucidrains/charformer-pytorch/blob/HEAD/charformer_pytorch/charformer_pytorch.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":"invariant","behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"830a1e254dcbecbe"}},{"code_sha256_prefix":"a32cff24bac6b0fd","entry":"masked_mean","repo":"lucidrains/charformer-pytorch","repo_kind":"listed","path":"charformer_pytorch/charformer_pytorch.py","file_url":"https://github.com/lucidrains/charformer-pytorch/blob/HEAD/charformer_pytorch/charformer_pytorch.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"a32cff24bac6b0fd"}},{"code_sha256_prefix":"a78cb0f6103c1464","entry":"next_divisible_length","repo":"lucidrains/charformer-pytorch","repo_kind":"listed","path":"charformer_pytorch/charformer_pytorch.py","file_url":"https://github.com/lucidrains/charformer-pytorch/blob/HEAD/charformer_pytorch/charformer_pytorch.py","link_basis":"first_harvest_node","language":"python","status":"ran_honours","verification_level":1,"contract_check":"HONOURS","metamorphic_tier":null,"behaviour_fingerprint":true,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"a78cb0f6103c1464"}},{"code_sha256_prefix":"5a84e35f3a42e1eb","entry":"pad_to_multiple","repo":"lucidrains/charformer-pytorch","repo_kind":"listed","path":"charformer_pytorch/charformer_pytorch.py","file_url":"https://github.com/lucidrains/charformer-pytorch/blob/HEAD/charformer_pytorch/charformer_pytorch.py","link_basis":"first_harvest_node","language":"python","status":"ran_draft_wrong","verification_level":1,"contract_check":"MISDECLARED","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"5a84e35f3a42e1eb"}},{"code_sha256_prefix":"9632f809d8608df4","entry":"exists","repo":"lucidrains/charformer-pytorch","repo_kind":"listed","path":"charformer_pytorch/charformer_pytorch.py","file_url":"https://github.com/lucidrains/charformer-pytorch/blob/HEAD/charformer_pytorch/charformer_pytorch.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":"VIOLATES","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"9632f809d8608df4"}},{"code_sha256_prefix":"9f9701376e781647","entry":"lcm","repo":"lucidrains/charformer-pytorch","repo_kind":"listed","path":"charformer_pytorch/charformer_pytorch.py","file_url":"https://github.com/lucidrains/charformer-pytorch/blob/HEAD/charformer_pytorch/charformer_pytorch.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":null,"metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"9f9701376e781647"}},{"code_sha256_prefix":"f52d38502f83c1fb","entry":"next_divisible_length","repo":"lucidrains/charformer-pytorch","repo_kind":"listed","path":"charformer_pytorch/charformer_pytorch.py","file_url":"https://github.com/lucidrains/charformer-pytorch/blob/HEAD/charformer_pytorch/charformer_pytorch.py","link_basis":"first_harvest_node","language":"python","status":"unverified","verification_level":0,"contract_check":"HONOURS","metamorphic_tier":null,"behaviour_fingerprint":false,"licence":"MIT","inline_ok":true,"mcp_get_code":{"code_sha256":"f52d38502f83c1fb"}}]},"arxiv_metadata":null,"syntology_extracted_results":null}