lanny xu commited on
Commit
c6e3d43
·
1 Parent(s): b764fd1

resolve conflict

Browse files
Files changed (1) hide show
  1. hallucination_detector.py +11 -4
hallucination_detector.py CHANGED
@@ -219,8 +219,7 @@ class NLIHallucinationDetector:
219
  problematic_sentences.append(sentence)
220
  elif 'neutral' in label:
221
  neutral_count += 1
222
- # neutral 也可能是幻觉(文档中没有支持)
223
- problematic_sentences.append(sentence)
224
  elif 'entailment' in label or 'entail' in label:
225
  entailment_count += 1
226
 
@@ -230,8 +229,16 @@ class NLIHallucinationDetector:
230
  print(f" 详细错误: {traceback.format_exc()[:200]}")
231
  continue
232
 
233
- # 判断是否有幻觉
234
- has_hallucination = contradiction_count > 0 or neutral_count > len(sentences) * 0.5
 
 
 
 
 
 
 
 
235
 
236
  return {
237
  "has_hallucination": has_hallucination,
 
219
  problematic_sentences.append(sentence)
220
  elif 'neutral' in label:
221
  neutral_count += 1
222
+ # neutral 只是中立,不一定是幻觉,不加入 problematic_sentences
 
223
  elif 'entailment' in label or 'entail' in label:
224
  entailment_count += 1
225
 
 
229
  print(f" 详细错误: {traceback.format_exc()[:200]}")
230
  continue
231
 
232
+ # 判断是否有幻觉(只有明确矛盾才算幻觉)
233
+ # neutral 表示文档中没有相关信息,但不一定是错误的
234
+ total_sentences = contradiction_count + neutral_count + entailment_count
235
+
236
+ # 只有当矛盾句子超过 30% 或者 neutral 超过 80% 才算幻觉
237
+ has_hallucination = False
238
+ if total_sentences > 0:
239
+ contradiction_ratio = contradiction_count / total_sentences
240
+ neutral_ratio = neutral_count / total_sentences
241
+ has_hallucination = (contradiction_ratio > 0.3) or (neutral_ratio > 0.8)
242
 
243
  return {
244
  "has_hallucination": has_hallucination,