Upload seamless_communication/datasets/datatypes.py with huggingface_hub
Browse files
seamless_communication/datasets/datatypes.py
ADDED
@@ -0,0 +1,47 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
# Copyright (c) Meta Platforms, Inc. and affiliates
|
2 |
+
# All rights reserved.
|
3 |
+
#
|
4 |
+
# This source code is licensed under the license found in the
|
5 |
+
# MIT_LICENSE file in the root directory of this source tree.
|
6 |
+
|
7 |
+
|
8 |
+
from dataclasses import dataclass
|
9 |
+
from typing import Any, Dict, List, Optional
|
10 |
+
|
11 |
+
import torch
|
12 |
+
|
13 |
+
|
14 |
+
@dataclass
|
15 |
+
class MultimodalSample:
|
16 |
+
id: int
|
17 |
+
lang: str
|
18 |
+
text: str
|
19 |
+
audio_local_path: Optional[str] = None
|
20 |
+
waveform: Optional[torch.Tensor] = None
|
21 |
+
sampling_rate: Optional[int] = None
|
22 |
+
units: Optional[List[int]] = None
|
23 |
+
|
24 |
+
@classmethod
|
25 |
+
def from_json(cls, js: Dict[str, Any]) -> "MultimodalSample":
|
26 |
+
return cls(
|
27 |
+
id=js["id"],
|
28 |
+
lang=js["lang"],
|
29 |
+
text=js["text"],
|
30 |
+
audio_local_path=js.get("audio_local_path"),
|
31 |
+
waveform=None, # don't serialize
|
32 |
+
sampling_rate=js.get("sampling_rate"),
|
33 |
+
units=js.get("units"),
|
34 |
+
)
|
35 |
+
|
36 |
+
|
37 |
+
@dataclass
|
38 |
+
class LangPairSample:
|
39 |
+
source: MultimodalSample
|
40 |
+
target: MultimodalSample
|
41 |
+
|
42 |
+
@classmethod
|
43 |
+
def from_json(cls, js: Dict[str, Any]) -> "LangPairSample":
|
44 |
+
return cls(
|
45 |
+
source=MultimodalSample.from_json(js["source"]),
|
46 |
+
target=MultimodalSample.from_json(js["target"]),
|
47 |
+
)
|