Spaces:
Sleeping
Sleeping
File size: 595 Bytes
506a2b4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 |
from .s3tokenizer import (
S3_SR,
S3_HOP,
S3_TOKEN_HOP,
S3_TOKEN_RATE,
SPEECH_VOCAB_SIZE,
S3Tokenizer,
)
SOS = SPEECH_VOCAB_SIZE
EOS = SPEECH_VOCAB_SIZE + 1
def drop_invalid_tokens(x):
"""Drop SoS and EoS"""
assert len(x.shape) == 1 or (len(x.shape) == 2 and x.shape[0] == 1), "only batch size of one allowed for now"
if SOS in x:
s = (x == SOS).nonzero(as_tuple=True)[0].squeeze(0) + 1
else:
s = 0
if EOS in x:
e = (x == EOS).nonzero(as_tuple=True)[0].squeeze(0)
else:
e = None
x = x[s: e]
return x
|