File size: 973 Bytes
1ae8986
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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.")