Instructions to use howtomix/pyannote-segmentation-3.0 with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- Transformers.js
How to use howtomix/pyannote-segmentation-3.0 with Transformers.js:
// ⚠️ Unknown pipeline tag
Duplicate from onnx-community/pyannote-segmentation-3.0
Browse filesCo-authored-by: Joshua <Xenova@users.noreply.huggingface.co>
- .gitattributes +35 -0
- README.md +93 -0
- config.json +21 -0
- onnx/model.onnx +3 -0
- onnx/model_bnb4.onnx +3 -0
- onnx/model_fp16.onnx +3 -0
- onnx/model_int8.onnx +3 -0
- onnx/model_q4.onnx +3 -0
- onnx/model_q4f16.onnx +3 -0
- onnx/model_quantized.onnx +3 -0
- onnx/model_uint8.onnx +3 -0
- preprocessor_config.json +7 -0
.gitattributes
ADDED
|
@@ -0,0 +1,35 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 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 |
+
*.tar filter=lfs diff=lfs merge=lfs -text
|
| 29 |
+
*.tflite filter=lfs diff=lfs merge=lfs -text
|
| 30 |
+
*.tgz filter=lfs diff=lfs merge=lfs -text
|
| 31 |
+
*.wasm filter=lfs diff=lfs merge=lfs -text
|
| 32 |
+
*.xz filter=lfs diff=lfs merge=lfs -text
|
| 33 |
+
*.zip filter=lfs diff=lfs merge=lfs -text
|
| 34 |
+
*.zst filter=lfs diff=lfs merge=lfs -text
|
| 35 |
+
*tfevents* filter=lfs diff=lfs merge=lfs -text
|
README.md
ADDED
|
@@ -0,0 +1,93 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
base_model: pyannote/segmentation-3.0
|
| 3 |
+
library_name: transformers.js
|
| 4 |
+
license: mit
|
| 5 |
+
---
|
| 6 |
+
|
| 7 |
+
https://huggingface.co/pyannote/segmentation-3.0 with ONNX weights to be compatible with Transformers.js.
|
| 8 |
+
|
| 9 |
+
|
| 10 |
+
## Transformers.js (v3) usage
|
| 11 |
+
|
| 12 |
+
```js
|
| 13 |
+
import { AutoProcessor, AutoModelForAudioFrameClassification, read_audio } from '@huggingface/transformers';
|
| 14 |
+
|
| 15 |
+
// Load model and processor
|
| 16 |
+
const model_id = 'onnx-community/pyannote-segmentation-3.0';
|
| 17 |
+
const model = await AutoModelForAudioFrameClassification.from_pretrained(model_id);
|
| 18 |
+
const processor = await AutoProcessor.from_pretrained(model_id);
|
| 19 |
+
|
| 20 |
+
// Read and preprocess audio
|
| 21 |
+
const url = 'https://huggingface.co/datasets/Xenova/transformers.js-docs/resolve/main/mlk.wav';
|
| 22 |
+
const audio = await read_audio(url, processor.feature_extractor.config.sampling_rate);
|
| 23 |
+
const inputs = await processor(audio);
|
| 24 |
+
|
| 25 |
+
// Run model with inputs
|
| 26 |
+
const { logits } = await model(inputs);
|
| 27 |
+
// {
|
| 28 |
+
// logits: Tensor {
|
| 29 |
+
// dims: [ 1, 767, 7 ], // [batch_size, num_frames, num_classes]
|
| 30 |
+
// type: 'float32',
|
| 31 |
+
// data: Float32Array(5369) [ ... ],
|
| 32 |
+
// size: 5369
|
| 33 |
+
// }
|
| 34 |
+
// }
|
| 35 |
+
|
| 36 |
+
const result = processor.post_process_speaker_diarization(logits, audio.length);
|
| 37 |
+
// [
|
| 38 |
+
// [
|
| 39 |
+
// { id: 0, start: 0, end: 1.0512535626298245, confidence: 0.8220156481664611 },
|
| 40 |
+
// { id: 2, start: 1.0512535626298245, end: 2.3398869619825127, confidence: 0.9008811707860472 },
|
| 41 |
+
// ...
|
| 42 |
+
// ]
|
| 43 |
+
// ]
|
| 44 |
+
|
| 45 |
+
// Display result
|
| 46 |
+
console.table(result[0], ['start', 'end', 'id', 'confidence']);
|
| 47 |
+
// ┌─────────┬────────────────────┬────────────────────┬────┬─────────────────────┐
|
| 48 |
+
// │ (index) │ start │ end │ id │ confidence │
|
| 49 |
+
// ├─────────┼────────────────────┼────────────────────┼────┼─────────────────────┤
|
| 50 |
+
// │ 0 │ 0 │ 1.0512535626298245 │ 0 │ 0.8220156481664611 │
|
| 51 |
+
// │ 1 │ 1.0512535626298245 │ 2.3398869619825127 │ 2 │ 0.9008811707860472 │
|
| 52 |
+
// │ 2 │ 2.3398869619825127 │ 3.5946089560890773 │ 0 │ 0.7521651315796233 │
|
| 53 |
+
// │ 3 │ 3.5946089560890773 │ 4.578039708226655 │ 2 │ 0.8491978128022479 │
|
| 54 |
+
// │ 4 │ 4.578039708226655 │ 4.594995410849717 │ 0 │ 0.2935352600416393 │
|
| 55 |
+
// │ 5 │ 4.594995410849717 │ 6.121008646925269 │ 3 │ 0.6788051309866024 │
|
| 56 |
+
// │ 6 │ 6.121008646925269 │ 6.256654267909762 │ 0 │ 0.37125512393851134 │
|
| 57 |
+
// │ 7 │ 6.256654267909762 │ 8.630452635138397 │ 2 │ 0.7467035186353542 │
|
| 58 |
+
// │ 8 │ 8.630452635138397 │ 10.088643060721703 │ 0 │ 0.7689364814666032 │
|
| 59 |
+
// │ 9 │ 10.088643060721703 │ 12.58113134631177 │ 2 │ 0.9123324509131324 │
|
| 60 |
+
// │ 10 │ 12.58113134631177 │ 13.005023911888312 │ 0 │ 0.4828358177572041 │
|
| 61 |
+
// └─────────┴────────────────────┴────────────────────┴────┴─────────────────────┘
|
| 62 |
+
```
|
| 63 |
+
|
| 64 |
+
## Torch → ONNX conversion code:
|
| 65 |
+
```py
|
| 66 |
+
# pip install torch onnx https://github.com/pyannote/pyannote-audio/archive/refs/heads/develop.zip
|
| 67 |
+
import torch
|
| 68 |
+
from pyannote.audio import Model
|
| 69 |
+
|
| 70 |
+
model = Model.from_pretrained(
|
| 71 |
+
"pyannote/segmentation-3.0",
|
| 72 |
+
use_auth_token="hf_...", # <-- Set your HF token here
|
| 73 |
+
).eval()
|
| 74 |
+
|
| 75 |
+
dummy_input = torch.zeros(2, 1, 160000)
|
| 76 |
+
torch.onnx.export(
|
| 77 |
+
model,
|
| 78 |
+
dummy_input,
|
| 79 |
+
'model.onnx',
|
| 80 |
+
do_constant_folding=True,
|
| 81 |
+
input_names=["input_values"],
|
| 82 |
+
output_names=["logits"],
|
| 83 |
+
dynamic_axes={
|
| 84 |
+
"input_values": {0: "batch_size", 1: "num_channels", 2: "num_samples"},
|
| 85 |
+
"logits": {0: "batch_size", 1: "num_frames"},
|
| 86 |
+
},
|
| 87 |
+
)
|
| 88 |
+
```
|
| 89 |
+
|
| 90 |
+
---
|
| 91 |
+
|
| 92 |
+
|
| 93 |
+
Note: Having a separate repo for ONNX weights is intended to be a temporary solution until WebML gains more traction. If you would like to make your models web-ready, we recommend converting to ONNX using [🤗 Optimum](https://huggingface.co/docs/optimum/index) and structuring your repo like this one (with ONNX weights located in a subfolder named `onnx`).
|
config.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"model_type": "pyannote",
|
| 3 |
+
"id2label": {
|
| 4 |
+
"0": "NO_SPEAKER",
|
| 5 |
+
"1": "SPEAKER_1",
|
| 6 |
+
"2": "SPEAKER_2",
|
| 7 |
+
"3": "SPEAKER_3",
|
| 8 |
+
"4": "SPEAKERS_1_AND_2",
|
| 9 |
+
"5": "SPEAKERS_1_AND_3",
|
| 10 |
+
"6": "SPEAKERS_2_AND_3"
|
| 11 |
+
},
|
| 12 |
+
"label2id": {
|
| 13 |
+
"NO_SPEAKER": 0,
|
| 14 |
+
"SPEAKER_1": 1,
|
| 15 |
+
"SPEAKER_2": 2,
|
| 16 |
+
"SPEAKER_3": 3,
|
| 17 |
+
"SPEAKERS_1_AND_2": 4,
|
| 18 |
+
"SPEAKERS_1_AND_3": 5,
|
| 19 |
+
"SPEAKERS_2_AND_3": 6
|
| 20 |
+
}
|
| 21 |
+
}
|
onnx/model.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:057ee564753071c0b09b5b611648b50ac188d50846bff5f01e9f7bbf1591ea25
|
| 3 |
+
size 5986908
|
onnx/model_bnb4.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:1068e7f01b47e5410b232399f02890f61e95897313daac1bfe0d6a3307134fcc
|
| 3 |
+
size 5815342
|
onnx/model_fp16.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:f3dba0c91270b923e9ce66e4cef123820cb73c9b07e47e03a3d7d4267e4fbec4
|
| 3 |
+
size 3000918
|
onnx/model_int8.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:465d0975bf70fbf14fb77c0589a5d346a9c07c2170345f529cf774678446db76
|
| 3 |
+
size 1542304
|
onnx/model_q4.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:b6b0462cd3555b183e8845d37f372d9be2c0dd9a04ce79991b361186cf4d23ac
|
| 3 |
+
size 5818448
|
onnx/model_q4f16.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:e5664adf52a5637fb3785608772ca0d34c31911f96c4f48b3cebda0fb6f2c7ed
|
| 3 |
+
size 2929425
|
onnx/model_quantized.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:93a3eb106923c9b76a7d8af07ac337dd24c2d0dcd20f1b6c55f21133e944d658
|
| 3 |
+
size 1542308
|
onnx/model_uint8.onnx
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:93a3eb106923c9b76a7d8af07ac337dd24c2d0dcd20f1b6c55f21133e944d658
|
| 3 |
+
size 1542308
|
preprocessor_config.json
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
{
|
| 2 |
+
"feature_extractor_type": "PyAnnoteFeatureExtractor",
|
| 3 |
+
"processor_class": "PyAnnoteProcessor",
|
| 4 |
+
"offset": 990,
|
| 5 |
+
"sampling_rate": 16000,
|
| 6 |
+
"step": 270
|
| 7 |
+
}
|