[Tokenizers] Add a Hugging Face-style tokenizer factory

Đang mở
#7,735 1 bình luận 1 reaction 0 người được giao Xem trên GitHub

Maintainer thường phản hồi trong vòng 1 ngày

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
45/100
Loại issue
Tính năng
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
csharp, huggingface
Lĩnh vực
ai-infra-agents, tooling

Hướng nghiên cứu

The issue is about adding a factory to the Microsoft.ML.Tokenizers library. Start by examining the existing tokenizer implementations (e.g., BpeTokenizer, WordPieceTokenizer) and their constructors. Look at how Hugging Face tokenizer.json files are structured and map their configuration to .NET types. The work involves reading configuration, detecting tokenizer type, and handling unsupported features. Check related issues #7383 and #7384 for context. 'Done' means a factory method can load a tokenizer from a model directory or tokenizer.json file with proper error reporting.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

area-Tokenizers enhancement untriaged

Is your feature request related to a problem? Please describe.
Migrating a custom Hugging Face tokenizer to .NET requires the caller to know the tokenizer implementation, identify and load the correct vocabulary and merge files, interpret tokenizer configuration, and manually map those resources to the corresponding Microsoft.ML.Tokenizers type. In Python, AutoTokenizer.from_pretrained(...) handles this discovery and construction from a model directory or tokenizer configuration.

This gap makes migration harder and encourages application-specific loader code. #7384 can document the current process, but documentation alone does not provide an equivalent loading abstraction.

Describe the solution you'd like
Provide a factory API that creates the appropriate tokenizer from Hugging Face tokenizer artifacts, for example from a model directory or tokenizer.json file. The factory should:

  • Detect the supported tokenizer implementation and construct the corresponding .NET tokenizer.
  • Read the relevant tokenizer configuration, vocabulary, merges, special tokens, normalizer, pre-tokenizer, post-processor, and decoder settings when supported.
  • Report unsupported tokenizer types or configuration sections explicitly rather than silently changing behavior.
  • Allow callers to inspect the concrete tokenizer or its capabilities when implementation-specific behavior is needed.

The final API shape does not need to match Python, but the migration experience should be comparable to AutoTokenizer.from_pretrained(...) for supported formats.

Describe alternatives you've considered
Callers can identify the tokenizer type themselves and write adapters around individual tokenizer constructors. A migration guide can explain those steps, but every consuming library still has to reproduce the detection, configuration mapping, validation, and error handling.

Additional context
This request was identified while splitting the feedback in #7383, which originated in microsoft/semantic-kernel#9793. Related format-specific gaps should remain separately trackable, while this issue covers the complete discovery-and-construction experience.

[!NOTE]
This issue was drafted with AI assistance.

Ngôn ngữ chính
C#
Star
9.4k
Fork
2k
Merge trung bình
2 ngày 18 giờ
Pull request đã merge (30 ngày)
64

Chuẩn bị môi trường

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của dotnet/machinelearning

Tất cả issue của dotnet/machinelearning

Issue tương tự

Thêm issue về C#

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.