From 98c1c7dfa5c2c900a0f0267986539b6ab412c8b9 Mon Sep 17 00:00:00 2001 From: Steffen Albrecht Date: Fri, 8 Dec 2023 14:57:32 +0100 Subject: [PATCH 1/4] adding function to remove whisper hallucinations --- scraibe/transcript_exporter.py | 117 +++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) diff --git a/scraibe/transcript_exporter.py b/scraibe/transcript_exporter.py index 3c68d87..c40a993 100644 --- a/scraibe/transcript_exporter.py +++ b/scraibe/transcript_exporter.py @@ -5,6 +5,110 @@ from typing import Union ALPHABET = [*"abcdefghijklmnopqrstuvwxyz"] +WHISPER_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" + " Untertitel im Auftrag des ZDF für funk, 2017", + " Untertitel von Stephanie Geiges", + " Untertitel der Amara.org-Community", + " Untertitel im Auftrag des ZDF, 2017", + " Untertitel im Auftrag des ZDF, 2020", + " Untertitel im Auftrag des ZDF, 2018", + " 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", + ], + "es": [ + " 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社區提供" + ] +} class Transcript: """ @@ -23,6 +127,7 @@ class Transcript: """ self.transcript = transcript + self._remove_hallucinations() self.speakers = self._extract_speakers() self.segments = self._extract_segments() self.annotation = {} @@ -62,6 +167,18 @@ class Transcript: return self + def _remove_hallucinations(self) -> None: + segments_to_drop=[] + + for id in self.transcript: + for language, snippets in WHISPER_HALLUCINATIONS.items(): + for snippet in snippets: + 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: """ Extracts the unique speaker names from the transcript. From 920a85a94a02c5a1bf541f30b1ca3f32a9cfc66d Mon Sep 17 00:00:00 2001 From: Steffen Albrecht Date: Fri, 8 Dec 2023 15:14:29 +0100 Subject: [PATCH 2/4] adding credit for list of known hallucinations --- scraibe/transcript_exporter.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scraibe/transcript_exporter.py b/scraibe/transcript_exporter.py index c40a993..5920fd9 100644 --- a/scraibe/transcript_exporter.py +++ b/scraibe/transcript_exporter.py @@ -5,6 +5,8 @@ from typing import Union ALPHABET = [*"abcdefghijklmnopqrstuvwxyz"] +# List of known hallucinations - taken from: +# https://github.com/openai/whisper/discussions/928 WHISPER_HALLUCINATIONS={ "en": [ " www.mooji.org", From 667ccd29af6e7e75e1df194f022e473fb5bd3f5a Mon Sep 17 00:00:00 2001 From: Steffen Albrecht Date: Mon, 11 Dec 2023 12:04:08 +0100 Subject: [PATCH 3/4] extend list of known hallucinations --- scraibe/transcript_exporter.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/scraibe/transcript_exporter.py b/scraibe/transcript_exporter.py index 5920fd9..b717d7f 100644 --- a/scraibe/transcript_exporter.py +++ b/scraibe/transcript_exporter.py @@ -5,7 +5,7 @@ from typing import Union ALPHABET = [*"abcdefghijklmnopqrstuvwxyz"] -# List of known hallucinations - taken from: +# List of known hallucinations - adapted from: # https://github.com/openai/whisper/discussions/928 WHISPER_HALLUCINATIONS={ "en": [ @@ -18,12 +18,17 @@ WHISPER_HALLUCINATIONS={ ], "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, 2020", " 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", From 8db033607044d66455bb79a0d3d814545cdcf405 Mon Sep 17 00:00:00 2001 From: Steffen Albrecht Date: Thu, 14 Dec 2023 14:54:03 +0100 Subject: [PATCH 4/4] moved known hallucinations from dict to list in external py file --- scraibe/hallucinations.py | 95 +++++++++++++++++++++++++ scraibe/transcript_exporter.py | 126 +++------------------------------ 2 files changed, 105 insertions(+), 116 deletions(-) create mode 100644 scraibe/hallucinations.py diff --git a/scraibe/hallucinations.py b/scraibe/hallucinations.py new file mode 100644 index 0000000..a337ec0 --- /dev/null +++ b/scraibe/hallucinations.py @@ -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社區提供" +] \ No newline at end of file diff --git a/scraibe/transcript_exporter.py b/scraibe/transcript_exporter.py index b717d7f..1ce43d4 100644 --- a/scraibe/transcript_exporter.py +++ b/scraibe/transcript_exporter.py @@ -2,120 +2,12 @@ import json import time from typing import Union - + +from .hallucinations import KNOWN_HALLUCINATIONS + ALPHABET = [*"abcdefghijklmnopqrstuvwxyz"] -# List of known hallucinations - adapted from: -# https://github.com/openai/whisper/discussions/928 -WHISPER_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", - ], - "es": [ - " 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社區提供" - ] -} + class Transcript: """ @@ -175,12 +67,14 @@ class Transcript: 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 language, snippets in WHISPER_HALLUCINATIONS.items(): - for snippet in snippets: - self.transcript[id]['text']=self.transcript[id]['text'].replace(snippet,'') + 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: