Сегментация: фикс резки по запятой, refine_span; датасет 6864 строк, переобучение
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
This commit is contained in:
1 parent
6be369c415
commit
bc9ff36e61
17 files changed
+9037
-272
No files matched your search
+23
-1
@@ -35,6 +35,27 @@ from .studio_norm import canonical
|
||||
from .train import MAX_LEN, decode_span
|
||||
|
||||
|
||||
# мусор, который модель иногда принимает за автора: раскладка каналов, кодеки
|
||||
RE_NOT_AUTHOR = re.compile(
|
||||
r"(?i)^[\s,/:+.\d]*(?:[LRC]|Ls|Rs|LFE|l|r|Front|Side|ch)?(?:[\s,/:+.\d]*(?:[LRC]|Ls|Rs|LFE|l|r|Front|Side|ch))*[\s,/:+.\d]*$"
|
||||
r"|dolby|digital|audio|kbps|khz|AC-?3|DTS|AAC|Opus")
|
||||
|
||||
|
||||
def refine_span(text: str, span: tuple[int, int] | None) -> tuple[int, int] | None:
|
||||
"""Постобработка спана автора: до границ слов; мусор и 1 символ -> None."""
|
||||
if span is None:
|
||||
return None
|
||||
a, z = span
|
||||
while a > 0 and text[a - 1].isalnum() and text[a].isalnum():
|
||||
a -= 1
|
||||
while z < len(text) and text[z].isalnum() and text[z - 1].isalnum():
|
||||
z += 1
|
||||
piece = text[a:z].strip()
|
||||
if len(piece) < 2 or RE_NOT_AUTHOR.search(piece):
|
||||
return None
|
||||
return a, z
|
||||
|
||||
|
||||
class DubPredictor:
|
||||
"""Загруженная модель для предсказания типа озвучки и автора."""
|
||||
|
||||
@@ -66,7 +87,8 @@ class DubPredictor:
|
||||
for i, text in enumerate(texts):
|
||||
tid = int(type_prob[i].argmax())
|
||||
aid = int(age_prob[i].argmax())
|
||||
span = decode_span(bio_pred[i], offsets[i], enc["attention_mask"][i].tolist())
|
||||
span = refine_span(text, decode_span(
|
||||
bio_pred[i], offsets[i], enc["attention_mask"][i].tolist()))
|
||||
span_text = text[span[0]:span[1]].strip() if span else None
|
||||
span_conf = None
|
||||
if span is not None:
|
||||
|
||||
Reference in new issue
Block a user