Limiting the number of languages for detection.

#5
by milanabogovic - opened

Hello.

I'm using the code under "How to use", and I'd like to know whether there is a possibility to limit the number of languages used for detection, and if it is, how could I go about doing that?

Thank you.

Hi,
I was looking for same solution and I managed to create some example.

audio_detector = EncoderClassifier.from_hparams(source="apenasissso/lang-id-voxlingua107-ecapa", savedir="/tmp")
emb = audio_detector.encode_batch(audio)
    out_prob = audio_detector.mods.classifier(emb).squeeze(1)
    probabilities = F.softmax(out_prob, dim=-1)
    top_k_values, top_k_indices = torch.topk(probabilities, k=5)
    results = [{
        "label": audio_detector.hparams.label_encoder.decode_torch(torch.tensor([idx.item()])),
        "score": value.item()
    } for value, idx in zip(top_k_values[0], top_k_indices[0])]

Sign up or log in to comment