Acliptic v5 bundle
Browse files- README.md +72 -0
- acliptic/__init__.py +0 -0
- acliptic/config.py +38 -0
- acliptic/content_filters.py +72 -0
- acliptic/media.py +93 -0
- acliptic/models/__init__.py +0 -0
- acliptic/models/base.py +95 -0
- acliptic/models/moment_ranker5.py +96 -0
- acliptic/ranker.py +112 -0
- acliptic/ranker5.py +193 -0
- acliptic/shortlist.py +81 -0
- acliptic/sound.py +96 -0
- acliptic/transcribe.py +109 -0
- bge-onnx/config.json +31 -0
- bge-onnx/onnx/model.onnx +3 -0
- bge-onnx/quantize_config.json +30 -0
- bge-onnx/special_tokens_map.json +7 -0
- bge-onnx/tokenizer.json +0 -0
- bge-onnx/tokenizer_config.json +15 -0
- clap-onnx/config.json +27 -0
- clap-onnx/onnx/audio_model.onnx +3 -0
- clap-onnx/onnx/text_model.onnx +3 -0
- clap-onnx/preprocessor_config.json +22 -0
- clap-onnx/quantize_config.json +122 -0
- clap-onnx/special_tokens_map.json +15 -0
- clap-onnx/tokenizer.json +0 -0
- clap-onnx/tokenizer_config.json +63 -0
- clap-onnx/vocab.json +0 -0
- faster-whisper-base.en/.gitattributes +34 -0
- faster-whisper-base.en/README.md +42 -0
- faster-whisper-base.en/config.json +220 -0
- faster-whisper-base.en/model.bin +3 -0
- faster-whisper-base.en/tokenizer.json +0 -0
- faster-whisper-base.en/vocabulary.txt +0 -0
- ranker5.pkl +3 -0
README.md
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language: en
|
| 3 |
+
tags:
|
| 4 |
+
- acliptic
|
| 5 |
+
- clip-detection
|
| 6 |
+
- livestreams
|
| 7 |
+
- audio
|
| 8 |
+
---
|
| 9 |
+
|
| 10 |
+
# Acliptic v5
|
| 11 |
+
|
| 12 |
+
Finds the moments in a stream or podcast most worth clipping. It listens to the audio, reads the speech, and ranks every 30-second moment in the video.
|
| 13 |
+
|
| 14 |
+
v5 replaces the DeBERTa text classifier (v2). It isn't a `transformers` model, so `AutoModel.from_pretrained` won't load it. Use the code in this repo.
|
| 15 |
+
|
| 16 |
+
## What's in this repo
|
| 17 |
+
|
| 18 |
+
| Path | What it is | Trained by us? |
|
| 19 |
+
|---|---|---|
|
| 20 |
+
| `ranker5.pkl` | The ranker: gradient-boosted regressor, gradient-boosted classifier and logistic regression | Yes |
|
| 21 |
+
| `bge-onnx/` | `BAAI/bge-base-en-v1.5` (ONNX): meaning of the speech | No |
|
| 22 |
+
| `clap-onnx/` | CLAP `clap-htsat-unfused` (Xenova ONNX): sound fingerprints | No |
|
| 23 |
+
| `faster-whisper-base.en/` | Speech to text | No |
|
| 24 |
+
| `acliptic/` | The code that builds the inputs and runs the ranker | |
|
| 25 |
+
|
| 26 |
+
`ranker5.pkl` is a Python pickle. It needs the `acliptic` package from this repo and scikit-learn 1.9.1. Only load it from a source you trust.
|
| 27 |
+
|
| 28 |
+
## Use it
|
| 29 |
+
|
| 30 |
+
```python
|
| 31 |
+
import os
|
| 32 |
+
import sys
|
| 33 |
+
from huggingface_hub import snapshot_download
|
| 34 |
+
|
| 35 |
+
d = snapshot_download("umarfarzan/acliptic-v5", token=os.environ["HF_TOKEN"])
|
| 36 |
+
os.environ["ACLIPTIC_ASR_MODEL"] = f"{d}/faster-whisper-base.en"
|
| 37 |
+
os.environ["ACLIPTIC_CLAP_ONNX"] = f"{d}/clap-onnx"
|
| 38 |
+
os.environ["ACLIPTIC_TEXT_EMB_ONNX"] = f"{d}/bge-onnx"
|
| 39 |
+
sys.path.insert(0, d)
|
| 40 |
+
|
| 41 |
+
from acliptic.models.base import MediaInfo, ScoreRequest, Segment
|
| 42 |
+
from acliptic.models.moment_ranker5 import MomentRanker5Provider
|
| 43 |
+
|
| 44 |
+
model = MomentRanker5Provider("acliptic-v5", d, "5.0")
|
| 45 |
+
# segments: consecutive 30-second transcript chunks. path: the audio or video file.
|
| 46 |
+
req = ScoreRequest(segments=[Segment(0, 0, 30, "text of the first 30 seconds"), Segment(1, 30, 60, "text of the next 30 seconds")],
|
| 47 |
+
media=MediaInfo(duration=60, has_audio=True, path="video.mp4"))
|
| 48 |
+
print(model.score(req))
|
| 49 |
+
```
|
| 50 |
+
|
| 51 |
+
Scores rank moments within one video. They aren't probabilities, and they can't be compared across videos. There's no threshold: take the top moments per video or hour. `MediaInfo(live=True)` uses the live model, which only looks at what has already happened.
|
| 52 |
+
|
| 53 |
+
## Data and results
|
| 54 |
+
|
| 55 |
+
- **Training:** 19 VODs, 50.6 hours, 8 streamers, labelled with YouTube Most Replayed data.
|
| 56 |
+
- **Test:** 24 unseen VODs, 65 hours, 22 streamers.
|
| 57 |
+
|
| 58 |
+
| Measure | Random | App with v2 | v5 |
|
| 59 |
+
|---|---|---|---|
|
| 60 |
+
| AUC | 0.500 | 0.507 | **0.599** |
|
| 61 |
+
| Top 6 picks per hour in the top 20% rewatched | 20% | 29.5% | **37.3%** |
|
| 62 |
+
| Top 6 picks per hour in the top 5% rewatched | 5% | 7.8% | **10.2%** |
|
| 63 |
+
|
| 64 |
+
The gain on the top 5% could be luck. About 6 in 10 picks still miss the top 20%.
|
| 65 |
+
|
| 66 |
+
## Limits
|
| 67 |
+
|
| 68 |
+
- English only.
|
| 69 |
+
- Trained on VODs up to 4.2 hours. Longer videos are untested.
|
| 70 |
+
- Doesn't use live chat.
|
| 71 |
+
- Weak on some fast gameplay streams. Tfue scored 0.36 AUC, worse than random.
|
| 72 |
+
- Without audio it runs from text alone, which hasn't been measured.
|
acliptic/__init__.py
ADDED
|
File without changes
|
acliptic/config.py
ADDED
|
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Settings, read once from environment variables (all optional)."""
|
| 2 |
+
import json
|
| 3 |
+
import os
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
|
| 6 |
+
APP_ROOT = Path(__file__).resolve().parents[2] # acliptic-app/
|
| 7 |
+
BACKEND = APP_ROOT / "backend"
|
| 8 |
+
DATA_DIR = Path(os.environ.get("ACLIPTIC_DATA", APP_ROOT / "data"))
|
| 9 |
+
WEB_DIST = APP_ROOT / "web" / "dist"
|
| 10 |
+
|
| 11 |
+
MODELS_FILE = Path(os.environ.get("ACLIPTIC_MODELS_FILE", BACKEND / "models.json"))
|
| 12 |
+
ACTIVE_MODEL = os.environ.get("ACLIPTIC_MODEL") # overrides "active" in models.json
|
| 13 |
+
MODEL_TIMEOUT_S = float(os.environ.get("ACLIPTIC_MODEL_TIMEOUT_S", 900))
|
| 14 |
+
|
| 15 |
+
MAX_UPLOAD_BYTES = int(float(os.environ.get("ACLIPTIC_MAX_UPLOAD_GB", 8)) * 1024 ** 3)
|
| 16 |
+
MAX_MINUTES = int(os.environ.get("ACLIPTIC_MAX_MINUTES", 240)) # longest stretch of a video we process
|
| 17 |
+
WHISPER_MODEL = os.environ.get("ACLIPTIC_WHISPER", "openai/whisper-base.en") # fallback only (transformers)
|
| 18 |
+
_ASR_DIR = APP_ROOT.parent / "model-testing" / "models" / "asr"
|
| 19 |
+
ASR_MODEL = Path(os.environ.get("ACLIPTIC_ASR_MODEL", _ASR_DIR / "faster-whisper-base.en")) # whole-video pass
|
| 20 |
+
CAPTION_MODEL = Path(os.environ.get("ACLIPTIC_CAPTION_MODEL", _ASR_DIR / "faster-whisper-small.en")) # clip captions
|
| 21 |
+
TEXT_EMB_MODEL = Path(os.environ.get("ACLIPTIC_TEXT_EMB_MODEL", APP_ROOT.parent / "model-testing" / "models" / "bge-base-en-v1.5"))
|
| 22 |
+
CLIP_ONNX = Path(os.environ.get("ACLIPTIC_CLIP_ONNX", APP_ROOT.parent / "model-testing" / "models" / "clip-onnx"))
|
| 23 |
+
CLAP_ONNX = Path(os.environ.get("ACLIPTIC_CLAP_ONNX", APP_ROOT.parent / "model-testing" / "models" / "clap-onnx"))
|
| 24 |
+
TEXT_EMB_ONNX = Path(os.environ.get("ACLIPTIC_TEXT_EMB_ONNX", APP_ROOT.parent / "model-testing" / "models" / "bge-onnx"))
|
| 25 |
+
CLAP_MODEL = Path(os.environ.get("ACLIPTIC_CLAP_MODEL", APP_ROOT.parent / "model-testing" / "models" / "clap"))
|
| 26 |
+
ASR_WORKERS = int(os.environ.get("ACLIPTIC_ASR_WORKERS", 4))
|
| 27 |
+
ASR_THREADS = int(os.environ.get("ACLIPTIC_ASR_THREADS", os.cpu_count() or 8))
|
| 28 |
+
SESSION_DAYS = 30
|
| 29 |
+
COOKIE_SECURE = os.environ.get("ACLIPTIC_COOKIE_SECURE", "0") == "1" # set to 1 behind HTTPS
|
| 30 |
+
|
| 31 |
+
LINK_HOSTS = ("youtube.com", "youtu.be", "twitch.tv", "kick.com") # what "paste a link" accepts
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
def model_registry() -> dict:
|
| 35 |
+
cfg = json.loads(MODELS_FILE.read_text(encoding="utf-8"))
|
| 36 |
+
if ACTIVE_MODEL:
|
| 37 |
+
cfg["active"] = ACTIVE_MODEL
|
| 38 |
+
return cfg
|
acliptic/content_filters.py
ADDED
|
@@ -0,0 +1,72 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Content filters, carried over unchanged from model-testing/deploy (tested on podcasts, streams and viral shorts):
|
| 2 |
+
sponsor reads, stream housekeeping, and safety flags (slurs / self-harm talk) for review."""
|
| 3 |
+
import re
|
| 4 |
+
|
| 5 |
+
STRONG = [
|
| 6 |
+
r"\b(use|enter|with) (the |my |our )?(promo |discount |offer )?code\b",
|
| 7 |
+
r"\bpromo code\b",
|
| 8 |
+
r"\b[a-z0-9]+ ?(\.|dot) ?(com|co|io|net) ?(/|slash)\s?\w+",
|
| 9 |
+
r"\bgo to [a-z0-9]+ ?(\.|dot) ?(com|co|io|net)\b",
|
| 10 |
+
r"\b(brought to you|sponsored|presented) by\b",
|
| 11 |
+
r"\b(today'?s|this episode'?s|our|a) (sponsor|new partner)\b",
|
| 12 |
+
r"\bwe'?ve got a new partner\b",
|
| 13 |
+
r"\blink (is )?in (the )?(description|show notes|bio)\b",
|
| 14 |
+
r"\bno upfront fees?\b",
|
| 15 |
+
r"\bfree shipping\b",
|
| 16 |
+
r"\b\d+ ?(%|percent) off\b",
|
| 17 |
+
r"\bfirst (order|month|box)\b",
|
| 18 |
+
r"\b(we|i) recommend you (give|try)\b",
|
| 19 |
+
]
|
| 20 |
+
WEAK = [
|
| 21 |
+
r"\bproducts?\b", r"\bbrand\b", r"\bingredients\b", r"\ball[ -]natural\b", r"\bno (filler|junk|middlemen)\b",
|
| 22 |
+
r"\b(hormone|antibiotic|gluten|sugar)[ -]free\b", r"\bgrass[ -]fed\b", r"\bpasture[ -]raised\b",
|
| 23 |
+
r"\b(customers|members|subscribers) (are )?sav", r"\bsign up\b", r"\bdownload (the|their) app\b",
|
| 24 |
+
r"\b(order|try|get) (it|yours|them) (now|today)\b", r"\blimited time\b", r"\bguarantee\b",
|
| 25 |
+
r"\bhomeowners\b", r"\bconsolidate\b", r"\bsubscription\b", r"\bdelicious\b", r"\bunlike other\b",
|
| 26 |
+
r"\b(they'?ve|we'?ve) created\b", r"\bis the answer\b", r"\bpromos?\b", r"\bdiscounts?\b",
|
| 27 |
+
r"\b(lineups?|sportsbook|first deposit)\b", r"\b(has|have) you covered\b", r"\bavailable in (most|all) states\b",
|
| 28 |
+
r"\b(next-gen |new )?formula\b", r"\b(vitamins|minerals|adaptogens|probiotics|prebiotics|superfoods?)\b",
|
| 29 |
+
r"\bdesigned to (help|support)\b",
|
| 30 |
+
]
|
| 31 |
+
_STRONG = [re.compile(p) for p in STRONG]
|
| 32 |
+
_WEAK = [re.compile(p) for p in WEAK]
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def ad_cues(text: str):
|
| 36 |
+
t = " ".join(text.lower().replace("’", "'").split())
|
| 37 |
+
return sum(bool(p.search(t)) for p in _STRONG), sum(bool(p.search(t)) for p in _WEAK)
|
| 38 |
+
|
| 39 |
+
|
| 40 |
+
def is_ad(text: str) -> bool:
|
| 41 |
+
strong, weak = ad_cues(text)
|
| 42 |
+
return strong >= 1 or weak >= 2
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
# Stream housekeeping: coming back from a break, reading chat / super chats, plugging a site. These are loud
|
| 46 |
+
# and lively, so they score high, but nobody clips them.
|
| 47 |
+
FILLER = [
|
| 48 |
+
r"\b(we|i)'?(re| are|m| am)? back\b.{0,40}\b(break|intermission|bathroom|chat)\b",
|
| 49 |
+
r"\b(intermission|be right back|brb|starting soon|stream (is )?(starting|ending|over))\b",
|
| 50 |
+
r"\bget your (questions|comments|super ?chats?) in\b", r"\bsuper ?chats?\b", r"\b(type|drop) (it )?in (the )?chat\b",
|
| 51 |
+
r"\b(like|subscribe) (and|&) (subscribe|like|share)\b", r"\bhit (the|that) (like|subscribe) button\b",
|
| 52 |
+
r"\b[a-z0-9]{3,}\.(com|tv|gg|net)\b",
|
| 53 |
+
]
|
| 54 |
+
_FILLER = [re.compile(p) for p in FILLER]
|
| 55 |
+
|
| 56 |
+
|
| 57 |
+
def is_filler(text: str) -> bool:
|
| 58 |
+
t = " ".join(text.lower().replace("’", "'").split())
|
| 59 |
+
return sum(bool(p.search(t)) for p in _FILLER) >= 1
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
SLURS = [r"\bn[i1]gg(a|er|ah|as|ers)\b", r"\bporch ?monkey", r"\bf[a@]gg?(ot|s)?\b", r"\bretard(ed|s)?\b",
|
| 63 |
+
r"\bch[i1]nk\b", r"\bsp[i1]c\b", r"\btr[a@]nn(y|ies)\b", r"\bk[i1]ke\b"]
|
| 64 |
+
SELF_HARM = [r"\b(kill|killing|hang|shoot) (myself|yourself)\b", r"\bkms\b", r"\bsuicid(e|al)\b",
|
| 65 |
+
r"\b(end|ending) (my|your) life\b", r"\bi'?m (going to|gonna) jump\b"]
|
| 66 |
+
_CHECKS = {"slur": [re.compile(p) for p in SLURS], "self-harm": [re.compile(p) for p in SELF_HARM]}
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
def safety_flags(text: str) -> list:
|
| 70 |
+
"""Names of the checks this text trips, e.g. ["slur"]. Empty list = fine to auto-post."""
|
| 71 |
+
t = " ".join(text.lower().replace("’", "'").split())
|
| 72 |
+
return [name for name, pats in _CHECKS.items() if any(p.search(t) for p in pats)]
|
acliptic/media.py
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""ffmpeg helpers: probe, make browser-playable, audio loudness, still frames."""
|
| 2 |
+
import re
|
| 3 |
+
import subprocess
|
| 4 |
+
from pathlib import Path
|
| 5 |
+
|
| 6 |
+
import imageio_ffmpeg
|
| 7 |
+
import numpy as np
|
| 8 |
+
|
| 9 |
+
FFMPEG = imageio_ffmpeg.get_ffmpeg_exe()
|
| 10 |
+
|
| 11 |
+
|
| 12 |
+
class MediaError(Exception):
|
| 13 |
+
pass
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
def run(cmd, cwd=None, timeout=None):
|
| 17 |
+
r = subprocess.run(cmd, capture_output=True, text=True, encoding="utf-8", errors="replace", cwd=cwd, timeout=timeout)
|
| 18 |
+
if r.returncode:
|
| 19 |
+
raise MediaError((r.stderr or r.stdout).strip().splitlines()[-1] if (r.stderr or r.stdout).strip() else "ffmpeg failed")
|
| 20 |
+
return r
|
| 21 |
+
|
| 22 |
+
|
| 23 |
+
def probe(path: Path) -> dict:
|
| 24 |
+
"""Duration, size, codecs and whether there's an audio track, from ffmpeg's stream summary."""
|
| 25 |
+
r = subprocess.run([FFMPEG, "-hide_banner", "-i", str(path)], capture_output=True, text=True, encoding="utf-8",
|
| 26 |
+
errors="replace")
|
| 27 |
+
err = r.stderr
|
| 28 |
+
m = re.search(r"Duration: (\d+):(\d+):([\d.]+)", err)
|
| 29 |
+
if not m:
|
| 30 |
+
raise MediaError("This file isn't a video we can read.")
|
| 31 |
+
v = re.search(r"Stream #.*Video: (\w+).*?, (\d{2,5})x(\d{2,5})", err)
|
| 32 |
+
if not v:
|
| 33 |
+
raise MediaError("No video track found in this file.")
|
| 34 |
+
a = re.search(r"Stream #.*Audio: (\w+)", err)
|
| 35 |
+
h, mi, s = m.groups()
|
| 36 |
+
return {"duration": int(h) * 3600 + int(mi) * 60 + float(s), "vcodec": v.group(1), "width": int(v.group(2)),
|
| 37 |
+
"height": int(v.group(3)), "acodec": a.group(1) if a else None,
|
| 38 |
+
"container": Path(path).suffix.lower()}
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
def make_playable(src: Path, dst: Path, max_seconds: float, progress=None) -> dict:
|
| 42 |
+
"""Keep H.264/AAC MP4 as is (just trimmed if too long); transcode anything else to a 720p MP4 proxy so
|
| 43 |
+
every browser can play it and rendering behaves the same."""
|
| 44 |
+
info = probe(src)
|
| 45 |
+
ok = info["container"] in (".mp4", ".m4v", ".mov") and info["vcodec"] == "h264" and info["acodec"] in (None, "aac")
|
| 46 |
+
if ok and info["duration"] <= max_seconds + 1:
|
| 47 |
+
if src != dst:
|
| 48 |
+
src.replace(dst)
|
| 49 |
+
return probe(dst)
|
| 50 |
+
cmd = [FFMPEG, "-y", "-v", "error", "-progress", "pipe:1", "-i", str(src), "-t", str(max_seconds)]
|
| 51 |
+
if ok:
|
| 52 |
+
cmd += ["-c", "copy"]
|
| 53 |
+
else:
|
| 54 |
+
cmd += ["-vf", "scale='min(1920,iw)':-2", "-c:v", "libx264", "-preset", "veryfast", "-crf", "20",
|
| 55 |
+
"-c:a", "aac", "-b:a", "128k"]
|
| 56 |
+
cmd += ["-movflags", "+faststart", str(dst)]
|
| 57 |
+
p = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True, encoding="utf-8",
|
| 58 |
+
errors="replace")
|
| 59 |
+
total = min(info["duration"], max_seconds)
|
| 60 |
+
for line in p.stdout:
|
| 61 |
+
if line.startswith("out_time_ms=") and progress and line.strip().split("=")[1].isdigit():
|
| 62 |
+
progress(min(1.0, int(line.strip().split("=")[1]) / 1e6 / max(total, 1)))
|
| 63 |
+
if p.wait():
|
| 64 |
+
raise MediaError("Couldn't convert this video: " + (p.stderr.read().strip().splitlines() or ["unknown error"])[-1])
|
| 65 |
+
if src != dst:
|
| 66 |
+
src.unlink(missing_ok=True)
|
| 67 |
+
return probe(dst)
|
| 68 |
+
|
| 69 |
+
|
| 70 |
+
def audio_pcm(path: Path, rate: int, seconds: float) -> np.ndarray:
|
| 71 |
+
raw = subprocess.run([FFMPEG, "-v", "error", "-i", str(path), "-t", str(seconds), "-ac", "1", "-ar", str(rate),
|
| 72 |
+
"-f", "s16le", "-"], capture_output=True).stdout
|
| 73 |
+
return np.frombuffer(raw, np.int16).astype(np.float32) / 32768
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def loudness(path: Path, n_segments: int, seg: float = 30.0) -> tuple[np.ndarray, np.ndarray]:
|
| 77 |
+
"""Per segment: mean and max of per-second RMS level (dB)."""
|
| 78 |
+
x = audio_pcm(path, 2000, n_segments * seg)
|
| 79 |
+
secs = len(x) // 2000
|
| 80 |
+
if secs == 0:
|
| 81 |
+
return np.full(n_segments, -100.0), np.full(n_segments, -100.0)
|
| 82 |
+
db = 20 * np.log10(np.sqrt((x[:secs * 2000].reshape(secs, 2000) ** 2).mean(1) + 1e-10))
|
| 83 |
+
db = np.pad(db, (0, max(0, int(n_segments * seg) - len(db))), constant_values=db.min())[:int(n_segments * seg)]
|
| 84 |
+
db = db.reshape(n_segments, int(seg))
|
| 85 |
+
return db.mean(1), db.max(1)
|
| 86 |
+
|
| 87 |
+
|
| 88 |
+
def frame(path: Path, t: float, out: Path, width: int = 640) -> Path:
|
| 89 |
+
if not out.exists():
|
| 90 |
+
out.parent.mkdir(parents=True, exist_ok=True)
|
| 91 |
+
run([FFMPEG, "-y", "-v", "error", "-ss", f"{max(0.0, t):.2f}", "-i", str(path), "-frames:v", "1",
|
| 92 |
+
"-vf", f"scale={width}:-2", "-q:v", "4", str(out)])
|
| 93 |
+
return out
|
acliptic/models/__init__.py
ADDED
|
File without changes
|
acliptic/models/base.py
ADDED
|
@@ -0,0 +1,95 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""The model-provider contract. Every model (dev sample, v2, v3, anything later) is an adapter implementing
|
| 2 |
+
`ModelProvider`. The pipeline only ever talks to this interface.
|
| 3 |
+
|
| 4 |
+
Input (ScoreRequest)
|
| 5 |
+
segments consecutive transcript chunks of the video, ~30 s each: index, start, end (seconds), text
|
| 6 |
+
media facts about the source: duration (s), has_audio, language, and the file path for models that listen
|
| 7 |
+
Output (ScoreResponse)
|
| 8 |
+
scores one SegmentScore per input segment, same order: index + score in [0, 1]
|
| 9 |
+
(higher = more likely worth clipping). A ranking signal, not a probability of going viral.
|
| 10 |
+
model_id, model_version, kind ("real" | "development"), latency_ms
|
| 11 |
+
|
| 12 |
+
Adapters declare what they can use in `capabilities` ({"text"}, later e.g. {"text", "audio"}); the runner
|
| 13 |
+
refuses a request the adapter can't serve (UnsupportedCapability), enforces a timeout (ModelTimeout) and
|
| 14 |
+
validates the output (ModelError) so a bad model never writes bad data.
|
| 15 |
+
"""
|
| 16 |
+
from __future__ import annotations
|
| 17 |
+
|
| 18 |
+
from abc import ABC, abstractmethod
|
| 19 |
+
from dataclasses import dataclass, field
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
class ModelError(Exception):
|
| 23 |
+
"""The model ran but returned something unusable, or failed."""
|
| 24 |
+
|
| 25 |
+
|
| 26 |
+
class ModelUnavailable(ModelError):
|
| 27 |
+
"""The model can't be loaded (missing files, bad config)."""
|
| 28 |
+
|
| 29 |
+
|
| 30 |
+
class ModelTimeout(ModelError):
|
| 31 |
+
"""The model took longer than the configured timeout."""
|
| 32 |
+
|
| 33 |
+
|
| 34 |
+
class UnsupportedCapability(ModelError):
|
| 35 |
+
"""The request needs an input this model doesn't support."""
|
| 36 |
+
|
| 37 |
+
|
| 38 |
+
@dataclass
|
| 39 |
+
class Segment:
|
| 40 |
+
index: int
|
| 41 |
+
start: float
|
| 42 |
+
end: float
|
| 43 |
+
text: str
|
| 44 |
+
|
| 45 |
+
|
| 46 |
+
@dataclass
|
| 47 |
+
class MediaInfo:
|
| 48 |
+
duration: float
|
| 49 |
+
has_audio: bool
|
| 50 |
+
language: str = "en"
|
| 51 |
+
path: str | None = None # the media file, for models that listen (capability "audio")
|
| 52 |
+
live: bool = False # scoring a stream as it happens: only the past may be used
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
@dataclass
|
| 56 |
+
class ScoreRequest:
|
| 57 |
+
segments: list[Segment]
|
| 58 |
+
media: MediaInfo
|
| 59 |
+
needs: set[str] = field(default_factory=lambda: {"text"})
|
| 60 |
+
|
| 61 |
+
|
| 62 |
+
@dataclass
|
| 63 |
+
class SegmentScore:
|
| 64 |
+
index: int
|
| 65 |
+
score: float
|
| 66 |
+
|
| 67 |
+
|
| 68 |
+
@dataclass
|
| 69 |
+
class ModelInfo:
|
| 70 |
+
id: str
|
| 71 |
+
version: str
|
| 72 |
+
display_name: str
|
| 73 |
+
kind: str # "real" | "development"
|
| 74 |
+
capabilities: set[str] # e.g. {"text"}
|
| 75 |
+
min_score: float = 0.0 # segments below this are never shortlisted
|
| 76 |
+
ranks_moments: bool = False # scores already combine every signal; the shortlist uses them as the ranking
|
| 77 |
+
notes: str = ""
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
@dataclass
|
| 81 |
+
class ScoreResponse:
|
| 82 |
+
scores: list[SegmentScore]
|
| 83 |
+
model_id: str
|
| 84 |
+
model_version: str
|
| 85 |
+
kind: str
|
| 86 |
+
latency_ms: int = 0
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
class ModelProvider(ABC):
|
| 90 |
+
@abstractmethod
|
| 91 |
+
def info(self) -> ModelInfo: ...
|
| 92 |
+
|
| 93 |
+
@abstractmethod
|
| 94 |
+
def score(self, req: ScoreRequest) -> list[SegmentScore]:
|
| 95 |
+
"""Return one score per request segment. Raise ModelError on failure."""
|
acliptic/models/moment_ranker5.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Adapter for Acliptic v5 (acliptic/ranker5.py): sound fingerprints + speech meaning + loudness + talk cues, judged
|
| 2 |
+
in context. Needs no PyTorch and no separate text model (only ONNX Runtime and scikit-learn).
|
| 3 |
+
|
| 4 |
+
models.json: {"type": "moment_ranker5", "path": "<dir with ranker5.pkl>", "version": "5.0"}
|
| 5 |
+
Without audio, the sound and loudness inputs are missing and the ranker works from the transcript alone.
|
| 6 |
+
"""
|
| 7 |
+
from __future__ import annotations
|
| 8 |
+
|
| 9 |
+
import numpy as np
|
| 10 |
+
import pandas as pd
|
| 11 |
+
|
| 12 |
+
from .base import ModelInfo, ModelProvider, ModelUnavailable, ScoreRequest, SegmentScore
|
| 13 |
+
|
| 14 |
+
CHUNK_SEGS = 20 # decode 10 minutes at a time
|
| 15 |
+
|
| 16 |
+
|
| 17 |
+
class MomentRanker5Provider(ModelProvider):
|
| 18 |
+
def __init__(self, id_: str, path: str, version: str, display_name: str = "", **_):
|
| 19 |
+
self.id, self.path, self.version = id_, path, version
|
| 20 |
+
self.display_name = display_name or f"Acliptic v{version}"
|
| 21 |
+
self._ranker = None
|
| 22 |
+
|
| 23 |
+
def info(self) -> ModelInfo:
|
| 24 |
+
return ModelInfo(id=self.id, version=self.version, display_name=self.display_name, kind="real",
|
| 25 |
+
capabilities={"text", "audio"}, min_score=0.0, ranks_moments=True,
|
| 26 |
+
notes="Sound fingerprints + speech meaning + loudness, in context; trained on Most Replayed data "
|
| 27 |
+
"from real streams.")
|
| 28 |
+
|
| 29 |
+
def _load(self):
|
| 30 |
+
if self._ranker is None:
|
| 31 |
+
try:
|
| 32 |
+
from ..ranker5 import Ranker5
|
| 33 |
+
self._ranker = Ranker5(self.path)
|
| 34 |
+
except FileNotFoundError as e:
|
| 35 |
+
raise ModelUnavailable(f"{self.display_name}: ranker5.pkl not found in {self.path}") from e
|
| 36 |
+
return self._ranker
|
| 37 |
+
|
| 38 |
+
@staticmethod
|
| 39 |
+
def _audio_parts(path: str, n: int):
|
| 40 |
+
"""Loudness and CLAP embeddings for n segments, decoding 10 minutes at a time."""
|
| 41 |
+
from .. import sound
|
| 42 |
+
from ..ranker import SEG, SR, loudness
|
| 43 |
+
from ..transcribe import audio_pcm_range
|
| 44 |
+
louds, embs = [], []
|
| 45 |
+
for a in range(0, n, CHUNK_SEGS):
|
| 46 |
+
k = min(CHUNK_SEGS, n - a)
|
| 47 |
+
audio = audio_pcm_range(path, a * SEG, (a + k) * SEG)
|
| 48 |
+
audio = np.pad(audio, (0, max(0, k * SEG * SR - len(audio))))
|
| 49 |
+
louds.append(pd.DataFrame(loudness(audio, k)))
|
| 50 |
+
embs.append(sound.embeddings(audio, k))
|
| 51 |
+
return pd.concat(louds, ignore_index=True), np.concatenate(embs)
|
| 52 |
+
|
| 53 |
+
def signals(self, req: ScoreRequest):
|
| 54 |
+
from .. import config, sound
|
| 55 |
+
from ..ranker5 import text_embeddings
|
| 56 |
+
texts = [s.text for s in req.segments]
|
| 57 |
+
raw = pd.DataFrame({"transcript": texts, "n_words": [len(t.split()) for t in texts]})
|
| 58 |
+
temb = text_embeddings(texts, config.TEXT_EMB_ONNX)
|
| 59 |
+
clap = None
|
| 60 |
+
if req.media.has_audio and req.media.path:
|
| 61 |
+
loud, clap = self._audio_parts(req.media.path, len(texts))
|
| 62 |
+
raw = pd.concat([raw, loud], axis=1)
|
| 63 |
+
for k, v in sound.scores(clap).items():
|
| 64 |
+
raw[k] = v
|
| 65 |
+
return raw, clap, temb
|
| 66 |
+
|
| 67 |
+
def score(self, req: ScoreRequest) -> list[SegmentScore]:
|
| 68 |
+
raw, clap, temb = self.signals(req)
|
| 69 |
+
s = self._load().score(raw, clap, temb, causal=req.media.live)
|
| 70 |
+
# the ranker may be a regressor; a within-video percentile keeps scores in [0, 1] and preserves the order
|
| 71 |
+
s = pd.Series(np.asarray(s, float)).rank(pct=True).values if len(s) > 1 else np.clip(s, 0, 1)
|
| 72 |
+
return [SegmentScore(seg.index, float(v)) for seg, v in zip(req.segments, s)]
|
| 73 |
+
|
| 74 |
+
# ---- live: one chunk at a time, ranked against the past only ----
|
| 75 |
+
def live_score(self, f, dur, text, has_audio, state: dict) -> float:
|
| 76 |
+
from .. import config, sound
|
| 77 |
+
from ..ranker import SR, loudness_one
|
| 78 |
+
from ..ranker5 import text_embeddings
|
| 79 |
+
from ..transcribe import audio_pcm_range
|
| 80 |
+
rows, claps, tembs = state.setdefault("rows", []), state.setdefault("clap", []), state.setdefault("temb", [])
|
| 81 |
+
row = {"transcript": text, "n_words": len(text.split())}
|
| 82 |
+
clap = np.full(512, np.nan, np.float32)
|
| 83 |
+
if has_audio:
|
| 84 |
+
audio = audio_pcm_range(f, 0, dur)
|
| 85 |
+
if len(audio) >= SR:
|
| 86 |
+
row |= loudness_one(audio)
|
| 87 |
+
clap = sound.embeddings(audio, 1)[0]
|
| 88 |
+
row |= {k: float(v[0]) for k, v in sound.scores(clap[None]).items()}
|
| 89 |
+
rows.append(row)
|
| 90 |
+
claps.append(clap)
|
| 91 |
+
tembs.append(text_embeddings([text], config.TEXT_EMB_ONNX)[0])
|
| 92 |
+
if len(rows) < 4:
|
| 93 |
+
return 0.5
|
| 94 |
+
c = np.vstack(claps)
|
| 95 |
+
c = None if np.isnan(c).any() else c
|
| 96 |
+
return float(self._load().score(pd.DataFrame(rows), c, np.vstack(tembs), causal=True)[-1])
|
acliptic/ranker.py
ADDED
|
@@ -0,0 +1,112 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Acliptic v4: a moment ranker. It scores each 30 s segment from what was said (the v2 speech model), how loud it is
|
| 2 |
+
against the surrounding minutes, and what it sounds like (laughter, screaming, cheering, gunfire... via sound.py),
|
| 3 |
+
with a small gradient-boosted model trained on YouTube "Most Replayed" data from 40+ hours of real streams.
|
| 4 |
+
|
| 5 |
+
The feature code here is imported by the training script (model-testing/v4_train.py), so training and serving
|
| 6 |
+
compute exactly the same numbers."""
|
| 7 |
+
import pickle
|
| 8 |
+
import threading
|
| 9 |
+
from pathlib import Path
|
| 10 |
+
|
| 11 |
+
import numpy as np
|
| 12 |
+
import pandas as pd
|
| 13 |
+
|
| 14 |
+
SEG = 30
|
| 15 |
+
SR = 16000
|
| 16 |
+
RAW = ["text_v2", "n_words", "db_mean", "db_max", "db_std", "db_p90",
|
| 17 |
+
"snd_laugh", "snd_scream", "snd_crowd", "snd_gasp", "snd_music", "snd_action", "snd_speech", "snd_silence", "snd_game"]
|
| 18 |
+
CHAT = ["chat_n", "chat_react"] # evaluated as a baseline only: the app has no chat feed, so v4 doesn't use it
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def loudness(audio: np.ndarray, n_seg: int) -> dict:
|
| 22 |
+
"""Per segment, from per-second RMS level (dB) of 16 kHz mono audio."""
|
| 23 |
+
secs = len(audio) // SR
|
| 24 |
+
x = audio[:secs * SR].reshape(secs, SR)
|
| 25 |
+
db = 20 * np.log10(np.sqrt((x ** 2).mean(1) + 1e-10))
|
| 26 |
+
db = np.pad(db, (0, max(0, n_seg * SEG - len(db))), constant_values=db.min() if len(db) else -80)[:n_seg * SEG]
|
| 27 |
+
w = db.reshape(n_seg, SEG)
|
| 28 |
+
return {"db_mean": w.mean(1), "db_max": w.max(1), "db_std": w.std(1), "db_p90": np.percentile(w, 90, axis=1)}
|
| 29 |
+
|
| 30 |
+
|
| 31 |
+
def loudness_one(audio: np.ndarray) -> dict:
|
| 32 |
+
"""loudness() for a single segment of any length (live chunks run 12-30 s)."""
|
| 33 |
+
secs = max(1, len(audio) // SR)
|
| 34 |
+
x = np.pad(audio, (0, max(0, secs * SR - len(audio))))[:secs * SR].reshape(secs, SR)
|
| 35 |
+
db = 20 * np.log10(np.sqrt((x ** 2).mean(1) + 1e-10))
|
| 36 |
+
return {"db_mean": float(db.mean()), "db_max": float(db.max()), "db_std": float(db.std()), "db_p90": float(np.percentile(db, 90))}
|
| 37 |
+
|
| 38 |
+
|
| 39 |
+
def rolling_z(x, w=20, causal=False):
|
| 40 |
+
s = pd.Series(np.asarray(x, float))
|
| 41 |
+
if causal:
|
| 42 |
+
med = s.shift(1).rolling(w, min_periods=4).median()
|
| 43 |
+
mad = (s.shift(1) - med).abs().rolling(w, min_periods=4).median()
|
| 44 |
+
else:
|
| 45 |
+
med = s.rolling(2 * w + 1, center=True, min_periods=5).median()
|
| 46 |
+
mad = (s - med).abs().rolling(2 * w + 1, center=True, min_periods=5).median()
|
| 47 |
+
return ((s - med) / (1.4826 * mad + 1e-6)).clip(-8, 8).fillna(0).values
|
| 48 |
+
|
| 49 |
+
|
| 50 |
+
def causal_pct(x, w=120):
|
| 51 |
+
x = np.asarray(x, float)
|
| 52 |
+
return np.array([(x[max(0, i - w):i] < x[i]).mean() if i >= 10 else 0.5 for i in range(len(x))])
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def featurize(g: pd.DataFrame, causal: bool = False) -> pd.DataFrame:
|
| 56 |
+
"""Per-video features from raw per-segment signals. causal=True uses only the past (live clipping)."""
|
| 57 |
+
f = pd.DataFrame(index=g.index)
|
| 58 |
+
for c in RAW:
|
| 59 |
+
if c not in g or g[c].isna().all():
|
| 60 |
+
continue
|
| 61 |
+
x = g[c].fillna(0).values.astype(float)
|
| 62 |
+
f[c] = x
|
| 63 |
+
f[c + "_z"] = rolling_z(x, causal=causal)
|
| 64 |
+
f[c + "_pct"] = causal_pct(x) if causal else pd.Series(x).rank(pct=True).values
|
| 65 |
+
f[c + "_dprev"] = x - np.r_[x[:1], x[:-1]]
|
| 66 |
+
return f
|
| 67 |
+
|
| 68 |
+
|
| 69 |
+
class Logistic:
|
| 70 |
+
"""Standardised logistic regression (one of the model types v4 training may pick); NaN (missing signal) -> 0."""
|
| 71 |
+
|
| 72 |
+
def __init__(self):
|
| 73 |
+
from sklearn.linear_model import LogisticRegression
|
| 74 |
+
self.m = LogisticRegression(C=0.05, max_iter=2000, class_weight="balanced")
|
| 75 |
+
|
| 76 |
+
def fit(self, X, y):
|
| 77 |
+
self.cols, self.mu, self.sd = X.columns, X.mean(), X.std().replace(0, 1)
|
| 78 |
+
self.m.fit(((X - self.mu) / self.sd).fillna(0).clip(-6, 6), y)
|
| 79 |
+
return self
|
| 80 |
+
|
| 81 |
+
def predict_proba(self, X):
|
| 82 |
+
return self.m.predict_proba(((X[self.cols] - self.mu) / self.sd).fillna(0).clip(-6, 6))
|
| 83 |
+
|
| 84 |
+
|
| 85 |
+
class Ranker:
|
| 86 |
+
"""Loads ranker.pkl (written by v4_train.py) and scores a video's segments."""
|
| 87 |
+
|
| 88 |
+
def __init__(self, path: str | Path):
|
| 89 |
+
with open(Path(path) / "ranker.pkl", "rb") as fh:
|
| 90 |
+
b = pickle.load(fh)
|
| 91 |
+
self.model, self.cols = b["model"], b["columns"]
|
| 92 |
+
self.live_model, self.live_cols = b.get("live_model"), b.get("live_columns")
|
| 93 |
+
self._lock = threading.Lock()
|
| 94 |
+
|
| 95 |
+
def score(self, raw: pd.DataFrame, causal: bool = False) -> np.ndarray:
|
| 96 |
+
m, cols = (self.live_model, self.live_cols) if causal and self.live_model is not None else (self.model, self.cols)
|
| 97 |
+
X = featurize(raw, causal).reindex(columns=cols)
|
| 98 |
+
with self._lock:
|
| 99 |
+
return m.predict_proba(X)[:, 1]
|
| 100 |
+
|
| 101 |
+
|
| 102 |
+
def raw_signals(audio16k: np.ndarray, texts: list[str], text_scores, n_seg: int, with_sound: bool = True) -> pd.DataFrame:
|
| 103 |
+
"""Everything the ranker needs for one video, in the training data's column names."""
|
| 104 |
+
from . import sound
|
| 105 |
+
df = pd.DataFrame({"text_v2": np.asarray(text_scores, float), "n_words": [len(t.split()) for t in texts]})
|
| 106 |
+
if len(audio16k) >= SR:
|
| 107 |
+
for k, v in loudness(audio16k, n_seg).items():
|
| 108 |
+
df[k] = v
|
| 109 |
+
if with_sound:
|
| 110 |
+
for k, v in sound.scores(sound.embeddings(audio16k, n_seg)).items():
|
| 111 |
+
df[k] = v
|
| 112 |
+
return df
|
acliptic/ranker5.py
ADDED
|
@@ -0,0 +1,193 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Acliptic v5: a moment ranker that judges each 30 s segment in context.
|
| 2 |
+
|
| 3 |
+
On top of v4's signals (speech score, loudness, nine sound descriptions) it uses:
|
| 4 |
+
* the full CLAP sound fingerprint of the segment (512 numbers, projected to a few directions learned in training)
|
| 5 |
+
* what is being said, as a sentence-meaning embedding (bge-base), projected the same way, plus stream-talk cues
|
| 6 |
+
("no way", "bro", "chat", laughter words, how fast and how much someone is talking)
|
| 7 |
+
* context: the same signals for the segments around it, and how the segment stands out from the last few minutes
|
| 8 |
+
|
| 9 |
+
Training (model-testing/v5_train.py) imports this module, so training and serving compute identical numbers.
|
| 10 |
+
"""
|
| 11 |
+
import pickle
|
| 12 |
+
import re
|
| 13 |
+
import threading
|
| 14 |
+
from pathlib import Path
|
| 15 |
+
|
| 16 |
+
import numpy as np
|
| 17 |
+
import pandas as pd
|
| 18 |
+
from sklearn.ensemble import HistGradientBoostingRegressor
|
| 19 |
+
|
| 20 |
+
from .ranker import RAW, causal_pct, featurize, rolling_z
|
| 21 |
+
|
| 22 |
+
CUES = {
|
| 23 |
+
"cue_hype": r"\b(no way|what the|oh my god|omg|holy|let'?s go+|bro+|yo+|dude|insane|crazy|wtf|stop|wait)\b",
|
| 24 |
+
"cue_chat": r"\b(chat|clip (it|that)|everybody|y'?all)\b",
|
| 25 |
+
"cue_laugh": r"\b(ha(ha)+|lol|lmao|hah)\b",
|
| 26 |
+
"cue_swear": r"\b(fuck\w*|shit\w*|damn|hell|bitch\w*)\b",
|
| 27 |
+
"cue_question": r"\?",
|
| 28 |
+
"cue_exclaim": r"!",
|
| 29 |
+
}
|
| 30 |
+
CONTEXT = ["db_mean_z", "db_max_z", "snd_laugh_z", "snd_scream_z", "snd_crowd_z", "snd_action_z", "text_v2_z", "n_words_z",
|
| 31 |
+
"cue_hype", "cue_laugh"]
|
| 32 |
+
_lock = threading.Lock()
|
| 33 |
+
_tm: dict = {}
|
| 34 |
+
|
| 35 |
+
|
| 36 |
+
def text_cues(texts) -> pd.DataFrame:
|
| 37 |
+
out = {}
|
| 38 |
+
low = [t.lower() for t in texts]
|
| 39 |
+
for k, rx in CUES.items():
|
| 40 |
+
r = re.compile(rx)
|
| 41 |
+
out[k] = [len(r.findall(t)) for t in low]
|
| 42 |
+
return pd.DataFrame(out)
|
| 43 |
+
|
| 44 |
+
|
| 45 |
+
def text_embeddings(texts, model_dir) -> np.ndarray:
|
| 46 |
+
"""(n, 768) unit-length sentence embeddings (bge-base-en-v1.5, CLS pooling) on ONNX Runtime (no PyTorch)."""
|
| 47 |
+
import onnxruntime as ort
|
| 48 |
+
from tokenizers import Tokenizer
|
| 49 |
+
with _lock:
|
| 50 |
+
if "m" not in _tm:
|
| 51 |
+
d = Path(model_dir)
|
| 52 |
+
tok = Tokenizer.from_file(str(d / "tokenizer.json"))
|
| 53 |
+
tok.enable_truncation(160)
|
| 54 |
+
tok.enable_padding(pad_id=0, pad_token="[PAD]")
|
| 55 |
+
_tm["t"] = tok
|
| 56 |
+
_tm["m"] = ort.InferenceSession(str(d / "onnx" / "model.onnx"), providers=["CPUExecutionProvider"])
|
| 57 |
+
out = []
|
| 58 |
+
for b in range(0, len(texts), 32):
|
| 59 |
+
enc = _tm["t"].encode_batch([t if t.strip() else "(silence)" for t in texts[b:b + 32]])
|
| 60 |
+
ids = np.array([e.ids for e in enc], np.int64)
|
| 61 |
+
mask = np.array([e.attention_mask for e in enc], np.int64)
|
| 62 |
+
h = _tm["m"].run(None, {"input_ids": ids, "attention_mask": mask, "token_type_ids": np.zeros_like(ids)})[0][:, 0]
|
| 63 |
+
out.append(h / np.linalg.norm(h, axis=1, keepdims=True))
|
| 64 |
+
return np.concatenate(out).astype(np.float32) if out else np.zeros((0, 768), np.float32)
|
| 65 |
+
|
| 66 |
+
|
| 67 |
+
def _shift(x, k):
|
| 68 |
+
"""x moved k segments (k > 0: the value k segments earlier), edges filled with the nearest value."""
|
| 69 |
+
if k == 0:
|
| 70 |
+
return x
|
| 71 |
+
if k > 0:
|
| 72 |
+
return np.r_[np.repeat(x[:1], k), x[:-k]]
|
| 73 |
+
return np.r_[x[-k:], np.repeat(x[-1:], -k)]
|
| 74 |
+
|
| 75 |
+
|
| 76 |
+
def featurize5(raw: pd.DataFrame, clap: np.ndarray | None, temb: np.ndarray | None, proj: dict, causal: bool = False) -> pd.DataFrame:
|
| 77 |
+
"""raw: per-segment signals (n_words, db_*, snd_*, transcript). clap/temb: per-segment embeddings.
|
| 78 |
+
proj: {"clap": (512, k) matrix, "text": (768, k) matrix, means} learned in training."""
|
| 79 |
+
base = featurize(raw, causal)
|
| 80 |
+
f = {c: base[c].values for c in base.columns} # columns collected in a dict, framed once at the end
|
| 81 |
+
cues = text_cues(raw.get("transcript", pd.Series([""] * len(raw))).fillna("").astype(str).tolist())
|
| 82 |
+
for c in cues:
|
| 83 |
+
f[c] = cues[c].values
|
| 84 |
+
if "n_words" in raw:
|
| 85 |
+
f["talk_change"] = raw.n_words.values - np.r_[raw.n_words.values[:1], raw.n_words.values[:-1]]
|
| 86 |
+
for name, emb in (("clap", clap), ("text", temb)):
|
| 87 |
+
if emb is None or name not in proj or len(emb) != len(raw):
|
| 88 |
+
continue
|
| 89 |
+
z = (emb.astype(np.float32) - proj[name + "_mean"]) @ proj[name]
|
| 90 |
+
for j in range(z.shape[1]):
|
| 91 |
+
f[f"{name}{j}"] = z[:, j]
|
| 92 |
+
f[f"{name}{j}_z"] = rolling_z(z[:, j], causal=causal)
|
| 93 |
+
# how different this segment sounds / reads from the previous one: novelty
|
| 94 |
+
prev = np.vstack([emb[:1], emb[:-1]]).astype(np.float32)
|
| 95 |
+
f[f"{name}_novelty"] = 1 - (emb.astype(np.float32) * prev).sum(1)
|
| 96 |
+
# context: neighbours (live: past only) and a short running peak
|
| 97 |
+
shifts = [1, 2] if causal else [-2, -1, 1, 2]
|
| 98 |
+
for c in CONTEXT:
|
| 99 |
+
if c not in f:
|
| 100 |
+
continue
|
| 101 |
+
x = np.asarray(f[c], float)
|
| 102 |
+
for k in shifts:
|
| 103 |
+
f[f"{c}_s{k}"] = _shift(x, k)
|
| 104 |
+
win = pd.Series(x).rolling(3 if causal else 5, center=not causal, min_periods=1)
|
| 105 |
+
f[f"{c}_peak"] = win.max().values
|
| 106 |
+
f[f"{c}_avg"] = win.mean().values
|
| 107 |
+
if causal:
|
| 108 |
+
f["clap_novelty_pct"] = causal_pct(f["clap_novelty"]) if "clap_novelty" in f else np.full(len(raw), 0.5)
|
| 109 |
+
return pd.DataFrame(f, index=raw.index)
|
| 110 |
+
|
| 111 |
+
|
| 112 |
+
def fit_projection(embs: list[np.ndarray], k: int, seed: int = 7) -> tuple[np.ndarray, np.ndarray]:
|
| 113 |
+
"""PCA directions (training data only)."""
|
| 114 |
+
X = np.concatenate([e.astype(np.float32) for e in embs])
|
| 115 |
+
mu = X.mean(0)
|
| 116 |
+
rng = np.random.default_rng(seed)
|
| 117 |
+
if len(X) > 30000:
|
| 118 |
+
X = X[rng.choice(len(X), 30000, replace=False)]
|
| 119 |
+
_, _, vt = np.linalg.svd(X - mu, full_matrices=False)
|
| 120 |
+
return vt[:k].T.astype(np.float32), mu.astype(np.float32)
|
| 121 |
+
|
| 122 |
+
|
| 123 |
+
class Reg:
|
| 124 |
+
"""A regressor on the replay level, exposed like a classifier (score = predicted level)."""
|
| 125 |
+
|
| 126 |
+
def __init__(self, **kw):
|
| 127 |
+
self.m = HistGradientBoostingRegressor(**kw, random_state=7)
|
| 128 |
+
|
| 129 |
+
def fit(self, X, y):
|
| 130 |
+
self.m.fit(X, y)
|
| 131 |
+
return self
|
| 132 |
+
|
| 133 |
+
def predict_proba(self, X):
|
| 134 |
+
p = np.clip(self.m.predict(X), 0, 1)
|
| 135 |
+
return np.c_[1 - p, p]
|
| 136 |
+
|
| 137 |
+
|
| 138 |
+
class MLP:
|
| 139 |
+
"""Small neural net on standardised features (scikit-learn; PyTorch is blocked here)."""
|
| 140 |
+
|
| 141 |
+
def __init__(self, seed=7):
|
| 142 |
+
from sklearn.neural_network import MLPClassifier
|
| 143 |
+
self.m = MLPClassifier(hidden_layer_sizes=(64, 32), alpha=1e-2, max_iter=300, early_stopping=True,
|
| 144 |
+
validation_fraction=0.15, random_state=seed)
|
| 145 |
+
|
| 146 |
+
def fit(self, X, y):
|
| 147 |
+
self.cols, self.mu, self.sd = X.columns, X.mean(), X.std().replace(0, 1)
|
| 148 |
+
Z = ((X - self.mu) / self.sd).fillna(0).clip(-6, 6)
|
| 149 |
+
# balance classes by resampling positives (MLPClassifier has no class weights)
|
| 150 |
+
pos = np.flatnonzero(y == 1)
|
| 151 |
+
extra = np.random.default_rng(7).choice(pos, max(0, (y == 0).sum() - len(pos)), replace=True) if len(pos) else []
|
| 152 |
+
idx = np.r_[np.arange(len(y)), extra].astype(int)
|
| 153 |
+
self.m.fit(Z.values[idx], y[idx])
|
| 154 |
+
return self
|
| 155 |
+
|
| 156 |
+
def predict_proba(self, X):
|
| 157 |
+
return self.m.predict_proba(((X[self.cols] - self.mu) / self.sd).fillna(0).clip(-6, 6).values)
|
| 158 |
+
|
| 159 |
+
|
| 160 |
+
class Ens:
|
| 161 |
+
def __init__(self, makers):
|
| 162 |
+
self.ms = [m() for m in makers]
|
| 163 |
+
|
| 164 |
+
def fit(self, X, y):
|
| 165 |
+
yb = (y >= 0.8).astype(int) if np.unique(y).size > 2 else y # classifiers see "top 20%"; regressors the level
|
| 166 |
+
for m in self.ms:
|
| 167 |
+
m.fit(X, y if isinstance(m, Reg) else yb)
|
| 168 |
+
return self
|
| 169 |
+
|
| 170 |
+
def predict_proba(self, X):
|
| 171 |
+
p = np.mean([pd.Series(m.predict_proba(X)[:, 1]).rank(pct=True).values for m in self.ms], 0)
|
| 172 |
+
return np.c_[1 - p, p]
|
| 173 |
+
|
| 174 |
+
|
| 175 |
+
class Ranker5:
|
| 176 |
+
"""Loads ranker5.pkl (written by v5_train.py)."""
|
| 177 |
+
|
| 178 |
+
def __init__(self, path: str | Path):
|
| 179 |
+
with open(Path(path) / "ranker5.pkl", "rb") as fh:
|
| 180 |
+
b = pickle.load(fh)
|
| 181 |
+
self.b = b
|
| 182 |
+
self._lock = threading.Lock()
|
| 183 |
+
|
| 184 |
+
def score(self, raw: pd.DataFrame, clap, temb, causal: bool = False) -> np.ndarray:
|
| 185 |
+
key = "live" if causal and "live" in self.b else "batch"
|
| 186 |
+
m = self.b[key]
|
| 187 |
+
X = featurize5(raw, clap, temb, self.b["proj"], causal).reindex(columns=m["columns"])
|
| 188 |
+
with self._lock:
|
| 189 |
+
return np.mean([mod.predict_proba(X)[:, 1] if hasattr(mod, "predict_proba") else mod.predict(X)
|
| 190 |
+
for mod in m["models"]], axis=0)
|
| 191 |
+
|
| 192 |
+
|
| 193 |
+
__all__ = ["RAW", "featurize5", "fit_projection", "text_cues", "text_embeddings", "Ranker5", "Reg", "MLP", "Ens"]
|
acliptic/shortlist.py
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Turns per-segment model scores into a short ranked list of highlights.
|
| 2 |
+
|
| 3 |
+
Ranking is the method that tested best on 5 long live streams in Nov 2026 (it caught 19 of the 25 biggest
|
| 4 |
+
Most Replayed peaks, against 14 for the model's text score alone):
|
| 5 |
+
rank score = average of (model-score percentile, audio-loudness percentile)
|
| 6 |
+
where loudness = how much louder the segment is than the surrounding 10 minutes.
|
| 7 |
+
Only segments the model scores above its `min_score` are eligible; sponsor reads, stream housekeeping (and the
|
| 8 |
+
segment after each) and near-empty segments are skipped. Picks are at least 2 minutes apart (closer on short
|
| 9 |
+
videos), about 6 per hour of video, between 3 and 12.
|
| 10 |
+
"""
|
| 11 |
+
import numpy as np
|
| 12 |
+
|
| 13 |
+
from .content_filters import is_ad, is_filler, safety_flags
|
| 14 |
+
|
| 15 |
+
SEG = 30.0
|
| 16 |
+
|
| 17 |
+
|
| 18 |
+
def _robust_z(x, w=20):
|
| 19 |
+
x = np.asarray(x, float)
|
| 20 |
+
out = np.zeros(len(x))
|
| 21 |
+
for i in range(len(x)):
|
| 22 |
+
win = x[max(0, i - w):i + w + 1]
|
| 23 |
+
med = np.median(win)
|
| 24 |
+
out[i] = (x[i] - med) / (1.4826 * np.median(np.abs(win - med)) + 1e-6)
|
| 25 |
+
return out
|
| 26 |
+
|
| 27 |
+
|
| 28 |
+
def _pct(x):
|
| 29 |
+
x = np.asarray(x, float)
|
| 30 |
+
return (np.argsort(np.argsort(x)) + 0.5) / max(1, len(x))
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def build(texts, model_scores, loud_mean, loud_max, has_audio, duration, min_score, direct=False):
|
| 34 |
+
"""direct=True: the model's scores already rank moments (v4: speech + loudness + sound), so they're used as is,
|
| 35 |
+
and a segment needs only 3 words (a scream or a laugh can be the moment)."""
|
| 36 |
+
n = len(texts)
|
| 37 |
+
scores = np.asarray(model_scores, float)
|
| 38 |
+
skipped = []
|
| 39 |
+
blocked = np.zeros(n, bool)
|
| 40 |
+
for i, t in enumerate(texts):
|
| 41 |
+
reason = "ad" if is_ad(t) else "housekeeping" if is_filler(t) else None
|
| 42 |
+
if reason:
|
| 43 |
+
blocked[i] = True
|
| 44 |
+
if i + 1 < n:
|
| 45 |
+
blocked[i + 1] = True # ad reads spill into the next segment
|
| 46 |
+
skipped.append(reason)
|
| 47 |
+
for i in range(n):
|
| 48 |
+
if blocked[i] and not skipped[i]:
|
| 49 |
+
skipped[i] = "after-ad"
|
| 50 |
+
if not skipped[i] and len(t_words(texts[i])) < (3 if direct else 8):
|
| 51 |
+
skipped[i] = "too-little-speech"
|
| 52 |
+
if has_audio and n > 1:
|
| 53 |
+
audio_z = _robust_z(loud_mean) + 0.5 * _robust_z(loud_max)
|
| 54 |
+
rank = _pct(scores) if direct else (_pct(scores) + _pct(audio_z)) / 2
|
| 55 |
+
else:
|
| 56 |
+
audio_z = np.zeros(n)
|
| 57 |
+
rank = _pct(scores)
|
| 58 |
+
eligible = np.array([not skipped[i] and scores[i] > min_score for i in range(n)])
|
| 59 |
+
k = int(np.clip(round(6 * duration / 3600), 3, 12))
|
| 60 |
+
gap = 4 if duration > 1200 else 2 # never two neighbouring segments: their padded clips would overlap
|
| 61 |
+
picks = []
|
| 62 |
+
for i in np.argsort(-rank):
|
| 63 |
+
if eligible[i] and all(abs(i - j) >= gap for j in picks):
|
| 64 |
+
picks.append(int(i))
|
| 65 |
+
if len(picks) == k:
|
| 66 |
+
break
|
| 67 |
+
highlights = []
|
| 68 |
+
for r, i in enumerate(picks, start=1):
|
| 69 |
+
start, end = max(0.0, i * SEG - 2), min(duration, (i + 1) * SEG + 2)
|
| 70 |
+
# carry on into the next segment when the moment clearly continues
|
| 71 |
+
if i + 1 < n and eligible[i + 1] and scores[i + 1] > max(0.9, min_score) and i + 1 not in picks and i + 2 not in picks:
|
| 72 |
+
end = min(duration, (i + 2) * SEG + 2)
|
| 73 |
+
text = " ".join(texts[i:i + (2 if end - start > SEG + 10 else 1)])
|
| 74 |
+
highlights.append(dict(rank=r, start=round(start, 2), end=round(end, 2), model_score=float(scores[i]),
|
| 75 |
+
rank_score=float(rank[i]), audio_z=float(audio_z[i]), text=text,
|
| 76 |
+
flags=safety_flags(text)))
|
| 77 |
+
return highlights, rank, audio_z, skipped
|
| 78 |
+
|
| 79 |
+
|
| 80 |
+
def t_words(t):
|
| 81 |
+
return [w for w in t.split() if any(c.isalnum() for c in w)]
|
acliptic/sound.py
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""What a moment sounds like: laughter, screaming, a crowd cheering, gunfire, music, silence...
|
| 2 |
+
|
| 3 |
+
CLAP (LAION clap-htsat-unfused) embeds the loudest 10 s of every 30 s segment; each embedding is compared with a few
|
| 4 |
+
text descriptions per sound. Runs on ONNX Runtime (no PyTorch: this PC's Application Control policy blocks PyTorch's
|
| 5 |
+
unsigned DLLs), with the exact preprocessing of transformers' ClapFeatureExtractor reproduced in numpy (10 s windows
|
| 6 |
+
at 48 kHz: Slaney mel filters, power dB). ~110x real time on a 16-thread CPU. Used by the v4/v5 rankers and,
|
| 7 |
+
identically, by their training scripts."""
|
| 8 |
+
import json
|
| 9 |
+
import threading
|
| 10 |
+
from pathlib import Path
|
| 11 |
+
|
| 12 |
+
import numpy as np
|
| 13 |
+
|
| 14 |
+
from . import config
|
| 15 |
+
|
| 16 |
+
SEG = 30
|
| 17 |
+
WIN = 10
|
| 18 |
+
SR_IN = 16000
|
| 19 |
+
SR_CLAP = 48000
|
| 20 |
+
SOUNDS = {
|
| 21 |
+
"laugh": ["people laughing", "loud laughter", "someone cracking up laughing"],
|
| 22 |
+
"scream": ["a person screaming", "someone yelling loudly", "an excited shout"],
|
| 23 |
+
"crowd": ["a crowd cheering", "applause and cheering", "a group of people shouting"],
|
| 24 |
+
"gasp": ["a shocked gasp", "someone crying", "a groan of disbelief"],
|
| 25 |
+
"music": ["music playing", "someone singing", "a song with beats"],
|
| 26 |
+
"action": ["gunshots and explosions", "a loud crash", "a car crash"],
|
| 27 |
+
"speech": ["a person talking calmly", "a calm conversation", "someone reading quietly"],
|
| 28 |
+
"silence": ["silence", "quiet background noise", "nothing happening"],
|
| 29 |
+
"game": ["video game sound effects", "electronic beeps", "game menu music"],
|
| 30 |
+
}
|
| 31 |
+
_lock = threading.Lock()
|
| 32 |
+
_m: dict = {}
|
| 33 |
+
|
| 34 |
+
|
| 35 |
+
def _sessions():
|
| 36 |
+
if "audio" not in _m:
|
| 37 |
+
import onnxruntime as ort
|
| 38 |
+
from tokenizers import Tokenizer
|
| 39 |
+
from transformers.audio_utils import mel_filter_bank, spectrogram, window_function # numpy only
|
| 40 |
+
d = Path(config.CLAP_ONNX)
|
| 41 |
+
opt = ort.SessionOptions()
|
| 42 |
+
opt.intra_op_num_threads = config.ASR_THREADS
|
| 43 |
+
_m["audio"] = ort.InferenceSession(str(d / "onnx" / "audio_model.onnx"), opt, providers=["CPUExecutionProvider"])
|
| 44 |
+
text = ort.InferenceSession(str(d / "onnx" / "text_model.onnx"), opt, providers=["CPUExecutionProvider"])
|
| 45 |
+
pp = json.loads((d / "preprocessor_config.json").read_text())
|
| 46 |
+
_m["mel"] = mel_filter_bank(num_frequency_bins=pp["nb_frequency_bins"], num_mel_filters=pp["feature_size"],
|
| 47 |
+
min_frequency=pp["frequency_min"], max_frequency=pp["frequency_max"],
|
| 48 |
+
sampling_rate=pp["sampling_rate"], norm="slaney", mel_scale="slaney")
|
| 49 |
+
_m["spec"] = lambda w: spectrogram(w, window_function(pp["fft_window_size"], "hann"), frame_length=pp["fft_window_size"],
|
| 50 |
+
hop_length=pp["hop_length"], power=2.0, mel_filters=_m["mel"], log_mel="dB").T
|
| 51 |
+
tok = Tokenizer.from_file(str(d / "tokenizer.json"))
|
| 52 |
+
_m["text"] = {}
|
| 53 |
+
for name, prompts in SOUNDS.items():
|
| 54 |
+
vecs = []
|
| 55 |
+
for t in prompts: # one at a time: the exported text model takes no attention mask, so no padding
|
| 56 |
+
ids = np.array([tok.encode(t).ids], np.int64)
|
| 57 |
+
v = text.run(None, {"input_ids": ids})[0][0]
|
| 58 |
+
vecs.append(v / np.linalg.norm(v))
|
| 59 |
+
_m["text"][name] = np.mean(vecs, 0)
|
| 60 |
+
return _m
|
| 61 |
+
|
| 62 |
+
|
| 63 |
+
def _loudest_windows(audio: np.ndarray, n_seg: int) -> list:
|
| 64 |
+
secs = len(audio) // SR_IN
|
| 65 |
+
rms = np.sqrt((audio[:secs * SR_IN].reshape(secs, SR_IN) ** 2).mean(1) + 1e-12) if secs else np.zeros(1)
|
| 66 |
+
out = []
|
| 67 |
+
for i in range(n_seg):
|
| 68 |
+
a, b = i * SEG, min(secs, (i + 1) * SEG)
|
| 69 |
+
if b - a <= WIN:
|
| 70 |
+
s = a
|
| 71 |
+
else:
|
| 72 |
+
c = np.convolve(rms[a:b], np.ones(WIN), "valid")
|
| 73 |
+
s = a + int(np.argmax(c))
|
| 74 |
+
w = audio[s * SR_IN:(s + WIN) * SR_IN]
|
| 75 |
+
out.append(np.pad(w, (0, WIN * SR_IN - len(w))))
|
| 76 |
+
return out
|
| 77 |
+
|
| 78 |
+
|
| 79 |
+
def embeddings(audio16k: np.ndarray, n_seg: int, batch: int = 16) -> np.ndarray:
|
| 80 |
+
"""(n_seg, 512) unit-length CLAP embeddings, one per 30 s segment (its loudest 10 s)."""
|
| 81 |
+
with _lock:
|
| 82 |
+
m = _sessions()
|
| 83 |
+
wins = _loudest_windows(audio16k, n_seg)
|
| 84 |
+
x48 = np.linspace(0, WIN * SR_IN - 1, WIN * SR_CLAP)
|
| 85 |
+
out = []
|
| 86 |
+
for b in range(0, len(wins), batch):
|
| 87 |
+
mels = [m["spec"](np.interp(x48, np.arange(WIN * SR_IN), w).astype(np.float32))[None] for w in wins[b:b + batch]]
|
| 88 |
+
e = m["audio"].run(None, {"input_features": np.stack(mels).astype(np.float32)})[0]
|
| 89 |
+
out.append(e / np.linalg.norm(e, axis=1, keepdims=True))
|
| 90 |
+
return np.concatenate(out).astype(np.float32) if out else np.zeros((0, 512), np.float32)
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
def scores(emb: np.ndarray) -> dict:
|
| 94 |
+
"""Cosine similarity of each segment with each sound's descriptions: {"snd_laugh": array, ...}."""
|
| 95 |
+
m = _sessions()
|
| 96 |
+
return {f"snd_{k}": emb @ v for k, v in m["text"].items()}
|
acliptic/transcribe.py
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""Speech-to-text when the platform has no captions.
|
| 2 |
+
|
| 3 |
+
faster-whisper (CTranslate2, int8) with real per-word timestamps, so burned-in captions land on the word as it's said.
|
| 4 |
+
The audio is cut at quiet moments into pieces that are transcribed in parallel (ASR_WORKERS x ASR_THREADS); on a
|
| 5 |
+
16-thread CPU 4 x 4 is ~30% faster than the old single-pass transformers Whisper. If faster-whisper can't load, the
|
| 6 |
+
old path (transformers, word times spread evenly through each 30 s chunk) is used instead.
|
| 7 |
+
|
| 8 |
+
`accurate_words` re-transcribes a short range with the bigger caption model, for clips (see captions_hq)."""
|
| 9 |
+
import threading
|
| 10 |
+
from concurrent.futures import ThreadPoolExecutor
|
| 11 |
+
from pathlib import Path
|
| 12 |
+
|
| 13 |
+
import numpy as np
|
| 14 |
+
|
| 15 |
+
from . import config
|
| 16 |
+
from .media import audio_pcm
|
| 17 |
+
|
| 18 |
+
SR = 16000
|
| 19 |
+
PIECE_S = 240 # target piece length; cut points snap to the quietest second nearby
|
| 20 |
+
_lock = threading.Lock()
|
| 21 |
+
_models: dict = {}
|
| 22 |
+
|
| 23 |
+
|
| 24 |
+
def _fw(path: str, workers: int):
|
| 25 |
+
key = (path, workers)
|
| 26 |
+
if key not in _models:
|
| 27 |
+
from faster_whisper import WhisperModel
|
| 28 |
+
_models[key] = WhisperModel(path, device="cpu", compute_type="int8", cpu_threads=max(1, config.ASR_THREADS // workers),
|
| 29 |
+
num_workers=workers)
|
| 30 |
+
return _models[key]
|
| 31 |
+
|
| 32 |
+
|
| 33 |
+
def _cuts(audio: np.ndarray, n: int) -> list[int]:
|
| 34 |
+
"""n pieces of about equal length, each boundary moved to the quietest second within 20 s, so words aren't split."""
|
| 35 |
+
if n <= 1:
|
| 36 |
+
return [0, len(audio)]
|
| 37 |
+
secs = len(audio) // SR
|
| 38 |
+
rms = np.sqrt((audio[:secs * SR].reshape(secs, SR) ** 2).mean(1) + 1e-12)
|
| 39 |
+
out = [0]
|
| 40 |
+
for k in range(1, n):
|
| 41 |
+
c = int(secs * k / n)
|
| 42 |
+
lo, hi = max(out[-1] // SR + 5, c - 20), min(secs - 5, c + 20)
|
| 43 |
+
out.append((lo + int(np.argmin(rms[lo:hi]))) * SR if hi > lo else c * SR)
|
| 44 |
+
return out + [len(audio)]
|
| 45 |
+
|
| 46 |
+
|
| 47 |
+
def _transcribe(model, audio: np.ndarray, offset: float, beam: int = 1) -> list:
|
| 48 |
+
segs, _ = model.transcribe(audio, language="en", beam_size=beam, word_timestamps=True, vad_filter=True,
|
| 49 |
+
condition_on_previous_text=False)
|
| 50 |
+
return [[round(float(offset) + float(w.start), 2), w.word.strip()] for s in segs for w in (s.words or []) if w.word.strip()]
|
| 51 |
+
|
| 52 |
+
|
| 53 |
+
def whisper_words(path: Path, duration: float, say=None) -> list:
|
| 54 |
+
with _lock: # one long transcription at a time; it already uses every core
|
| 55 |
+
audio = audio_pcm(path, SR, duration)
|
| 56 |
+
try:
|
| 57 |
+
model = _fw(str(config.ASR_MODEL), config.ASR_WORKERS)
|
| 58 |
+
except Exception:
|
| 59 |
+
return _legacy(audio, say)
|
| 60 |
+
secs = len(audio) / SR # enough pieces to keep every worker busy, none shorter than a minute
|
| 61 |
+
n = max(1, min(int(secs // 60), max(2 * config.ASR_WORKERS, round(secs / PIECE_S))))
|
| 62 |
+
b = _cuts(audio, n)
|
| 63 |
+
pieces = [(float(b[i]) / SR, audio[b[i]:b[i + 1]]) for i in range(n)]
|
| 64 |
+
words, done = [], 0
|
| 65 |
+
with ThreadPoolExecutor(config.ASR_WORKERS) as ex:
|
| 66 |
+
for part in ex.map(lambda p: _transcribe(model, p[1], p[0]), pieces):
|
| 67 |
+
words += part
|
| 68 |
+
done += 1
|
| 69 |
+
if say:
|
| 70 |
+
say(done / n)
|
| 71 |
+
return sorted(words, key=lambda w: w[0])
|
| 72 |
+
|
| 73 |
+
|
| 74 |
+
def accurate_words(path: Path, start: float, end: float) -> list:
|
| 75 |
+
"""Short range (a clip plus a little margin) with the caption model: beam search, bigger model."""
|
| 76 |
+
audio = audio_pcm_range(path, start, end)
|
| 77 |
+
model = _fw(str(config.CAPTION_MODEL), 1)
|
| 78 |
+
return _transcribe(model, audio, start, beam=5)
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def audio_pcm_range(path: Path, start: float, end: float) -> np.ndarray:
|
| 82 |
+
import subprocess
|
| 83 |
+
from .media import FFMPEG
|
| 84 |
+
raw = subprocess.run([FFMPEG, "-v", "error", "-ss", f"{start:.3f}", "-t", f"{max(0.5, end - start):.3f}", "-i", str(path),
|
| 85 |
+
"-ac", "1", "-ar", str(SR), "-f", "s16le", "-"], capture_output=True).stdout
|
| 86 |
+
return np.frombuffer(raw, np.int16).astype(np.float32) / 32768
|
| 87 |
+
|
| 88 |
+
|
| 89 |
+
def _legacy(audio: np.ndarray, say=None) -> list:
|
| 90 |
+
"""transformers Whisper on 30 s chunks; word times spread evenly inside each chunk."""
|
| 91 |
+
import torch
|
| 92 |
+
from transformers import WhisperForConditionalGeneration, WhisperProcessor
|
| 93 |
+
if "legacy" not in _models:
|
| 94 |
+
_models["legacy"] = (WhisperProcessor.from_pretrained(config.WHISPER_MODEL),
|
| 95 |
+
WhisperForConditionalGeneration.from_pretrained(config.WHISPER_MODEL).eval())
|
| 96 |
+
proc, m = _models["legacy"]
|
| 97 |
+
chunks = [audio[i:i + 30 * SR] for i in range(0, len(audio), 30 * SR)]
|
| 98 |
+
words = []
|
| 99 |
+
for b in range(0, len(chunks), 8):
|
| 100 |
+
batch = chunks[b:b + 8]
|
| 101 |
+
with torch.no_grad():
|
| 102 |
+
ids = m.generate(proc(batch, sampling_rate=SR, return_tensors="pt").input_features, max_new_tokens=220)
|
| 103 |
+
for j, txt in enumerate(proc.batch_decode(ids, skip_special_tokens=True)):
|
| 104 |
+
ws = txt.split()
|
| 105 |
+
t0, span = (b + j) * 30, min(30, len(batch[j]) / SR)
|
| 106 |
+
words += [[round(t0 + span * k / max(1, len(ws)), 2), w] for k, w in enumerate(ws)]
|
| 107 |
+
if say:
|
| 108 |
+
say(min(1.0, (b + len(batch)) / len(chunks)))
|
| 109 |
+
return words
|
bge-onnx/config.json
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_name_or_path": "BAAI/bge-base-en-v1.5",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"BertModel"
|
| 5 |
+
],
|
| 6 |
+
"attention_probs_dropout_prob": 0.1,
|
| 7 |
+
"classifier_dropout": null,
|
| 8 |
+
"gradient_checkpointing": false,
|
| 9 |
+
"hidden_act": "gelu",
|
| 10 |
+
"hidden_dropout_prob": 0.1,
|
| 11 |
+
"hidden_size": 768,
|
| 12 |
+
"id2label": {
|
| 13 |
+
"0": "LABEL_0"
|
| 14 |
+
},
|
| 15 |
+
"initializer_range": 0.02,
|
| 16 |
+
"intermediate_size": 3072,
|
| 17 |
+
"label2id": {
|
| 18 |
+
"LABEL_0": 0
|
| 19 |
+
},
|
| 20 |
+
"layer_norm_eps": 1e-12,
|
| 21 |
+
"max_position_embeddings": 512,
|
| 22 |
+
"model_type": "bert",
|
| 23 |
+
"num_attention_heads": 12,
|
| 24 |
+
"num_hidden_layers": 12,
|
| 25 |
+
"pad_token_id": 0,
|
| 26 |
+
"position_embedding_type": "absolute",
|
| 27 |
+
"transformers_version": "4.34.0.dev0",
|
| 28 |
+
"type_vocab_size": 2,
|
| 29 |
+
"use_cache": true,
|
| 30 |
+
"vocab_size": 30522
|
| 31 |
+
}
|
bge-onnx/onnx/model.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:9bc579acdba21c253c62a9bf866891355a63ffa3442b52c8a37d75b2ccb91848
|
| 3 |
+
size 435811539
|
bge-onnx/quantize_config.json
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"per_channel": true,
|
| 3 |
+
"reduce_range": true,
|
| 4 |
+
"per_model_config": {
|
| 5 |
+
"model": {
|
| 6 |
+
"op_types": [
|
| 7 |
+
"Cast",
|
| 8 |
+
"Softmax",
|
| 9 |
+
"Sub",
|
| 10 |
+
"Shape",
|
| 11 |
+
"Constant",
|
| 12 |
+
"Transpose",
|
| 13 |
+
"Concat",
|
| 14 |
+
"ReduceMean",
|
| 15 |
+
"Gather",
|
| 16 |
+
"Pow",
|
| 17 |
+
"Mul",
|
| 18 |
+
"Sqrt",
|
| 19 |
+
"Reshape",
|
| 20 |
+
"Slice",
|
| 21 |
+
"Erf",
|
| 22 |
+
"MatMul",
|
| 23 |
+
"Div",
|
| 24 |
+
"Unsqueeze",
|
| 25 |
+
"Add"
|
| 26 |
+
],
|
| 27 |
+
"weight_type": "QInt8"
|
| 28 |
+
}
|
| 29 |
+
}
|
| 30 |
+
}
|
bge-onnx/special_tokens_map.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"cls_token": "[CLS]",
|
| 3 |
+
"mask_token": "[MASK]",
|
| 4 |
+
"pad_token": "[PAD]",
|
| 5 |
+
"sep_token": "[SEP]",
|
| 6 |
+
"unk_token": "[UNK]"
|
| 7 |
+
}
|
bge-onnx/tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
bge-onnx/tokenizer_config.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"clean_up_tokenization_spaces": true,
|
| 3 |
+
"cls_token": "[CLS]",
|
| 4 |
+
"do_basic_tokenize": true,
|
| 5 |
+
"do_lower_case": true,
|
| 6 |
+
"mask_token": "[MASK]",
|
| 7 |
+
"model_max_length": 512,
|
| 8 |
+
"never_split": null,
|
| 9 |
+
"pad_token": "[PAD]",
|
| 10 |
+
"sep_token": "[SEP]",
|
| 11 |
+
"strip_accents": null,
|
| 12 |
+
"tokenize_chinese_chars": true,
|
| 13 |
+
"tokenizer_class": "BertTokenizer",
|
| 14 |
+
"unk_token": "[UNK]"
|
| 15 |
+
}
|
clap-onnx/config.json
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"_name_or_path": "laion/clap-htsat-unfused",
|
| 3 |
+
"architectures": [
|
| 4 |
+
"ClapModel"
|
| 5 |
+
],
|
| 6 |
+
"audio_config": {
|
| 7 |
+
"fusion_num_hidden_layers": 2,
|
| 8 |
+
"model_type": "clap_audio_model",
|
| 9 |
+
"projection_hidden_size": 768
|
| 10 |
+
},
|
| 11 |
+
"hidden_size": 768,
|
| 12 |
+
"initializer_factor": 1.0,
|
| 13 |
+
"logit_scale_init_value": 14.285714285714285,
|
| 14 |
+
"model_type": "clap",
|
| 15 |
+
"num_hidden_layers": 16,
|
| 16 |
+
"projection_dim": 512,
|
| 17 |
+
"projection_hidden_act": "relu",
|
| 18 |
+
"text_config": {
|
| 19 |
+
"classifier_dropout": null,
|
| 20 |
+
"fusion_hidden_size": 768,
|
| 21 |
+
"fusion_num_hidden_layers": 2,
|
| 22 |
+
"initializer_range": 0.02,
|
| 23 |
+
"model_type": "clap_text_model",
|
| 24 |
+
"projection_hidden_size": 768
|
| 25 |
+
},
|
| 26 |
+
"transformers_version": "4.36.0.dev0"
|
| 27 |
+
}
|
clap-onnx/onnx/audio_model.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:a1c2b43c44f71e0fa841a4b86700886c199bf87699ea45632c4d831bc6c88957
|
| 3 |
+
size 117528416
|
clap-onnx/onnx/text_model.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:6df7c51f2d78e236a03f2b816e613d538c815639d13644fe7c2124f439da9648
|
| 3 |
+
size 501513769
|
clap-onnx/preprocessor_config.json
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"chunk_length_s": 10,
|
| 3 |
+
"feature_extractor_type": "ClapFeatureExtractor",
|
| 4 |
+
"feature_size": 64,
|
| 5 |
+
"fft_window_size": 1024,
|
| 6 |
+
"frequency_max": 14000,
|
| 7 |
+
"frequency_min": 50,
|
| 8 |
+
"hop_length": 480,
|
| 9 |
+
"max_length_s": 10,
|
| 10 |
+
"n_fft": 1024,
|
| 11 |
+
"nb_frequency_bins": 513,
|
| 12 |
+
"nb_max_frames": 1000,
|
| 13 |
+
"nb_max_samples": 480000,
|
| 14 |
+
"padding": "repeatpad",
|
| 15 |
+
"padding_side": "right",
|
| 16 |
+
"padding_value": 0.0,
|
| 17 |
+
"processor_class": "ClapProcessor",
|
| 18 |
+
"return_attention_mask": false,
|
| 19 |
+
"sampling_rate": 48000,
|
| 20 |
+
"top_db": null,
|
| 21 |
+
"truncation": "rand_trunc"
|
| 22 |
+
}
|
clap-onnx/quantize_config.json
ADDED
|
@@ -0,0 +1,122 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"per_channel": true,
|
| 3 |
+
"reduce_range": true,
|
| 4 |
+
"per_model_config": {
|
| 5 |
+
"model": {
|
| 6 |
+
"op_types": [
|
| 7 |
+
"Expand",
|
| 8 |
+
"ScatterND",
|
| 9 |
+
"Pad",
|
| 10 |
+
"Abs",
|
| 11 |
+
"Unsqueeze",
|
| 12 |
+
"ReduceSum",
|
| 13 |
+
"Not",
|
| 14 |
+
"CumSum",
|
| 15 |
+
"Constant",
|
| 16 |
+
"Exp",
|
| 17 |
+
"Sub",
|
| 18 |
+
"MatMul",
|
| 19 |
+
"Cast",
|
| 20 |
+
"Reshape",
|
| 21 |
+
"Flatten",
|
| 22 |
+
"Resize",
|
| 23 |
+
"Conv",
|
| 24 |
+
"ConstantOfShape",
|
| 25 |
+
"Gather",
|
| 26 |
+
"Relu",
|
| 27 |
+
"Div",
|
| 28 |
+
"Mul",
|
| 29 |
+
"GlobalAveragePool",
|
| 30 |
+
"Range",
|
| 31 |
+
"Erf",
|
| 32 |
+
"Where",
|
| 33 |
+
"ReduceMean",
|
| 34 |
+
"Pow",
|
| 35 |
+
"Shape",
|
| 36 |
+
"Concat",
|
| 37 |
+
"Slice",
|
| 38 |
+
"Softmax",
|
| 39 |
+
"Tanh",
|
| 40 |
+
"Sqrt",
|
| 41 |
+
"BatchNormalization",
|
| 42 |
+
"Add",
|
| 43 |
+
"Transpose",
|
| 44 |
+
"Gemm",
|
| 45 |
+
"Equal"
|
| 46 |
+
],
|
| 47 |
+
"weight_type": "QUInt8"
|
| 48 |
+
},
|
| 49 |
+
"text_model": {
|
| 50 |
+
"op_types": [
|
| 51 |
+
"ReduceMean",
|
| 52 |
+
"Reshape",
|
| 53 |
+
"Softmax",
|
| 54 |
+
"Pow",
|
| 55 |
+
"Erf",
|
| 56 |
+
"Tanh",
|
| 57 |
+
"Concat",
|
| 58 |
+
"Sub",
|
| 59 |
+
"Not",
|
| 60 |
+
"Expand",
|
| 61 |
+
"Mul",
|
| 62 |
+
"Transpose",
|
| 63 |
+
"Div",
|
| 64 |
+
"Constant",
|
| 65 |
+
"Equal",
|
| 66 |
+
"Unsqueeze",
|
| 67 |
+
"Slice",
|
| 68 |
+
"MatMul",
|
| 69 |
+
"Gather",
|
| 70 |
+
"ConstantOfShape",
|
| 71 |
+
"Shape",
|
| 72 |
+
"Cast",
|
| 73 |
+
"Where",
|
| 74 |
+
"Sqrt",
|
| 75 |
+
"Add",
|
| 76 |
+
"Gemm",
|
| 77 |
+
"CumSum",
|
| 78 |
+
"Relu"
|
| 79 |
+
],
|
| 80 |
+
"weight_type": "QInt8"
|
| 81 |
+
},
|
| 82 |
+
"audio_model": {
|
| 83 |
+
"op_types": [
|
| 84 |
+
"BatchNormalization",
|
| 85 |
+
"ScatterND",
|
| 86 |
+
"ReduceMean",
|
| 87 |
+
"Reshape",
|
| 88 |
+
"Softmax",
|
| 89 |
+
"Pow",
|
| 90 |
+
"Erf",
|
| 91 |
+
"GlobalAveragePool",
|
| 92 |
+
"Concat",
|
| 93 |
+
"Sub",
|
| 94 |
+
"Not",
|
| 95 |
+
"Expand",
|
| 96 |
+
"Mul",
|
| 97 |
+
"Transpose",
|
| 98 |
+
"Div",
|
| 99 |
+
"Constant",
|
| 100 |
+
"Equal",
|
| 101 |
+
"Unsqueeze",
|
| 102 |
+
"Pad",
|
| 103 |
+
"Slice",
|
| 104 |
+
"Resize",
|
| 105 |
+
"Range",
|
| 106 |
+
"MatMul",
|
| 107 |
+
"Gather",
|
| 108 |
+
"ConstantOfShape",
|
| 109 |
+
"Shape",
|
| 110 |
+
"Cast",
|
| 111 |
+
"Sqrt",
|
| 112 |
+
"Where",
|
| 113 |
+
"Add",
|
| 114 |
+
"Conv",
|
| 115 |
+
"Flatten",
|
| 116 |
+
"Gemm",
|
| 117 |
+
"Relu"
|
| 118 |
+
],
|
| 119 |
+
"weight_type": "QUInt8"
|
| 120 |
+
}
|
| 121 |
+
}
|
| 122 |
+
}
|
clap-onnx/special_tokens_map.json
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"bos_token": "<s>",
|
| 3 |
+
"cls_token": "<s>",
|
| 4 |
+
"eos_token": "</s>",
|
| 5 |
+
"mask_token": {
|
| 6 |
+
"content": "<mask>",
|
| 7 |
+
"lstrip": true,
|
| 8 |
+
"normalized": false,
|
| 9 |
+
"rstrip": false,
|
| 10 |
+
"single_word": false
|
| 11 |
+
},
|
| 12 |
+
"pad_token": "<pad>",
|
| 13 |
+
"sep_token": "</s>",
|
| 14 |
+
"unk_token": "<unk>"
|
| 15 |
+
}
|
clap-onnx/tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
clap-onnx/tokenizer_config.json
ADDED
|
@@ -0,0 +1,63 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"add_prefix_space": false,
|
| 3 |
+
"added_tokens_decoder": {
|
| 4 |
+
"0": {
|
| 5 |
+
"content": "<s>",
|
| 6 |
+
"lstrip": false,
|
| 7 |
+
"normalized": false,
|
| 8 |
+
"rstrip": false,
|
| 9 |
+
"single_word": false,
|
| 10 |
+
"special": true
|
| 11 |
+
},
|
| 12 |
+
"1": {
|
| 13 |
+
"content": "<pad>",
|
| 14 |
+
"lstrip": false,
|
| 15 |
+
"normalized": false,
|
| 16 |
+
"rstrip": false,
|
| 17 |
+
"single_word": false,
|
| 18 |
+
"special": true
|
| 19 |
+
},
|
| 20 |
+
"2": {
|
| 21 |
+
"content": "</s>",
|
| 22 |
+
"lstrip": false,
|
| 23 |
+
"normalized": false,
|
| 24 |
+
"rstrip": false,
|
| 25 |
+
"single_word": false,
|
| 26 |
+
"special": true
|
| 27 |
+
},
|
| 28 |
+
"3": {
|
| 29 |
+
"content": "<unk>",
|
| 30 |
+
"lstrip": false,
|
| 31 |
+
"normalized": false,
|
| 32 |
+
"rstrip": false,
|
| 33 |
+
"single_word": false,
|
| 34 |
+
"special": true
|
| 35 |
+
},
|
| 36 |
+
"50264": {
|
| 37 |
+
"content": "<mask>",
|
| 38 |
+
"lstrip": true,
|
| 39 |
+
"normalized": false,
|
| 40 |
+
"rstrip": false,
|
| 41 |
+
"single_word": false,
|
| 42 |
+
"special": true
|
| 43 |
+
}
|
| 44 |
+
},
|
| 45 |
+
"bos_token": "<s>",
|
| 46 |
+
"clean_up_tokenization_spaces": true,
|
| 47 |
+
"cls_token": "<s>",
|
| 48 |
+
"eos_token": "</s>",
|
| 49 |
+
"errors": "replace",
|
| 50 |
+
"mask_token": "<mask>",
|
| 51 |
+
"max_length": null,
|
| 52 |
+
"model_max_length": 512,
|
| 53 |
+
"pad_to_multiple_of": null,
|
| 54 |
+
"pad_token": "<pad>",
|
| 55 |
+
"pad_token_type_id": 0,
|
| 56 |
+
"padding_side": "right",
|
| 57 |
+
"processor_class": "ClapProcessor",
|
| 58 |
+
"sep_token": "</s>",
|
| 59 |
+
"tokenizer_class": "RobertaTokenizer",
|
| 60 |
+
"trim_offsets": true,
|
| 61 |
+
"trust_remote_code": false,
|
| 62 |
+
"unk_token": "<unk>"
|
| 63 |
+
}
|
clap-onnx/vocab.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
faster-whisper-base.en/.gitattributes
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
*.7z filter=lfs diff=lfs merge=lfs -text
|
| 2 |
+
*.arrow filter=lfs diff=lfs merge=lfs -text
|
| 3 |
+
*.bin filter=lfs diff=lfs merge=lfs -text
|
| 4 |
+
*.bz2 filter=lfs diff=lfs merge=lfs -text
|
| 5 |
+
*.ckpt filter=lfs diff=lfs merge=lfs -text
|
| 6 |
+
*.ftz filter=lfs diff=lfs merge=lfs -text
|
| 7 |
+
*.gz filter=lfs diff=lfs merge=lfs -text
|
| 8 |
+
*.h5 filter=lfs diff=lfs merge=lfs -text
|
| 9 |
+
*.joblib filter=lfs diff=lfs merge=lfs -text
|
| 10 |
+
*.lfs.* filter=lfs diff=lfs merge=lfs -text
|
| 11 |
+
*.mlmodel filter=lfs diff=lfs merge=lfs -text
|
| 12 |
+
*.model filter=lfs diff=lfs merge=lfs -text
|
| 13 |
+
*.msgpack filter=lfs diff=lfs merge=lfs -text
|
| 14 |
+
*.npy filter=lfs diff=lfs merge=lfs -text
|
| 15 |
+
*.npz filter=lfs diff=lfs merge=lfs -text
|
| 16 |
+
*.onnx filter=lfs diff=lfs merge=lfs -text
|
| 17 |
+
*.ot filter=lfs diff=lfs merge=lfs -text
|
| 18 |
+
*.parquet filter=lfs diff=lfs merge=lfs -text
|
| 19 |
+
*.pb filter=lfs diff=lfs merge=lfs -text
|
| 20 |
+
*.pickle filter=lfs diff=lfs merge=lfs -text
|
| 21 |
+
*.pkl filter=lfs diff=lfs merge=lfs -text
|
| 22 |
+
*.pt filter=lfs diff=lfs merge=lfs -text
|
| 23 |
+
*.pth filter=lfs diff=lfs merge=lfs -text
|
| 24 |
+
*.rar filter=lfs diff=lfs merge=lfs -text
|
| 25 |
+
*.safetensors filter=lfs diff=lfs merge=lfs -text
|
| 26 |
+
saved_model/**/* filter=lfs diff=lfs merge=lfs -text
|
| 27 |
+
*.tar.* filter=lfs diff=lfs merge=lfs -text
|
| 28 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
faster-whisper-base.en/README.md
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
language:
|
| 3 |
+
- en
|
| 4 |
+
tags:
|
| 5 |
+
- audio
|
| 6 |
+
- automatic-speech-recognition
|
| 7 |
+
license: mit
|
| 8 |
+
library_name: ctranslate2
|
| 9 |
+
---
|
| 10 |
+
|
| 11 |
+
# Whisper base.en model for CTranslate2
|
| 12 |
+
|
| 13 |
+
This repository contains the conversion of [openai/whisper-base.en](https://huggingface.co/openai/whisper-base.en) to the [CTranslate2](https://github.com/OpenNMT/CTranslate2) model format.
|
| 14 |
+
|
| 15 |
+
This model can be used in CTranslate2 or projects based on CTranslate2 such as [faster-whisper](https://github.com/systran/faster-whisper).
|
| 16 |
+
|
| 17 |
+
## Example
|
| 18 |
+
|
| 19 |
+
```python
|
| 20 |
+
from faster_whisper import WhisperModel
|
| 21 |
+
|
| 22 |
+
model = WhisperModel("base.en")
|
| 23 |
+
|
| 24 |
+
segments, info = model.transcribe("audio.mp3")
|
| 25 |
+
for segment in segments:
|
| 26 |
+
print("[%.2fs -> %.2fs] %s" % (segment.start, segment.end, segment.text))
|
| 27 |
+
```
|
| 28 |
+
|
| 29 |
+
## Conversion details
|
| 30 |
+
|
| 31 |
+
The original model was converted with the following command:
|
| 32 |
+
|
| 33 |
+
```
|
| 34 |
+
ct2-transformers-converter --model openai/whisper-base.en --output_dir faster-whisper-base.en \
|
| 35 |
+
--copy_files tokenizer.json --quantization float16
|
| 36 |
+
```
|
| 37 |
+
|
| 38 |
+
Note that the model weights are saved in FP16. This type can be changed when the model is loaded using the [`compute_type` option in CTranslate2](https://opennmt.net/CTranslate2/quantization.html).
|
| 39 |
+
|
| 40 |
+
## More information
|
| 41 |
+
|
| 42 |
+
**For more information about the original model, see its [model card](https://huggingface.co/openai/whisper-base.en).**
|
faster-whisper-base.en/config.json
ADDED
|
@@ -0,0 +1,220 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"alignment_heads": [
|
| 3 |
+
[
|
| 4 |
+
3,
|
| 5 |
+
3
|
| 6 |
+
],
|
| 7 |
+
[
|
| 8 |
+
4,
|
| 9 |
+
7
|
| 10 |
+
],
|
| 11 |
+
[
|
| 12 |
+
5,
|
| 13 |
+
1
|
| 14 |
+
],
|
| 15 |
+
[
|
| 16 |
+
5,
|
| 17 |
+
5
|
| 18 |
+
],
|
| 19 |
+
[
|
| 20 |
+
5,
|
| 21 |
+
7
|
| 22 |
+
]
|
| 23 |
+
],
|
| 24 |
+
"lang_ids": [
|
| 25 |
+
50259,
|
| 26 |
+
50260,
|
| 27 |
+
50261,
|
| 28 |
+
50262,
|
| 29 |
+
50263,
|
| 30 |
+
50264,
|
| 31 |
+
50265,
|
| 32 |
+
50266,
|
| 33 |
+
50267,
|
| 34 |
+
50268,
|
| 35 |
+
50269,
|
| 36 |
+
50270,
|
| 37 |
+
50271,
|
| 38 |
+
50272,
|
| 39 |
+
50273,
|
| 40 |
+
50274,
|
| 41 |
+
50275,
|
| 42 |
+
50276,
|
| 43 |
+
50277,
|
| 44 |
+
50278,
|
| 45 |
+
50279,
|
| 46 |
+
50280,
|
| 47 |
+
50281,
|
| 48 |
+
50282,
|
| 49 |
+
50283,
|
| 50 |
+
50284,
|
| 51 |
+
50285,
|
| 52 |
+
50286,
|
| 53 |
+
50287,
|
| 54 |
+
50288,
|
| 55 |
+
50289,
|
| 56 |
+
50290,
|
| 57 |
+
50291,
|
| 58 |
+
50292,
|
| 59 |
+
50293,
|
| 60 |
+
50294,
|
| 61 |
+
50295,
|
| 62 |
+
50296,
|
| 63 |
+
50297,
|
| 64 |
+
50298,
|
| 65 |
+
50299,
|
| 66 |
+
50300,
|
| 67 |
+
50301,
|
| 68 |
+
50302,
|
| 69 |
+
50303,
|
| 70 |
+
50304,
|
| 71 |
+
50305,
|
| 72 |
+
50306,
|
| 73 |
+
50307,
|
| 74 |
+
50308,
|
| 75 |
+
50309,
|
| 76 |
+
50310,
|
| 77 |
+
50311,
|
| 78 |
+
50312,
|
| 79 |
+
50313,
|
| 80 |
+
50314,
|
| 81 |
+
50315,
|
| 82 |
+
50316,
|
| 83 |
+
50317,
|
| 84 |
+
50318,
|
| 85 |
+
50319,
|
| 86 |
+
50320,
|
| 87 |
+
50321,
|
| 88 |
+
50322,
|
| 89 |
+
50323,
|
| 90 |
+
50324,
|
| 91 |
+
50325,
|
| 92 |
+
50326,
|
| 93 |
+
50327,
|
| 94 |
+
50328,
|
| 95 |
+
50329,
|
| 96 |
+
50330,
|
| 97 |
+
50331,
|
| 98 |
+
50332,
|
| 99 |
+
50333,
|
| 100 |
+
50334,
|
| 101 |
+
50335,
|
| 102 |
+
50336,
|
| 103 |
+
50337,
|
| 104 |
+
50338,
|
| 105 |
+
50339,
|
| 106 |
+
50340,
|
| 107 |
+
50341,
|
| 108 |
+
50342,
|
| 109 |
+
50343,
|
| 110 |
+
50344,
|
| 111 |
+
50345,
|
| 112 |
+
50346,
|
| 113 |
+
50347,
|
| 114 |
+
50348,
|
| 115 |
+
50349,
|
| 116 |
+
50350,
|
| 117 |
+
50351,
|
| 118 |
+
50352,
|
| 119 |
+
50353,
|
| 120 |
+
50354,
|
| 121 |
+
50355,
|
| 122 |
+
50356
|
| 123 |
+
],
|
| 124 |
+
"suppress_ids": [
|
| 125 |
+
1,
|
| 126 |
+
2,
|
| 127 |
+
7,
|
| 128 |
+
8,
|
| 129 |
+
9,
|
| 130 |
+
10,
|
| 131 |
+
14,
|
| 132 |
+
25,
|
| 133 |
+
26,
|
| 134 |
+
27,
|
| 135 |
+
28,
|
| 136 |
+
29,
|
| 137 |
+
31,
|
| 138 |
+
58,
|
| 139 |
+
59,
|
| 140 |
+
60,
|
| 141 |
+
61,
|
| 142 |
+
62,
|
| 143 |
+
63,
|
| 144 |
+
90,
|
| 145 |
+
91,
|
| 146 |
+
92,
|
| 147 |
+
93,
|
| 148 |
+
357,
|
| 149 |
+
366,
|
| 150 |
+
438,
|
| 151 |
+
532,
|
| 152 |
+
685,
|
| 153 |
+
705,
|
| 154 |
+
796,
|
| 155 |
+
930,
|
| 156 |
+
1058,
|
| 157 |
+
1220,
|
| 158 |
+
1267,
|
| 159 |
+
1279,
|
| 160 |
+
1303,
|
| 161 |
+
1343,
|
| 162 |
+
1377,
|
| 163 |
+
1391,
|
| 164 |
+
1635,
|
| 165 |
+
1782,
|
| 166 |
+
1875,
|
| 167 |
+
2162,
|
| 168 |
+
2361,
|
| 169 |
+
2488,
|
| 170 |
+
3467,
|
| 171 |
+
4008,
|
| 172 |
+
4211,
|
| 173 |
+
4600,
|
| 174 |
+
4808,
|
| 175 |
+
5299,
|
| 176 |
+
5855,
|
| 177 |
+
6329,
|
| 178 |
+
7203,
|
| 179 |
+
9609,
|
| 180 |
+
9959,
|
| 181 |
+
10563,
|
| 182 |
+
10786,
|
| 183 |
+
11420,
|
| 184 |
+
11709,
|
| 185 |
+
11907,
|
| 186 |
+
13163,
|
| 187 |
+
13697,
|
| 188 |
+
13700,
|
| 189 |
+
14808,
|
| 190 |
+
15306,
|
| 191 |
+
16410,
|
| 192 |
+
16791,
|
| 193 |
+
17992,
|
| 194 |
+
19203,
|
| 195 |
+
19510,
|
| 196 |
+
20724,
|
| 197 |
+
22305,
|
| 198 |
+
22935,
|
| 199 |
+
27007,
|
| 200 |
+
30109,
|
| 201 |
+
30420,
|
| 202 |
+
33409,
|
| 203 |
+
34949,
|
| 204 |
+
40283,
|
| 205 |
+
40493,
|
| 206 |
+
40549,
|
| 207 |
+
47282,
|
| 208 |
+
49146,
|
| 209 |
+
50257,
|
| 210 |
+
50357,
|
| 211 |
+
50358,
|
| 212 |
+
50359,
|
| 213 |
+
50360,
|
| 214 |
+
50361
|
| 215 |
+
],
|
| 216 |
+
"suppress_ids_begin": [
|
| 217 |
+
220,
|
| 218 |
+
50256
|
| 219 |
+
]
|
| 220 |
+
}
|
faster-whisper-base.en/model.bin
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:2a166925539a16005f14ff328359f9b9adb9dc4fb631bb3b227526862e93e2ef
|
| 3 |
+
size 145216508
|
faster-whisper-base.en/tokenizer.json
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
faster-whisper-base.en/vocabulary.txt
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
ranker5.pkl
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:cb8cb31edd0e80b842f3c4189129262f849cfa07508a7f09cebd38266d5d99ae
|
| 3 |
+
size 3111326
|