Merge pull request #21 from stalbrec/1-hallucinations
adding function to remove whisper hallucinations
This commit is contained in:
@@ -0,0 +1,95 @@
|
|||||||
|
# List of known hallucinations - adapted from:
|
||||||
|
# https://github.com/openai/whisper/discussions/928
|
||||||
|
KNOWN_HALLUCINATIONS=[
|
||||||
|
# en
|
||||||
|
" www.mooji.org"
|
||||||
|
# nl
|
||||||
|
" Ondertitels ingediend door de Amara.org gemeenschap",
|
||||||
|
" Ondertiteld door de Amara.org gemeenschap",
|
||||||
|
" Ondertiteling door de Amara.org gemeenschap"
|
||||||
|
# de
|
||||||
|
" Untertitelung aufgrund der Amara.org-Community"
|
||||||
|
" Untertitelung im Auftrag des ZDF für funk, 2016",
|
||||||
|
" Untertitelung im Auftrag des ZDF f\u00fcr funk, 2016",
|
||||||
|
" Untertitel im Auftrag des ZDF für funk, 2017",
|
||||||
|
" Untertitel im Auftrag des ZDF f\u00fcr funk, 2017",
|
||||||
|
" Untertitel im Auftrag des ZDF für funk, 2018",
|
||||||
|
" Untertitel von Stephanie Geiges",
|
||||||
|
" Untertitel der Amara.org-Community",
|
||||||
|
" Untertitel im Auftrag des ZDF, 2017",
|
||||||
|
" Untertitel im Auftrag des ZDF, 2018",
|
||||||
|
" Untertitel im Auftrag des ZDF, 2019",
|
||||||
|
" Untertitel im Auftrag des ZDF, 2020",
|
||||||
|
" Untertitel im Auftrag des ZDF, 2021",
|
||||||
|
" Untertitelung im Auftrag des ZDF, 2021",
|
||||||
|
" Copyright WDR 2021",
|
||||||
|
" Copyright WDR 2020",
|
||||||
|
" Copyright WDR 2019",
|
||||||
|
" SWR 2021",
|
||||||
|
" SWR 2020",
|
||||||
|
# fr
|
||||||
|
" Sous-titres réalisés para la communauté d'Amara.org",
|
||||||
|
" Sous-titres réalisés par la communauté d'Amara.org",
|
||||||
|
" Sous-titres fait par Sous-titres par Amara.org",
|
||||||
|
" Sous-titres réalisés par les SousTitres d'Amara.org",
|
||||||
|
" Sous-titres par Amara.org",
|
||||||
|
" Sous-titres par la communauté d'Amara.org",
|
||||||
|
" Sous-titres réalisés pour la communauté d'Amara.org",
|
||||||
|
" Sous-titres réalisés par la communauté de l'Amara.org",
|
||||||
|
" Sous-Titres faits par la communauté d'Amara.org",
|
||||||
|
" Sous-titres par l'Amara.org",
|
||||||
|
" Sous-titres fait par la communauté d'Amara.org"
|
||||||
|
" Sous-titrage ST' 501",
|
||||||
|
" Sous-titrage ST'501",
|
||||||
|
" Cliquez-vous sur les sous-titres et abonnez-vous à la chaîne d'Amara.org",
|
||||||
|
" ❤️ par SousTitreur.com",
|
||||||
|
# it
|
||||||
|
" Sottotitoli creati dalla comunità Amara.org",
|
||||||
|
" Sottotitoli di Sottotitoli di Amara.org",
|
||||||
|
" Sottotitoli e revisione al canale di Amara.org",
|
||||||
|
" Sottotitoli e revisione a cura di Amara.org",
|
||||||
|
" Sottotitoli e revisione a cura di QTSS",
|
||||||
|
" Sottotitoli e revisione a cura di QTSS.",
|
||||||
|
" Sottotitoli a cura di QTSS",
|
||||||
|
" Subtítulos realizados por la comunidad de Amara.org",
|
||||||
|
" Subtitulado por la comunidad de Amara.org",
|
||||||
|
" Subtítulos por la comunidad de Amara.org",
|
||||||
|
" Subtítulos creados por la comunidad de Amara.org",
|
||||||
|
" Subtítulos en español de Amara.org",
|
||||||
|
" Subtítulos hechos por la comunidad de Amara.org",
|
||||||
|
" Subtitulos por la comunidad de Amara.org"
|
||||||
|
" Más información www.alimmenta.com",
|
||||||
|
" www.mooji.org",
|
||||||
|
# gl
|
||||||
|
" Subtítulos realizados por la comunidad de Amara.org"
|
||||||
|
# pt
|
||||||
|
" Legendas pela comunidade Amara.org",
|
||||||
|
" Legendas pela comunidade de Amara.org",
|
||||||
|
" Legendas pela comunidade do Amara.org",
|
||||||
|
" Legendas pela comunidade das Amara.org",
|
||||||
|
" Transcrição e Legendas pela comunidade de Amara.org"
|
||||||
|
# la
|
||||||
|
" Sottotitoli creati dalla comunità Amara.org",
|
||||||
|
" Sous-titres réalisés para la communauté d'Amara.org"
|
||||||
|
# ln
|
||||||
|
" Sous-titres réalisés para la communauté d'Amara.org"
|
||||||
|
# pl
|
||||||
|
" Napisy stworzone przez społeczność Amara.org",
|
||||||
|
" Napisy wykonane przez społeczność Amara.org",
|
||||||
|
" Zdjęcia i napisy stworzone przez społeczność Amara.org",
|
||||||
|
" napisy stworzone przez społeczność Amara.org",
|
||||||
|
" Tłumaczenie i napisy stworzone przez społeczność Amara.org",
|
||||||
|
" Napisy stworzone przez społeczności Amara.org",
|
||||||
|
" Tłumaczenie stworzone przez społeczność Amara.org",
|
||||||
|
" Napisy robione przez społeczność Amara.org"
|
||||||
|
" www.multi-moto.eu",
|
||||||
|
# ru
|
||||||
|
" Редактор субтитров А.Синецкая Корректор А.Егорова"
|
||||||
|
# tr
|
||||||
|
" Yorumlarınızıza abone olmayı unutmayın.",
|
||||||
|
# su
|
||||||
|
" Sottotitoli creati dalla comunità Amara.org"
|
||||||
|
# zh
|
||||||
|
"字幕由Amara.org社区提供",
|
||||||
|
"小編字幕由Amara.org社區提供"
|
||||||
|
]
|
||||||
@@ -2,10 +2,13 @@ import json
|
|||||||
import time
|
import time
|
||||||
|
|
||||||
from typing import Union
|
from typing import Union
|
||||||
|
|
||||||
|
from .hallucinations import KNOWN_HALLUCINATIONS
|
||||||
|
|
||||||
ALPHABET = [*"abcdefghijklmnopqrstuvwxyz"]
|
ALPHABET = [*"abcdefghijklmnopqrstuvwxyz"]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class Transcript:
|
class Transcript:
|
||||||
"""
|
"""
|
||||||
Class for storing transcript data, including speaker information and text segments,
|
Class for storing transcript data, including speaker information and text segments,
|
||||||
@@ -23,6 +26,7 @@ class Transcript:
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
self.transcript = transcript
|
self.transcript = transcript
|
||||||
|
self._remove_hallucinations()
|
||||||
self.speakers = self._extract_speakers()
|
self.speakers = self._extract_speakers()
|
||||||
self.segments = self._extract_segments()
|
self.segments = self._extract_segments()
|
||||||
self.annotation = {}
|
self.annotation = {}
|
||||||
@@ -62,6 +66,20 @@ class Transcript:
|
|||||||
|
|
||||||
return self
|
return self
|
||||||
|
|
||||||
|
def _remove_hallucinations(self) -> None:
|
||||||
|
"""
|
||||||
|
Removes all occurances of known hallucinations from all segments of the transcript.
|
||||||
|
Segments that are identical to empty strings afterwards are removed from the transcript.
|
||||||
|
"""
|
||||||
|
segments_to_drop=[]
|
||||||
|
for id in self.transcript:
|
||||||
|
for snippet in KNOWN_HALLUCINATIONS:
|
||||||
|
self.transcript[id]['text']=self.transcript[id]['text'].replace(snippet,'')
|
||||||
|
if self.transcript[id]['text'] == '': segments_to_drop.append(id)
|
||||||
|
|
||||||
|
for id in segments_to_drop:
|
||||||
|
del self.transcript[id]
|
||||||
|
|
||||||
def _extract_speakers(self) -> list:
|
def _extract_speakers(self) -> list:
|
||||||
"""
|
"""
|
||||||
Extracts the unique speaker names from the transcript.
|
Extracts the unique speaker names from the transcript.
|
||||||
|
|||||||
Reference in New Issue
Block a user