image_intents / test.py
smeintadmin's picture
Upload 16 files
1ae8986
Raw
History Blame
973 Bytes
import torch
from transformers import AutoTokenizer, AutoModelForSequenceClassification
MODEL_DIR = "img_intents_model"
TOKENIZER_NAME = "./results"
# Load the trained model
model = AutoModelForSequenceClassification.from_pretrained(MODEL_DIR)
# Load the tokenizer
tokenizer = AutoTokenizer.from_pretrained(TOKENIZER_NAME)
while True:
# Get the input from the command line
input_text = input("Enter a message to classify (or 'q' to quit): ")
if input_text.lower() == 'q':
break
# Encode the input and convert it to a torch tensor
inputs = tokenizer.encode_plus(input_text, return_tensors='pt')
# Get the model's prediction
outputs = model(**inputs)
# Get the predicted class from the model's output
predicted_class = torch.argmax(outputs.logits).item()
if predicted_class == 1:
print("The message is predicted as an image intent.")
else:
print("The message is not predicted as an image intent.")