Created
November 15, 2024 00:12
-
-
Save freedomtowin/9a1b55b9808390108df4e1cbc3696be0 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, AutoModelForSequenceClassification#, AutoModel | |
checkpoint = "distilbert-base-uncased-finetuned-sst-2-english" | |
tokenizer = AutoTokenizer.from_pretrained(checkpoint) | |
# model = AutoModel.from_pretrained(checkpoint) | |
model_seq_classification = AutoModelForSequenceClassification.from_pretrained(checkpoint) | |
raw_inputs = [ | |
"I've been waiting for a HuggingFace course my whole life.", | |
"I hate this so much!", | |
] | |
inputs = tokenizer(raw_inputs, padding=True, truncation=True, return_tensors="pt") | |
print("Inputs:", inputs) | |
output = model_seq_classification(**inputs) | |
print("Logits:", output.logits) | |
predictions = torch.nn.functional.softmax(output.logits, dim=1) | |
print("Predictions:", predictions) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment