Giter VIP home page Giter VIP logo

Comments (3)

Adel-Moumen avatar Adel-Moumen commented on September 24, 2024

Hey @TParcollet, could you please have a look?

from speechbrain.

porfirythelaw avatar porfirythelaw commented on September 24, 2024

My local fix is something like this (using features_padding_mask):

   padding_mask = make_padding_masks(wav, wav_len=wav_lens)
   features_padding_mask = self.model._get_feature_vector_attention_mask(
            sequence_length, padding_mask, add_adapter=False
        )

    # 1. Compute the indices that will be masked
    mask_time_indices = _compute_mask_indices(
        (batch_size, sequence_length),
        mask_prob=self.mask_prob,
        mask_length=self.mask_length,
        attention_mask=features_padding_mask

    )
    torch_mask_time_indices = torch.tensor(
        mask_time_indices, device=wav.device, dtype=torch.long,
    )

    # 2. Sample the negative samples from the entire sequence.
    # Fairseq does it only on the masked indices, but this only work if you
    # have long sentences. For more versatily, we sample on the entire sequence.
    # value.
    full_sentence_indices = np.ones((batch_size, sequence_length))

    negative_sample_indices = torch.tensor(
        transformers.models.wav2vec2.modeling_wav2vec2._sample_negative_indices(
            (batch_size, sequence_length),
            num_negatives=self.config.num_negatives,
            # mask_time_indices=full_sentence_indices,
            mask_time_indices=features_padding_mask.detach().cpu().numpy()

        ),
        device=wav.device,
        dtype=torch.long,
    )

from speechbrain.

TParcollet avatar TParcollet commented on September 24, 2024

That's quite late to answer, but yes it certainly is true. The reason is that we rely on HF functions here, and back to when we wrote this code, I believe there was no alternative. @porfirythelaw could you propose a PR with this fix? I will test it.

Many thanks.

from speechbrain.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.