Created
November 17, 2024 23:16
-
-
Save freedomtowin/256fd5b782695e94de7997a97a2450b3 to your computer and use it in GitHub Desktop.
Example of creating a Gist using Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import torch | |
from transformers import AutoTokenizer | |
checkpoint = "distilbert-base-uncased-finetuned-sst-2-english" | |
tokenizer = AutoTokenizer.from_pretrained(checkpoint) | |
sequence = "I've been waiting for a HuggingFace course my whole life." | |
tokens = tokenizer.tokenize(sequence) | |
print("Tokens:", tokens) | |
ids = tokenizer.convert_tokens_to_ids(tokens) | |
input_ids = torch.tensor([ids]) | |
print("Input IDs:", input_ids) | |
final_inputs = tokenizer.prepare_for_model(ids) | |
print("Final Inputs:", final_inputs) | |
decoded_inputs = tokenizer.decode(final_inputs['input_ids']) | |
print("Decoded Inputs:", decoded_inputs) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment