Views
No views yet
transformers library on a subset of the UCSD Goodreads Book Graph dataset.1from transformers import AutoTokenizer, AutoModelForSequenceClassification
2import torch
3
4model_name = "nthapa/distilbert-goodreads-genres"
5tokenizer = AutoTokenizer.from_pretrained(model_name)
6model = AutoModelForSequenceClassification.from_pretrained(model_name)
7
8text = "A beautiful coming-of-age story with magic and dragons."
9inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True)
10with torch.no_grad():
11 outputs = model(**inputs)
12pred = outputs.logits.argmax(dim=-1).item()
13print(pred)