EMMA commited on
Commit
0498d09
·
1 Parent(s): d52310d

update code

Browse files
Files changed (1) hide show
  1. utils/crisis_gate.py +22 -11
utils/crisis_gate.py CHANGED
@@ -45,6 +45,16 @@ def _normalize(text: str) -> str:
45
  text = text.strip().lower()
46
  text = re.sub(r"[^\w\s']", " ", text) # strip punctuation, keep contractions
47
  text = re.sub(r"\s+", " ", text)
 
 
 
 
 
 
 
 
 
 
48
  return text
49
 
50
 
@@ -53,39 +63,40 @@ def _normalize(text: str) -> str:
53
  # copy-paste sources -- keep both rather than relying on one regex trick.
54
  IMMINENT_PATTERNS = [
55
  "i want to hurt myself right now",
56
- "i'm going to kill myself right now",
57
  "im going to kill myself right now",
58
  "i have the means right here",
59
- "i've made up my mind",
60
  "ive made up my mind",
61
- "i'm doing it tonight",
62
  "im doing it tonight",
 
 
63
  ]
64
 
65
  HIGH_RISK_PATTERNS = [
66
  "i want to kill myself",
67
  "i want to end my life",
68
  "i want to hurt myself",
69
- "i dont want to be alive anymore",
70
- "i don't want to be alive anymore",
71
- "i dont want to live anymore",
72
- "i don't want to live anymore",
73
  "i want to die",
 
 
 
 
74
  ]
75
 
76
  CONCERN_PATTERNS = [
77
  "i wish i didnt exist",
78
- "i wish i didn't exist",
79
  "life isnt worth it",
80
  "life isn't worth it",
81
- "i cant take it anymore",
82
- "i can't take it anymore",
83
  "its all over",
84
  "it's all over",
85
  "whats the point of going on",
86
  "what's the point of going on",
87
  "im tired of life",
88
- "i'm tired of life",
 
89
  ]
90
 
91
 
 
45
  text = text.strip().lower()
46
  text = re.sub(r"[^\w\s']", " ", text) # strip punctuation, keep contractions
47
  text = re.sub(r"\s+", " ", text)
48
+ # Collapse common contraction variants onto one form so a single pattern
49
+ # entry catches "i am", "i'm", and "im" alike, instead of needing every
50
+ # spelling variant hand-listed. This is the fix for the "i am tired of
51
+ # life" miss -- it previously only matched "im"/"i'm", not "i am".
52
+ text = re.sub(r"\bi am\b", "im", text)
53
+ text = re.sub(r"\bi'm\b", "im", text)
54
+ text = re.sub(r"\bdo not\b", "dont", text)
55
+ text = re.sub(r"\bdon't\b", "dont", text)
56
+ text = re.sub(r"\bi've\b", "ive", text)
57
+ text = re.sub(r"\bi have\b", "ive", text)
58
  return text
59
 
60
 
 
63
  # copy-paste sources -- keep both rather than relying on one regex trick.
64
  IMMINENT_PATTERNS = [
65
  "i want to hurt myself right now",
 
66
  "im going to kill myself right now",
67
  "i have the means right here",
 
68
  "ive made up my mind",
 
69
  "im doing it tonight",
70
+ "want to end it all tonight",
71
+ "going to end it all tonight",
72
  ]
73
 
74
  HIGH_RISK_PATTERNS = [
75
  "i want to kill myself",
76
  "i want to end my life",
77
  "i want to hurt myself",
78
+ "dont want to be alive anymore",
79
+ "dont want to live anymore",
 
 
80
  "i want to die",
81
+ "want to end it all",
82
+ "better off dead",
83
+ "no reason to keep living",
84
+ "no point in living",
85
  ]
86
 
87
  CONCERN_PATTERNS = [
88
  "i wish i didnt exist",
 
89
  "life isnt worth it",
90
  "life isn't worth it",
91
+ "cant take it anymore",
92
+ "can't take it anymore",
93
  "its all over",
94
  "it's all over",
95
  "whats the point of going on",
96
  "what's the point of going on",
97
  "im tired of life",
98
+ "tired of life",
99
+ "dont want to be here anymore",
100
  ]
101
 
102