{"id":33373629,"url":"https://github.com/yuniko-software/qwen3-tokenizer-dotnet","last_synced_at":"2026-04-13T03:02:23.417Z","repository":{"id":320451271,"uuid":"1082160470","full_name":"yuniko-software/qwen3-tokenizer-dotnet","owner":"yuniko-software","description":"Multi-language BPE tokenizer implementation for Qwen3 models. Lightweight byte-pair encoding for C#/.NET","archived":false,"fork":false,"pushed_at":"2025-11-12T23:05:36.000Z","size":104,"stargazers_count":0,"open_issues_count":1,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-11-13T00:22:11.341Z","etag":null,"topics":["bpe-tokenizer","csharp","dotnet","embedding-models","huggingface","inference","llm","machine-learning","onnx","qwen","vector-database"],"latest_commit_sha":null,"homepage":"","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/yuniko-software.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-10-23T20:28:46.000Z","updated_at":"2025-11-12T22:58:31.000Z","dependencies_parsed_at":"2025-10-23T22:23:26.868Z","dependency_job_id":null,"html_url":"https://github.com/yuniko-software/qwen3-tokenizer-dotnet","commit_stats":null,"previous_names":["yuniko-software/qwen3-tokenizer","yuniko-software/qwen3-tokenizer-dotnet"],"tags_count":4,"template":false,"template_full_name":null,"purl":"pkg:github/yuniko-software/qwen3-tokenizer-dotnet","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuniko-software%2Fqwen3-tokenizer-dotnet","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuniko-software%2Fqwen3-tokenizer-dotnet/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuniko-software%2Fqwen3-tokenizer-dotnet/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuniko-software%2Fqwen3-tokenizer-dotnet/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/yuniko-software","download_url":"https://codeload.github.com/yuniko-software/qwen3-tokenizer-dotnet/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/yuniko-software%2Fqwen3-tokenizer-dotnet/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":285873538,"owners_count":27246054,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-11-22T02:00:05.934Z","response_time":64,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["bpe-tokenizer","csharp","dotnet","embedding-models","huggingface","inference","llm","machine-learning","onnx","qwen","vector-database"],"created_at":"2025-11-22T23:00:34.806Z","updated_at":"2025-11-22T23:01:07.676Z","avatar_url":"https://github.com/yuniko-software.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Yuniko.Software.Qwen3Tokenizer\n\n[![CI](https://github.com/yuniko-software/qwen3-tokenizer/actions/workflows/ci.yml/badge.svg)](https://github.com/yuniko-software/qwen3-tokenizer/actions/workflows/ci.yml)\n[![NuGet](https://img.shields.io/nuget/v/Yuniko.Software.Qwen3Tokenizer.svg)](https://www.nuget.org/packages/Yuniko.Software.Qwen3Tokenizer)\n[![NuGet Downloads](https://img.shields.io/nuget/dt/Yuniko.Software.Qwen3Tokenizer.svg)](https://www.nuget.org/packages/Yuniko.Software.Qwen3Tokenizer)\n\nNative .NET tokenizer implementation for Qwen3 models. Lightweight byte-pair encoding with HuggingFace integration.\n\n## Features\n\n- **Native .NET Implementation**: Qwen3 tokenizer built specifically for .NET applications\n- **Identical to HuggingFace**: Produces the same token IDs and outputs as the official HuggingFace tokenizer\n- **Qwen Model Family Support**: Compatible with all Qwen3 variants (LLM, Embedding, Reranker, and Vision-Language models)\n- **HuggingFace Integration**: Load tokenizer files directly from HuggingFace model repositories\n- **Configurable**: Customize tokenization behavior through options and custom file providers\n- **No External Dependencies**: Does not require Python or other runtime dependencies\n\n## Installation\n\n```bash\ndotnet add package Yuniko.Software.Qwen3Tokenizer\n```\n\nOr via Package Manager:\n\n```powershell\nInstall-Package Yuniko.Software.Qwen3Tokenizer\n```\n\n## Quick Start\n\n```csharp\nusing Yuniko.Software.Qwen3Tokenizer;\n\n// Load from HuggingFace model (specify if it's for an embedding model)\nvar tokenizer = await Qwen3Tokenizer.FromHuggingFaceAsync(\n    \"Qwen/Qwen3-0.6B\", \n    isForEmbeddingModel: false\n);\n\n// Encode text\nint[] tokenIds = tokenizer.Encode(\"Hello, world!\");\nConsole.WriteLine($\"Token IDs: [{string.Join(\", \", tokenIds)}]\");\nConsole.WriteLine($\"Token count: {tokenIds.Length}\");\n\n// Decode tokens\nstring decodedText = tokenizer.Decode(tokenIds);\nConsole.WriteLine($\"Decoded: {decodedText}\");\n```\n\n## Usage Examples\n\n### Basic Tokenization\n\n```csharp\n// For regular LLM models\nvar tokenizer = Qwen3Tokenizer.FromHuggingFace(\"Qwen/Qwen3-0.6B\", isForEmbeddingModel: false);\n\n// Encode text into token IDs\nint[] ids = tokenizer.Encode(\"The quick brown fox jumps over the lazy dog\");\n\n// Decode token IDs back to text\nstring text = tokenizer.Decode(ids);\n\n// Count tokens without full encoding\nint tokenCount = tokenizer.CountTokens(\"Some text to count\");\n```\n\n### Working with Embedding Models\n\n```csharp\n// For embedding models - adds pad token at the end when addSpecialTokens=true\nvar embeddingTokenizer = Qwen3Tokenizer.FromHuggingFace(\n    \"Qwen/Qwen3-Embedding-0.6B\", \n    isForEmbeddingModel: true\n);\n\n// With special tokens (includes pad token at the end)\nint[] withSpecial = embeddingTokenizer.Encode(\"Your text here\", addSpecialTokens: true);\n\n// Without special tokens\nint[] withoutSpecial = embeddingTokenizer.Encode(\"Your text here\", addSpecialTokens: false);\n\nConsole.WriteLine($\"With special tokens: {withSpecial.Length} tokens\");\nConsole.WriteLine($\"Without special tokens: {withoutSpecial.Length} tokens\");\n```\n\n### Decoding with Special Tokens\n\n```csharp\n// Encode text with special tokens\nstring chatMessage = \"\u003c|im_start|\u003euser\\nHello!\u003c|im_end|\u003e\";\nint[] tokens = tokenizer.Encode(chatMessage);\n\n// Decode with special tokens preserved\nstring withSpecial = tokenizer.Decode(tokens, skipSpecialTokens: false);\n\n// Decode with special tokens removed (default behavior)\nstring withoutSpecial = tokenizer.Decode(tokens, skipSpecialTokens: true);\n\nConsole.WriteLine($\"With special tokens: {withSpecial}\");\nConsole.WriteLine($\"Without special tokens: {withoutSpecial}\");\n```\n\n### Detailed Encoding Information\n\n```csharp\n// Get detailed information about tokens\nvar result = tokenizer.EncodeDetailed(\"Hello, world!\");\n\nfor (int i = 0; i \u003c result.Ids.Length; i++)\n{\n    Console.WriteLine($\"Token: '{result.Tokens[i]}' | ID: {result.Ids[i]} | \" +\n                     $\"Offset: {result.Offsets[i].Index}, Length: {result.Offsets[i].Length}\");\n}\n```\n\n### ONNX Runtime Integration\n\n```csharp\n// Prepare inputs for ONNX Runtime inference (dynamic length, no padding)\nvar inputs = tokenizer.PrepareForOnnx(\"Your input text here\");\n\n// Use with ONNX Runtime\n// Note: Some models (e.g., embedding models) may not require position_ids\nlong[] inputIds = inputs.InputIds;\nlong[] attentionMask = inputs.AttentionMask;\nlong[] positionIds = inputs.PositionIds;\n```\n\n### Loading from Local Files\n\n```csharp\n// Load tokenizer from local vocabulary and merges files\nvar tokenizer = Qwen3Tokenizer.FromFiles(\n    vocabPath: \"/path/to/vocab.json\",\n    mergesPath: \"/path/to/merges.txt\",\n    isForEmbeddingModel: false\n);\n```\n\n### Custom File Provider\n\n```csharp\n// Implement custom file provider for advanced scenarios\npublic class CustomFileProvider : ITokenizerFileProvider\n{\n    public (string VocabPath, string MergesPath) GetFiles()\n    {\n        // Custom logic to provide tokenizer files\n        return (\"/path/to/vocab.json\", \"/path/to/merges.txt\");\n    }\n\n    public Task\u003c(string VocabPath, string MergesPath)\u003e GetFilesAsync(\n        CancellationToken cancellationToken = default)\n    {\n        return Task.FromResult(GetFiles());\n    }\n}\n\n// Use custom provider\nvar tokenizer = Qwen3Tokenizer.FromProvider(new CustomFileProvider(), isForEmbeddingModel: false);\n```\n\n### Accessing Vocabulary and Token Information\n\n```csharp\n// Get vocabulary size\nint vocabSize = tokenizer.VocabularySize;\n\n// Access full vocabulary\nIReadOnlyDictionary\u003cstring, int\u003e vocab = tokenizer.Vocabulary;\n\n// Access added tokens (special tokens and others)\nIReadOnlyDictionary\u003cstring, int\u003e addedTokens = tokenizer.AddedTokens;\n\n// Access special token IDs\nIReadOnlySet\u003cint\u003e specialTokenIds = tokenizer.SpecialTokenIds;\n\n// Use predefined token constants\nConsole.WriteLine($\"IM_END token: {Qwen3Tokens.ImEnd} (ID: {Qwen3Tokens.ImEndTokenId})\");\nConsole.WriteLine($\"PAD token: {Qwen3Tokens.EndOfText} (ID: {Qwen3Tokens.EndOfTextTokenId})\");\nConsole.WriteLine($\"IM_START token: {Qwen3Tokens.ImStart} (ID: {Qwen3Tokens.ImStartTokenId})\");\n```\n\nFor more examples, see the [sample project](samples/Yuniko.Software.Qwen3Tokenizer.Sample).\n\n## Supported Models\n\nWorks with all Qwen3 model variants:\n- Qwen3 LLM models (text generation)\n- Qwen3-Embedding models (text embeddings)\n- Qwen3-Reranker models (document reranking)\n- Qwen3-VL models (vision-language)\n\n## Requirements\n\n- .NET 10.0 or later\n\n## License\n\nThis project is licensed under the Apache 2.0 License - see the [LICENSE](https://github.com/yuniko-software/qwen3-tokenizer/blob/main/LICENSE) file for details.\n\n## Contributing\n\nContributions are welcome! Please visit the [GitHub repository](https://github.com/yuniko-software/qwen3-tokenizer) for more information.\n\n## Support\n\nFor issues, questions, or suggestions, please open an issue on [GitHub](https://github.com/yuniko-software/qwen3-tokenizer/issues).\n\n---\n\n⭐ If you find this project useful, please consider giving it a star on GitHub! ⭐\n\nYour support helps make this project more visible to other developers who might benefit from a native .NET implementation of the Qwen3 tokenizer.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuniko-software%2Fqwen3-tokenizer-dotnet","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fyuniko-software%2Fqwen3-tokenizer-dotnet","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fyuniko-software%2Fqwen3-tokenizer-dotnet/lists"}