浏览代码

Classifier: Slot-Extraktion via KeywordMatcher nach ONNX-Erkennung

Problem: ONNX-Classifier erkennt Intent (play_music) aber extrahiert
keine Slots (query fehlt → Musik ohne Suchbegriff abgespielt).

Fix: Nach ONNX-Intent-Erkennung den KeywordMatcher fuer Slot-Extraktion
nutzen. Der Classifier erkennt den Intent, der KeywordMatcher die Slots.

"koenntest du bitte musik von rammstein spielen"
  → Classifier: play_music (0.96)
  → KeywordMatcher Slots: {query: "musik von rammstein"}

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
patrick 2 月之前
父节点
当前提交
64cd5d0b56
共有 1 个文件被更改,包括 11 次插入2 次删除
  1. 11 2
      plugins/nlp_classifier/main.py

+ 11 - 2
plugins/nlp_classifier/main.py

@@ -183,13 +183,22 @@ class NLPClassifierPlugin(TrixyPlugin):
             if prediction.confidence >= min_confidence:
                 intent = prediction.intent
                 confidence = prediction.confidence
-                slots = prediction.slots
                 matched_by = "classifier"
 
+                # Slot-Extraktion via KeywordMatcher (der Classifier erkennt Intents,
+                # der KeywordMatcher extrahiert Slots aus den Patterns)
+                slots = prediction.slots or {}
+                if self._keyword_matcher:
+                    kw_slots = self._keyword_matcher.match(text)
+                    if kw_slots and kw_slots.slots:
+                        slots = kw_slots.slots
+                        pdebug(f"[Classifier] Slots via KeywordMatcher: {slots}")
+
                 if log_predictions:
                     pinfo(
                         f"[Classifier] ONNX: '{intent}' "
-                        f"(conf={confidence:.2f}, {prediction.inference_ms:.1f}ms)"
+                        f"(conf={confidence:.2f}, {prediction.inference_ms:.1f}ms, "
+                        f"slots={slots})"
                     )
 
         # --- Stufe 3: LLM-Fallback ---