Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

intent ranking added #1656

Merged
merged 1 commit into from
Dec 16, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion kairon/nlu/classifiers/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ def process(self, messages: List[Message]) -> List[Message]:
else:
label, reason, entities = self.predict(message.get(TEXT))
intent = {"name": label, "confidence": 1, "reason": reason}
intent_ranking = []
intent_ranking = [intent.copy()]
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Consider implementing proper confidence scoring for intent ranking

While copying the intent is better than an empty list, the current implementation doesn't provide true intent ranking as it:

  1. Always sets confidence to 1
  2. Only includes a single intent in the ranking

Consider implementing proper confidence scoring and multiple intents in the ranking. Example approach:

def process(self, messages: List[Message]) -> List[Message]:
    for message in messages:
        if not self.vector and not self.data:
            intent = None
            intent_ranking = []
            entities = []
        else:
            label, reason, entities = self.predict(message.get(TEXT))
            # Get top N intents with confidence scores
            intent = {"name": label, "confidence": self._calculate_confidence(label), "reason": reason}
            intent_ranking = self._get_intent_ranking(label)  # Return top N intents with scores
            entities = self.add_extractor_name(entities)

entities = self.add_extractor_name(entities)

message.set("intent", intent, add_to_output=True)
Expand Down
Loading