Downloads · 30 days
20
27% of all-time downloads
sartajbhuvaji/gutenberg-gpt2
gutenberg-gpt2 is a text classification model from sartajbhuvaji. Use it when you need a label for a piece of text. It is set up for transformers. The card lists the license as mit.
Downloads · 30 days
20
27% of all-time downloads
All-time downloads
74
Public
Parameters
124M
996 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors498 MB · 100%
From the Hugging Face model README
from transformers import GPT2ForSequenceClassification, GPT2Tokenizer
from datasets import load_dataset
from transformers import pipeline
import pandas as pd
# Load the model from Hugging Face
model = GPT2ForSequenceClassification.from_pretrained('sartajbhuvaji/gutenberg-gpt2')
tokenizer = GPT2Tokenizer.from_pretrained("sartajbhuvaji/gutenberg-gpt2")
# Create a text classification pipeline
classifier = pipeline("text-classification", model=model, tokenizer=tokenizer)
# Test the pipeline
result = classifier("This is a great book!")
print(result) # [{'label': 'LABEL_7', 'score': 0.8302432298660278}]
# Test the pipeline on a document
doc_id = 1
doc_text = df.loc[df['DocID'] == doc_id, 'Text'].values[0]
result = classifier(doc_text[:1024])
print(result) # [{'label': 'LABEL_4', 'score': 0.6285566091537476}]