Skip to content

Add new tokens to tokenizer before distillation with Model2Vec #3313

@aoezdTchibo

Description

@aoezdTchibo

Hello!

Is it possible to incorporate new tokens into the tokenizer before I distill the corresponding model with Model2Vec? Also, in the context of Zipf's Law, at which position in the vocabulary?

What I could do is the following:

tokens = ["my_special_token", "my_special_token2"]
tokenizer = AutoTokenizer.from_pretrained("intfloat/multilingual-e5-large")
tokenizer.add_tokens(tokens)
static_embedding = StaticEmbedding(
    tokenizer,
    embedding_dim=1024,
)
model = SentenceTransformer(
    modules=[static_embedding],
    device="cpu",
)
model.tokenizer.encode("my_special_token my_special_token2").tokens
# --> ['<s>', 'my_special_token', 'my_special_token2', '</s>']

However, this would be without distillation and corresponding weighting. The context is that we use the distilled model for product search, and we don't want to break down specific brand names further, but rather take them as they are, especially while fine-tuning.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions