You're encountering a common issue with language models, especially smaller ones like Mistral 7B, when the prompt contains subtle contradictions or ambiguities.
The core problem lies in this line:
"Classify the user input into one of the following categories ONLY IF it's logistics related:"
And then you define GREETINGS as "for hello/hi-style messages". A simple "hello" or "hi" has no logistics content. The model is likely interpreting "logistics related" very strictly. Since a greeting isn't explicitly about logistics, it falls back to UNKNOWN because it doesn't meet the "ONLY IF it's logistics related" condition.
Similarly, some "FAQ" questions that are very general (e.g., "What is ShypBuddy?") might not be seen as directly logistics-related by the model, even though they are part of a logistics service's FAQ.
Solution: Use Few-Shot Examples and Refine the Instructions
The most effective way to guide a model for classification is to provide clear examples (few-shot learning). This demonstrates exactly how you want it to interpret the rules, especially the nuances of "logistics-related" for GREETINGS and general FAQs.
Here's an improved prompt that should work better:
prompt = (
"You are a classifier that handles various user queries for ShypBuddy. "
"Classify the user input into one of the following categories. "
"If the input does not fit any of the defined categories, respond with UNKNOWN.\n\n"
"Categories:\n"
" - GREETINGS: for hello/hi-style messages. These are considered within the scope of this classifier.\n"
" - FAQ: for general logistics or ShypBuddy service questions.\n"
" - TRACKING: for AWB or shipment tracking requests.\n"
" - REMITTANCE: for remittance/payment/finance-related queries.\n\n"
"Respond with only one word: GREETINGS, FAQ, TRACKING, REMITTANCE, or UNKNOWN.\n\n"
"Examples:\n"
"Input: \"Hello there!\"\nClassification: GREETINGS\n\n"
"Input: \"Hi, how are you?\"\nClassification: GREETINGS\n\n"
"Input: \"What are your shipping rates?\"\nClassification: FAQ\n\n"
"Input: \"How does ShypBuddy work?\"\nClassification: FAQ\n\n"
"Input: \"Can I track my package with AWB number 12345?\"\nClassification: TRACKING\n\n"
"Input: \"Where is my shipment?\"\nClassification: TRACKING\n\n"
"Input: \"When will my remittance be processed?\"\nClassification: REMITTANCE\n\n"
"Input: \"I have a question about my invoice.\"\nClassification: REMITTANCE\n\n"
"Input: \"Tell me a joke.\"\nClassification: UNKNOWN\n\n"
f"Input: \"{user_input}\"\nClassification:"
)
Key Changes and Why They Work:
-
Relaxed Initial Constraint: Changed "You are a classifier that only handles logistics-related queries for ShypBuddy." to "You are a classifier that handles various user queries for ShypBuddy." and "Classify the user input into one of the following categories ONLY IF it's logistics related:" to "Classify the user input into one of the following categories. If the input does not fit any of the defined categories, respond with UNKNOWN."
- This removes the direct "ONLY IF logistics related" constraint from the classification step for all categories, allowing the model to classify
GREETINGS and FAQ as defined, rather than filtering them out first. The context is still a logistics classifier, but it explicitly handles these broader types of interactions.
-
Clarified GREETINGS Definition: Added "These are considered within the scope of this classifier." to the GREETINGS definition to explicitly tell the model that even non-logistics-specific greetings should be classified under GREETINGS within this system.
-
Few-Shot Examples: This is the most crucial part. By providing several concrete examples for each category (including GREETINGS and FAQ inputs that aren't strictly logistics-keyword heavy), you directly demonstrate the desired behavior to the model. Models learn very effectively from examples.
With this revised prompt, Mistral 7B should be much more consistent in classifying GREETINGS and general FAQ inputs correctly.