--- task_categories: - text-generation language: - en - eng - pt - por - es - spa - fr - fra - zh - cmn - ja - jpn - de - deu - ru - rus - ar - arb - it - ita - pl - pol - ko - kor - code multilinguality: - multilingual pretty_name: Multilingual Tokenizer Benchmark size_categories: - 100K bool: for nl_parent_type in NATURAL_LANGUAGE_PARENT_TOKEN_TYPES: if tok_type in nl_parent_type: # This checks if tok_type is nl_parent_type OR a child return True return False def pygments_tokenize(code: str, language: str) -> list[str]: lexer = get_lexer_by_name(language, stripnl=True, stripall=True) tokens = lex(code, lexer) result = [] for tok_type, value in tokens: if _is_natural_language_like(tok_type): # Recursively tokenize comment or string content. Use the default english tokenizer. result.extend(word_tokenize(value)) else: # Tokenize symbol/keyword/identifier at surface level result.append(value) return [t for t in result if t.strip() != ''] #### Usage Example #### word_count_json = len(pygments_tokenize('{"hello": 1}', 'json')) word_count_python = len(pygments_tokenize("lambda x: print('hello')", "python")) ``` ### Per language stats | Code | Language | Num. of Subsets | Num. of Docs | Num. of Characters | Num. of Words | Data Types | |:-------|:----------------------|------------------:|---------------:|---------------------:|----------------:|:---------------------------------------------------------------------------------------------------------------------------------| | code | Programming Languages | 18 | 19820 | 90121858 | 18976907 | C, C++, CSS, Dockerfile, Go, HTML, JSON, Java, JavaScript, Lua, Markdown, PHP, Python, Rust, SQL, Shell, TeX, TypeScript | | en | English | 12 | 38155 | 61999845 | 12361906 | Biomedical, Books, Emoji Heavy, Finance, Legal, Live Speech, News, Scientific Papers, Social Networks, Subtitles, Web, Wikipedia | | pt | Portuguese | 10 | 30528 | 50195889 | 9603267 | Biomedical, Books, Legal, Live Speech, News, Scientific Papers, Social Networks, Subtitles, Web, Wikipedia | | ar | Arabic | 9 | 50539 | 45233908 | 8911565 | Biomedical, Books, Live Speech, Lyrics, News, Poetry, Subtitles, Web, Wikipedia | | es | Spanish | 9 | 25315 | 45168212 | 8420656 | Biomedical, Books, Legal, Live Speech, News, Scientific Papers, Subtitles, Web, Wikipedia | | fr | French | 9 | 26934 | 45185903 | 8594454 | Biomedical, Finance, Legal, Live Speech, News, Scientific Papers, Subtitles, Web, Wikipedia | | zh | Chinese | 9 | 47627 | 43209186 | 24276657 | Biomedical, Emoji Heavy, Finance, Legal, Live Speech, News, Subtitles, Web, Wikipedia | | ja | Japanese | 8 | 35950 | 35945203 | 19903904 | Books, Haiku, Legal, News, Scientific Papers, Subtitles, Web, Wikipedia | | de | German | 7 | 19740 | 35215590 | 5876322 | Biomedical, Legal, News, Scientific Papers, Subtitles, Web, Wikipedia | | it | Italian | 6 | 29414 | 30160296 | 5462293 | Biomedical, Legal, Scientific Papers, Subtitles, Web, Wikipedia | | ko | Korean | 6 | 28795 | 30376957 | 8362948 | Finance, Legal, News, Subtitles, Web, Wikipedia | | ru | Russian | 6 | 24329 | 30360746 | 5250785 | Biomedical, News, Scientific Papers, Subtitles, Web, Wikipedia | | pl | Polish | 5 | 15763 | 25168261 | 4131439 | Legal, News, Subtitles, Web, Wikipedia | ### Sourced datasets: | | HF Dataset | Num. Subsets | Languages | Data Types | |---:|:---------------------------------------------------------------------------------------------------------------------------------------------------|--------:|:-----------------------------------------------|:-------------------------------------------------------------------------------------------------------------------| | 0 | [bigcode/the-stack-smol](https://huggingface.co/datasets/bigcode/the-stack-smol) | 17 | code | C, C++, CSS, Dockerfile, Go, HTML, Java, JavaScript, Lua, Markdown, PHP, Python, Rust, SQL, Shell, TeX, TypeScript | | 1 | [badranx/opus_raw](https://huggingface.co/datasets/badranx/opus_raw) | 13 | ar, de, en, es, fr, it, ja, ko, pl, pt, ru, zh | Subtitles | | 2 | [HuggingFaceFW/fineweb-2](https://huggingface.co/datasets/HuggingFaceFW/fineweb-2) | 11 | ar, de, es, fr, it, ja, ko, pl, pt, ru, zh | Web | | 3 | [rntc/pubmed_preprocess](https://huggingface.co/datasets/rntc/pubmed_preprocess) | 8 | de, en, es, fr, it, pt, ru, zh | Biomedical | | 4 | [joelniklaus/Multi_Legal_Pile](https://huggingface.co/datasets/joelniklaus/Multi_Legal_Pile) | 6 | de, en, es, fr, it, pl | Legal | | 5 | [wikimedia/wikipedia](https://huggingface.co/datasets/wikimedia/wikipedia) | 6 | de, it, ja, ko, pl, ru | Wikipedia | | 6 | [almanach/HALvest](https://huggingface.co/datasets/almanach/HALvest) | 5 | de, es, fr, it, ru | Scientific Papers | | 7 | [premio-ai/TheArabicPile_Medical](https://huggingface.co/datasets/premio-ai/TheArabicPile_Medical) | 1 | ar | Biomedical | | 8 | [ImruQays/Rasaif-Classical-Arabic-English-Parallel-texts](https://huggingface.co/datasets/ImruQays/Rasaif-Classical-Arabic-English-Parallel-texts) | 1 | ar | Books | | 9 | [bigscience-data/roots_ar_ted_talks_iwslt](https://huggingface.co/datasets/bigscience-data/roots_ar_ted_talks_iwslt) | 1 | ar | Live Speech | | 10 | [premio-ai/TheArabicPile_Lyrics](https://huggingface.co/datasets/premio-ai/TheArabicPile_Lyrics) | 1 | ar | Lyrics | | 11 | [AIR-Bench/qa_news_ar](https://huggingface.co/datasets/AIR-Bench/qa_news_ar) | 1 | ar | News | | 12 | [premio-ai/TheArabicPile_Poetry](https://huggingface.co/datasets/premio-ai/TheArabicPile_Poetry) | 1 | ar | Poetry | | 13 | [bigscience-data/roots_ar_wikipedia](https://huggingface.co/datasets/bigscience-data/roots_ar_wikipedia) | 1 | ar | Wikipedia | | 14 | [bigcode/starcoderdata](https://huggingface.co/datasets/bigcode/starcoderdata) | 1 | code | JSON | | 15 | [AIR-Bench/qa_news_de](https://huggingface.co/datasets/AIR-Bench/qa_news_de) | 1 | de | News | | 16 | [orionweller/books_mds_incremental](https://huggingface.co/datasets/orionweller/books_mds_incremental) | 1 | en | Books | | 17 | [ElKulako/stocktwits-emoji](https://huggingface.co/datasets/ElKulako/stocktwits-emoji) | 1 | en | Emoji Heavy | | 18 | [Orion-zhen/dpo-codealpaca-emoji](https://huggingface.co/datasets/Orion-zhen/dpo-codealpaca-emoji) | 1 | en | Emoji Heavy | | 19 | [Orion-zhen/dpo-mathinstuct-emoji](https://huggingface.co/datasets/Orion-zhen/dpo-mathinstuct-emoji) | 1 | en | Emoji Heavy | | 20 | [Orion-zhen/dpo-physical-reasoning-emoji](https://huggingface.co/datasets/Orion-zhen/dpo-physical-reasoning-emoji) | 1 | en | Emoji Heavy | | 21 | [AIR-Bench/qa_finance_en](https://huggingface.co/datasets/AIR-Bench/qa_finance_en) | 1 | en | Finance | | 22 | [bigscience-data/roots_en_ted_talks_iwslt](https://huggingface.co/datasets/bigscience-data/roots_en_ted_talks_iwslt) | 1 | en | Live Speech | | 23 | [orionweller/cc_news_mds_incremental](https://huggingface.co/datasets/orionweller/cc_news_mds_incremental) | 1 | en | News | | 24 | [orionweller/arxiv_mds_incremental](https://huggingface.co/datasets/orionweller/arxiv_mds_incremental) | 1 | en | Scientific Papers | | 25 | [orionweller/pes2o_mds_incremental](https://huggingface.co/datasets/orionweller/pes2o_mds_incremental) | 1 | en | Scientific Papers | | 26 | [orionweller/reddit_mds_incremental](https://huggingface.co/datasets/orionweller/reddit_mds_incremental) | 1 | en | Social Networks | | 27 | [HuggingFaceFW/fineweb](https://huggingface.co/datasets/HuggingFaceFW/fineweb) | 1 | en | Web | | 28 | [orionweller/wikipedia_mds_incremental](https://huggingface.co/datasets/orionweller/wikipedia_mds_incremental) | 1 | en | Wikipedia | | 29 | [jorgeortizfuentes/spanish_books](https://huggingface.co/datasets/jorgeortizfuentes/spanish_books) | 1 | es | Books | | 30 | [bigscience-data/roots_es_ted_talks_iwslt](https://huggingface.co/datasets/bigscience-data/roots_es_ted_talks_iwslt) | 1 | es | Live Speech | | 31 | [LeoCordoba/CC-NEWS-ES](https://huggingface.co/datasets/LeoCordoba/CC-NEWS-ES) | 1 | es | News | | 32 | [eduagarcia/scielo_abstracts](https://huggingface.co/datasets/eduagarcia/scielo_abstracts) | 1 | es | Scientific Papers | | 33 | [bigscience-data/roots_es_wikipedia](https://huggingface.co/datasets/bigscience-data/roots_es_wikipedia) | 1 | es | Wikipedia | | 34 | [AIR-Bench/qa_finance_fr](https://huggingface.co/datasets/AIR-Bench/qa_finance_fr) | 1 | fr | Finance | | 35 | [bigscience-data/roots_fr_ted_talks_iwslt](https://huggingface.co/datasets/bigscience-data/roots_fr_ted_talks_iwslt) | 1 | fr | Live Speech | | 36 | [AIR-Bench/qa_news_fr](https://huggingface.co/datasets/AIR-Bench/qa_news_fr) | 1 | fr | News | | 37 | [kamarko/ccnews-french-subset](https://huggingface.co/datasets/kamarko/ccnews-french-subset) | 1 | fr | News | | 38 | [bigscience-data/roots_fr_wikipedia](https://huggingface.co/datasets/bigscience-data/roots_fr_wikipedia) | 1 | fr | Wikipedia | | 39 | [HiTZ/Multilingual-Medical-Corpus](https://huggingface.co/datasets/HiTZ/Multilingual-Medical-Corpus) | 1 | it | Biomedical | | 40 | [globis-university/aozorabunko-clean](https://huggingface.co/datasets/globis-university/aozorabunko-clean) | 1 | ja | Books | | 41 | [p1atdev/modern_haiku](https://huggingface.co/datasets/p1atdev/modern_haiku) | 1 | ja | Haiku | | 42 | [geniacllm/hanrei](https://huggingface.co/datasets/geniacllm/hanrei) | 1 | ja | Legal | | 43 | [kajuma/CC-news-2024-July-October-cleaned](https://huggingface.co/datasets/kajuma/CC-news-2024-July-October-cleaned) | 1 | ja | News | | 44 | [kunishou/J-ResearchCorpus](https://huggingface.co/datasets/kunishou/J-ResearchCorpus) | 1 | ja | Scientific Papers | | 45 | [BCCard/BCCard-Finance-Kor-QnA](https://huggingface.co/datasets/BCCard/BCCard-Finance-Kor-QnA) | 1 | ko | Finance | | 46 | [jihye-moon/klac_legal_aid_counseling](https://huggingface.co/datasets/jihye-moon/klac_legal_aid_counseling) | 1 | ko | Legal | | 47 | [joonhok-exo-ai/korean_law_open_data_precedents](https://huggingface.co/datasets/joonhok-exo-ai/korean_law_open_data_precedents) | 1 | ko | Legal | | 48 | [AIR-Bench/qa_news_ko](https://huggingface.co/datasets/AIR-Bench/qa_news_ko) | 1 | ko | News | | 49 | [daekeun-ml/naver-news-summarization-ko](https://huggingface.co/datasets/daekeun-ml/naver-news-summarization-ko) | 1 | ko | News | | 50 | [WiktorS/polish-news](https://huggingface.co/datasets/WiktorS/polish-news) | 1 | pl | News | | 51 | [winterkitsune/elka-pl-news](https://huggingface.co/datasets/winterkitsune/elka-pl-news) | 1 | pl | News | | 52 | [eduagarcia/pd_books_pt](https://huggingface.co/datasets/eduagarcia/pd_books_pt) | 1 | pt | Books | | 53 | [eduagarcia/LegalPT_dedup](https://huggingface.co/datasets/eduagarcia/LegalPT_dedup) | 1 | pt | Legal | | 54 | [bigscience-data/roots_pt_ted_talks_iwslt](https://huggingface.co/datasets/bigscience-data/roots_pt_ted_talks_iwslt) | 1 | pt | Live Speech | | 55 | [eduagarcia/cc_news_pt_v2](https://huggingface.co/datasets/eduagarcia/cc_news_pt_v2) | 1 | pt | News | | 56 | [eduagarcia/scielo_papers](https://huggingface.co/datasets/eduagarcia/scielo_papers) | 1 | pt | Scientific Papers | | 57 | [carolina-c4ai/corpus-carolina](https://huggingface.co/datasets/carolina-c4ai/corpus-carolina) | 1 | pt | Social Networks | | 58 | [tallesl/quinquilharia](https://huggingface.co/datasets/tallesl/quinquilharia) | 1 | pt | Social Networks | | 59 | [bigscience-data/roots_pt_wikipedia](https://huggingface.co/datasets/bigscience-data/roots_pt_wikipedia) | 1 | pt | Wikipedia | | 60 | [blinoff/medical_qa_ru_data](https://huggingface.co/datasets/blinoff/medical_qa_ru_data) | 1 | ru | Biomedical | | 61 | [AIR-Bench/qa_news_ru](https://huggingface.co/datasets/AIR-Bench/qa_news_ru) | 1 | ru | News | | 62 | [IlyaGusev/ru_news](https://huggingface.co/datasets/IlyaGusev/ru_news) | 1 | ru | News | | 63 | [mlsa-iai-msu-lab/ru_sci_bench](https://huggingface.co/datasets/mlsa-iai-msu-lab/ru_sci_bench) | 1 | ru | Scientific Papers | | 64 | [DavidLanz/medical_pretrain](https://huggingface.co/datasets/DavidLanz/medical_pretrain) | 1 | zh | Biomedical | | 65 | [Orion-zhen/dpo-emoji-zh](https://huggingface.co/datasets/Orion-zhen/dpo-emoji-zh) | 1 | zh | Emoji Heavy | | 66 | [Orion-zhen/dpo-ruozhiba-emoji](https://huggingface.co/datasets/Orion-zhen/dpo-ruozhiba-emoji) | 1 | zh | Emoji Heavy | | 67 | [shareAI/DPO-zh-en-emoji](https://huggingface.co/datasets/shareAI/DPO-zh-en-emoji) | 1 | zh | Emoji Heavy | | 68 | [Duxiaoman-DI/FinCorpus](https://huggingface.co/datasets/Duxiaoman-DI/FinCorpus) | 1 | zh | Finance | | 69 | [TigerResearch/tigerbot-law-plugin](https://huggingface.co/datasets/TigerResearch/tigerbot-law-plugin) | 1 | zh | Legal | | 70 | [bigscience-data/roots_zh_ted_talks_iwslt](https://huggingface.co/datasets/bigscience-data/roots_zh_ted_talks_iwslt) | 1 | zh | Live Speech | | 71 | [AIR-Bench/qa_news_zh](https://huggingface.co/datasets/AIR-Bench/qa_news_zh) | 1 | zh | News | | 72 | [liswei/news-collection-zhtw](https://huggingface.co/datasets/liswei/news-collection-zhtw) | 1 | zh | News | | 73 | [bigscience-data/roots_zh-cn_wikipedia](https://huggingface.co/datasets/bigscience-data/roots_zh-cn_wikipedia) | 1 | zh | Wikipedia |