[Tokenizers] Add a Hugging Face-style tokenizer factory

Aberta
#7,735 1 comentário 1 reação 0 responsáveis Ver no GitHub

Mantenedores costumam responder em até 1 dia

Ninguém assumiu esta issue ainda.

Avaliação

Dificuldade
4/5
Tempo estimado
3-5 dias
Facilidade para iniciantes
45/100
Tipo de issue
Funcionalidade
Clareza
Claramente especificada
Status de atividade
Ativa
Stack de tecnologia
csharp, huggingface

Direção de pesquisa

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.

Escrita pelo modelo de indexação a partir do texto da issue.

Descrição

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.

Linguagem predominante
C#
Estrelas
9.4k
Forks
2k
Merge médio
2d 18h
PRs com merge (30d)
64

Preparar o ambiente

Primeiros passos

  1. Leia a issue inteira e depois o guia de contribuição do projeto.
  2. Comente na issue dizendo que vai assumir — evita que duas pessoas façam o mesmo trabalho.
  3. Faça um fork do repositório e trabalhe em uma branch.
  4. Abra um pull request que referencie o número da issue.

Mais de dotnet/machinelearning

Todas as issues de dotnet/machinelearning

Issues semelhantes

Mais issues de C#

Receba novas issues na sua caixa de entrada

Um resumo curto de issues do GitHub para quem está começando.