Downloads · 30 days
16
6% of all-time downloads
sartajbhuvaji/gutenberg-bert-encoder-decoder
gutenberg-bert-encoder-decoder 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 apache-2.0.
Downloads · 30 days
16
6% of all-time downloads
All-time downloads
257
Public
Parameters
247M
2 GB on disk
Likes
0
Public
Click a slice to open those files.
.pth990 MB · 50%
From the Hugging Face model README
from transformers import EncoderDecoderModel, BertTokenizer
from datasets import load_dataset
from transformers import pipeline
import torch
# Load the encoder-decoder model and tokenizer from Hugging Face
encoder_decoder_model = EncoderDecoderModel.from_pretrained('sartajbhuvaji/gutenberg-bert-encoder-decoder')
tokenizer = BertTokenizer.from_pretrained("sartajbhuvaji/gutenberg-bert-encoder-decoder")
# Define the number of labels for your classification task
num_labels = 10
# Load the custom classification head
classification_model = EncoderDecoderForClassification(encoder_decoder_model, num_labels)
classification_model.load_state_dict(torch.load("gutenberg-classification-head.pth"))
# Now create a text classification pipeline
classifier = pipeline("text-classification", model=classification_model, tokenizer=tokenizer)
# Test the pipeline with a single sentence
result = classifier("This is a great book!")
print(result)
# Load sample dataset
dataset = load_dataset("sartajbhuvaji/gutenberg", split="100")
df = dataset.to_pandas()
# Test the pipeline on a document from a DataFrame (assuming `df` is a pandas DataFrame with text data)
doc_id = 1
doc_text = df.loc[df['DocID'] == doc_id, 'Text'].values[0]
result = classifier(doc_text[:1024])
print(result)