Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save freedomtowin/9a1b55b9808390108df4e1cbc3696be0 to your computer and use it in GitHub Desktop.
Save freedomtowin/9a1b55b9808390108df4e1cbc3696be0 to your computer and use it in GitHub Desktop.
Example of creating a Gist using Python
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