Views
No views yet
pip install transformers torch1
2from transformers import BertForSequenceClassification, BertTokenizer
3import torch
4
5# Load quantized model
6quantized_model_path = "AventIQ-AI/sentiment-analysis-for-whistleblower-report-sentiment"
7quantized_model = BertForSequenceClassification.from_pretrained(quantized_model_path)
8quantized_model.eval() # Set to evaluation mode
9quantized_model.half() # Convert model to FP16
10
11# Load tokenizer
12tokenizer = BertTokenizer.from_pretrained("bert-base-uncased")
13
14# Define a test sentence
15test_sentence = "Despite repeated warnings to upper management, safety protocols continued to be ignored at the facility. Employees expressed growing concerns, but supervisors dismissed them without proper review. While some improvements were promised, no tangible actions were taken. The general atmosphere became increasingly hostile, with staff fearing retaliation for speaking out. However, a few departments did show minor signs of improvement after anonymous complaints were made."
16
17# Tokenize input
18inputs = tokenizer(test_sentence, return_tensors="pt", padding=True, truncation=True, max_length=128)
19
20# Ensure input tensors are in correct dtype
21inputs["input_ids"] = inputs["input_ids"].long() # Convert to long type
22inputs["attention_mask"] = inputs["attention_mask"].long() # Convert to long type
23
24# Make prediction
25with torch.no_grad():
26 outputs = quantized_model(**inputs)
27
28# Get predicted class
29predicted_class = torch.argmax(outputs.logits, dim=1).item()
30print(f"Predicted Class: {predicted_class}")
31
32
33label_mapping = {0: "very_negative", 1: "negative", 2: "neutral", 3: "positive", 4: "very_positive"} # Example
34
35predicted_label = label_mapping[predicted_class]
36print(f"Predicted Label: {predicted_label}")
37.
├── model/ # Contains the quantized model files
├── tokenizer_config/ # Tokenizer configuration and vocabulary files
├── model.safensors/ # Fine Tuned Model
├── README.md # Model documentation