Instructions to use nfhakim/police-sentiment-c1-v2 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers
How to use nfhakim/police-sentiment-c1-v2 with Transformers:
# Use a pipeline as a high-level helper from transformers import pipeline pipe = pipeline("text-classification", model="nfhakim/police-sentiment-c1-v2")# Load model directly from transformers import AutoTokenizer, AutoModelForSequenceClassification tokenizer = AutoTokenizer.from_pretrained("nfhakim/police-sentiment-c1-v2") model = AutoModelForSequenceClassification.from_pretrained("nfhakim/police-sentiment-c1-v2") - Notebooks
- Google Colab
- Kaggle
This is the first classification of sentiment analysis for police new task
How to import
import torch
from transformers import BertForSequenceClassification, BertTokenizer, BertConfig, pipeline
# Load the tokenizer and model
tokenizer = BertTokenizer.from_pretrained("nfhakim/police-sentiment-c1-v2")
config = BertConfig.from_pretrained("nfhakim/police-sentiment-c1-v2")
model = BertForSequenceClassification.from_pretrained("nfhakim/police-sentiment-c1-v2", config=config)
How to use
# 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)
- Downloads last month
- 2