Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sequence post processor #771

Merged
merged 6 commits into from
May 23, 2024
Merged

Add sequence post processor #771

merged 6 commits into from
May 23, 2024

Conversation

xenova
Copy link
Collaborator

@xenova xenova commented May 23, 2024

Adds support for updated Llama 3 tokenizer.

Closes #739

Example JavaScript code:

import { AutoTokenizer } from "@xenova/transformers";
const tokenizer = await AutoTokenizer.from_pretrained("Xenova/llama3-tokenizer-new");

console.log(tokenizer.encode('hello world')); // [128000, 15339, 1917]
console.log(tokenizer.encode('hello', 'world')); // [128000, 15339, 128000, 14957]

console.log(tokenizer('hello world', { return_tensor: false })); // { input_ids: [ 128000, 15339, 1917 ], attention_mask: [ 1, 1, 1 ] }
console.log(tokenizer('hello', { text_pair: 'world', return_tensor: false })); // { input_ids: [128000, 15339, 128000, 14957], attention_mask: [1, 1, 1, 1] }

console.log(tokenizer('hello world', { return_token_type_ids: true, return_tensor: false })); // { input_ids: [128000, 15339, 1917], attention_mask: [1, 1, 1], token_type_ids: [0, 0, 0] }
console.log(tokenizer('hello', { text_pair: 'world', return_token_type_ids: true, return_tensor: false })); // { input_ids: [128000, 15339, 128000, 14957], attention_mask: [1, 1, 1, 1], token_type_ids: [0, 0, 1, 1] }

Equivalent Python code:

from transformers import AutoTokenizer
tokenizer = AutoTokenizer.from_pretrained('Xenova/llama-3-tokenizer-new')

print(tokenizer.encode('hello world')) # [128000, 15339, 1917]
print(tokenizer.encode('hello', 'world')) # [128000, 15339, 128000, 14957]

print(tokenizer('hello world')) # {'input_ids': [128000, 15339, 1917], 'attention_mask': [1, 1, 1]}
print(tokenizer('hello', 'world')) # {'input_ids': [128000, 15339, 128000, 14957], 'attention_mask': [1, 1, 1, 1]}

print(tokenizer('hello world', return_token_type_ids=True)) # {'input_ids': [128000, 15339, 1917], 'token_type_ids': [0, 0, 0], 'attention_mask': [1, 1, 1]}
print(tokenizer('hello', 'world', return_token_type_ids=True)) # {'input_ids': [128000, 15339, 128000, 14957], 'token_type_ids': [0, 0, 1, 1], 'attention_mask': [1, 1, 1, 1]}

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@xenova xenova mentioned this pull request May 23, 2024
5 tasks
@xenova xenova merged commit db9250b into main May 23, 2024
4 checks passed
@xenova xenova deleted the add-sequence-post-processor branch May 23, 2024 09:42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unknown PostProcessor type: Sequence
2 participants