Downloads · 30 days
2
8% of all-time downloads
DeclanBracken/BERT_uncased_for_binary_TO_recycling_classification_augmented
BERT_uncased_for_binary_TO_recycling_classification_augmented is a text classification model from DeclanBracken. Use it when you need a label for a piece of text. It is set up for transformers.
- Developed by: Declan Bracken, Armando Ordorica, Michael Santorelli, Paul Zhou - Model type: Transformer - Language(s) (NLP): English - Finetuned from model: BERTbaseuncased
Downloads · 30 days
2
8% of all-time downloads
All-time downloads
25
Public
Parameters
109M
438 MB on disk
Likes
0
Public
Click a slice to open those files.
.safetensors438 MB · 100%
From the Hugging Face model README
Create a custom class to load in the model, the label encoder, and the BERT tokenizer used for training (bert-base-uncased) as below. use the tokenizer to tokenize any input string you'd like, then pass it through the model to get outputs.
class BERTClassifier: def init(self, model_identifier): # Load the tokenizer from bert base uncased self.tokenizer = BertTokenizer.from_pretrained('bert-base-uncased')
# Load the config
config = AutoConfig.from_pretrained(model_identifier)
# Load the model
self.model = BertForSequenceClassification.from_pretrained(model_identifier, config=config)
self.model.eval() # Set the model to evaluation mode
# Load the label encoder
encoder_url = f'https://huggingface.co/{model_identifier}/resolve/main/model_encoder.pkl'
self.labels = pickle.loads(requests.get(encoder_url).content)
def predict_category(self, text):
# Tokenize the text
inputs = self.tokenizer(text, return_tensors='pt', truncation=True, padding=True)
# Predict
with torch.no_grad():
outputs = self.model(**inputs)
# Get the prediction index
prediction_idx = torch.argmax(outputs.logits, dim=1).item()
# Decode the prediction index to get the label
prediction_label = self.labels[prediction_idx] # Use indexing for a NumPy array
return prediction_label