Downloads · 30 days
11
3% of all-time downloads
nfhakim/police-sentiment-c2-v2
police-sentiment-c2-v2 is a text classification model from nfhakim. Use it when you need a label for a piece of text. It is set up for transformers.
This is the second classification of sentiment analysis for police news task
Downloads · 30 days
11
3% of all-time downloads
All-time downloads
328
Public
Repo size
996 MB
Likes
0
Public
Click a slice to open those files.
.bin498 MB · 100%
From the Hugging Face model README
This is the second classification of sentiment analysis for police news task
import torch
from transformers import BertForSequenceClassification, BertTokenizer, BertConfig, pipeline
# Load the tokenizer and model
tokenizer = BertTokenizer.from_pretrained("nfhakim/police-sentiment-c2-v2")
config = BertConfig.from_pretrained("nfhakim/police-sentiment-c2-v2")
model = BertForSequenceClassification.from_pretrained("nfhakim/police-sentiment-c2-v2", config=config)
# Initialize the pipeline
nlp = pipeline("text-classification", model=model, tokenizer=tokenizer)
# Define a function to handle input text
def classify_text(text):
# Tokenize the text and truncate to the first 512 tokens if necessary
inputs = tokenizer(text, truncation=True, max_length=512, return_tensors="pt")
# Use the model to classify the text
results = nlp(inputs['input_ids'])
return results
# Example usage
input_text = "Your input text here"
output = classify_text(input_text)
print(output)