lanny xu commited on
Commit
c3f88f2
·
1 Parent(s): ee3fb2e

resolve conflict

Browse files
Files changed (1) hide show
  1. hallucination_detector.py +12 -1
hallucination_detector.py CHANGED
@@ -139,6 +139,7 @@ class NLIHallucinationDetector:
139
  }
140
  """
141
  if self.nli_model is None:
 
142
  return {
143
  "has_hallucination": False,
144
  "contradiction_count": 0,
@@ -150,6 +151,16 @@ class NLIHallucinationDetector:
150
  # 分割成句子
151
  sentences = self.split_sentences(generation)
152
 
 
 
 
 
 
 
 
 
 
 
153
  contradiction_count = 0
154
  neutral_count = 0
155
  entailment_count = 0
@@ -179,7 +190,7 @@ class NLIHallucinationDetector:
179
  entailment_count += 1
180
 
181
  except Exception as e:
182
- print(f"⚠️ NLI 检测句子失败: {e}")
183
  continue
184
 
185
  # 判断是否有幻觉
 
139
  }
140
  """
141
  if self.nli_model is None:
142
+ print("⚠️ NLI 模型未加载,跳过检测")
143
  return {
144
  "has_hallucination": False,
145
  "contradiction_count": 0,
 
151
  # 分割成句子
152
  sentences = self.split_sentences(generation)
153
 
154
+ if not sentences:
155
+ print("⚠️ 没有检测到有效句子")
156
+ return {
157
+ "has_hallucination": False,
158
+ "contradiction_count": 0,
159
+ "neutral_count": 0,
160
+ "entailment_count": 0,
161
+ "problematic_sentences": []
162
+ }
163
+
164
  contradiction_count = 0
165
  neutral_count = 0
166
  entailment_count = 0
 
190
  entailment_count += 1
191
 
192
  except Exception as e:
193
+ print(f"⚠️ NLI 检测句子失败: {str(e)[:100]}")
194
  continue
195
 
196
  # 判断是否有幻觉