[Tokenizers] Add a Hugging Face-style tokenizer factory

Abierto
#7,735 1 comentario 1 reacción 0 asignados Ver en GitHub

Los mantenedores suelen responder en 1 día

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
4/5
Tiempo estimado
3-5 días
Aptitud para principiantes
45/100
Tipo de issue
Nueva funcionalidad
Claridad
Bien especificado
Estado de actividad
Activo
Stack tecnológico
csharp, huggingface

Línea de trabajo

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.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

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.

Lenguaje dominante
C#
Estrellas
9.4k
Forks
2k
Merge medio
2 d 18 h
PR fusionados (30 d)
64

Preparar el entorno

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de dotnet/machinelearning

Todos los issues de dotnet/machinelearning

Issues similares

Más issues de C#

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.