Skip to content

Commit bfae643

Browse files
authored
improved hallucination detection system.
1 parent 0875e90 commit bfae643

1 file changed

Lines changed: 12 additions & 6 deletions

File tree

autosub.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -136,15 +136,21 @@
136136
for segment in segments:
137137
if info.language in ["ja"] and not args.translate:
138138
segment.text = segment.text.replace(" ", "") # Remove additional spaces
139-
print(f" {segment.start} --> {segment.end} {segment.text}")
140-
if prev_segment == segment.text:
139+
140+
text = " ".join(segment.text.strip().split()) # NEW
141+
print(f" {segment.start} --> {segment.end} {text}")
142+
143+
if prev_segment == text:
141144
count_duplicates += 1
142145
else:
143146
count_duplicates = 0
144-
if count_duplicates > 3:
145-
print(" Whisper hallucinating with too many duplicates")
146-
sys.exit(-1)
147-
prev_segment = segment.text
147+
148+
if count_duplicates > 10:
149+
print("Possible hallucination detected. Skipping segment.")
150+
continue
151+
152+
prev_segment = text
153+
segment.text = text # CLEAN VERSION
148154
#if WORD_TIMESTAMPS:
149155
# for word in segment.words:
150156
# print(f" [{round(word.start, 2)} -> {round(word.end, 2)}] {word.word}")

0 commit comments

Comments
 (0)