Upload pipeline.py with huggingface_hub
Browse files- pipeline.py +19 -24
pipeline.py
CHANGED
|
@@ -18,7 +18,8 @@ class ThoughtCompletionPipeline(Pipeline):
|
|
| 18 |
def ends_with_incomplete_word(self, text):
|
| 19 |
"""Check if text ends with words that indicate incomplete thought"""
|
| 20 |
text = text.strip().lower()
|
| 21 |
-
|
|
|
|
| 22 |
words = text.split()
|
| 23 |
|
| 24 |
if not words:
|
|
@@ -36,35 +37,29 @@ class ThoughtCompletionPipeline(Pipeline):
|
|
| 36 |
|
| 37 |
ai_utterance = parts[0].strip()
|
| 38 |
cx_utterance = parts[1].strip()
|
|
|
|
| 39 |
|
| 40 |
-
#
|
| 41 |
-
|
| 42 |
-
return [{'label': 'INCOMPLETE', 'score': 0.95}], 'rule:incomplete_ending'
|
| 43 |
-
|
| 44 |
-
cx_lower = cx_utterance.lower()
|
| 45 |
|
| 46 |
-
#
|
| 47 |
-
|
| 48 |
-
"that's all", "nothing else", "i'm done", "
|
| 49 |
-
"no thanks", "no thank you", "yes", "yes
|
| 50 |
-
"perfect", "great", "sounds good", "that's everything"
|
|
|
|
|
|
|
| 51 |
]
|
| 52 |
|
| 53 |
-
for phrase in
|
| 54 |
-
if
|
| 55 |
-
return [{'label': 'COMPLETE', 'score': 0.95}], f'rule:
|
| 56 |
|
| 57 |
-
#
|
| 58 |
-
|
| 59 |
-
|
| 60 |
-
"can i get", "i want", "i'd like", "i need",
|
| 61 |
-
"hold on", "one more", "oh and"
|
| 62 |
-
]
|
| 63 |
-
|
| 64 |
-
for phrase in incomplete_phrases:
|
| 65 |
-
if phrase in cx_lower:
|
| 66 |
-
return [{'label': 'INCOMPLETE', 'score': 0.95}], f'rule:contains_{phrase}'
|
| 67 |
|
|
|
|
| 68 |
return None, None
|
| 69 |
|
| 70 |
def preprocess(self, inputs):
|
|
|
|
| 18 |
def ends_with_incomplete_word(self, text):
|
| 19 |
"""Check if text ends with words that indicate incomplete thought"""
|
| 20 |
text = text.strip().lower()
|
| 21 |
+
# Remove trailing punctuation
|
| 22 |
+
text = re.sub(r'[.,!?;:]$', '', text)
|
| 23 |
words = text.split()
|
| 24 |
|
| 25 |
if not words:
|
|
|
|
| 37 |
|
| 38 |
ai_utterance = parts[0].strip()
|
| 39 |
cx_utterance = parts[1].strip()
|
| 40 |
+
cx_lower = cx_utterance.lower().strip()
|
| 41 |
|
| 42 |
+
# Remove punctuation for exact matching
|
| 43 |
+
cx_lower_clean = re.sub(r'[.,!?;:]$', '', cx_lower)
|
|
|
|
|
|
|
|
|
|
| 44 |
|
| 45 |
+
# RULE 1: Check for EXACT MATCH complete thoughts (full sentence match)
|
| 46 |
+
complete_full_sentences = [
|
| 47 |
+
"that's all", "that's it", "nothing else", "i'm done", "i'm good",
|
| 48 |
+
"no thanks", "no thank you", "yes please", "yes", "no",
|
| 49 |
+
"perfect", "great", "sounds good", "that's everything",
|
| 50 |
+
"all set", "done", "finished", "that is all", "that is it",
|
| 51 |
+
"nope", "yep", "yeah"
|
| 52 |
]
|
| 53 |
|
| 54 |
+
for phrase in complete_full_sentences:
|
| 55 |
+
if cx_lower_clean == phrase: # EXACT MATCH ONLY
|
| 56 |
+
return [{'label': 'COMPLETE', 'score': 0.95}], f'rule:exact_match_{phrase.replace(" ", "_")}'
|
| 57 |
|
| 58 |
+
# RULE 2: Check if sentence ENDS with incomplete word
|
| 59 |
+
if self.ends_with_incomplete_word(cx_utterance):
|
| 60 |
+
return [{'label': 'INCOMPLETE', 'score': 0.95}], 'rule:ends_with_incomplete_word'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 61 |
|
| 62 |
+
# No rule applies - use the neural model
|
| 63 |
return None, None
|
| 64 |
|
| 65 |
def preprocess(self, inputs):
|