Code Monkey home page Code Monkey logo

Comments (3)

goncalomcorreia avatar goncalomcorreia commented on August 20, 2024 1

Hi,

We did define a trainable parameter for each head per layer. Here's a small code snippet that we used:

class AlphaChooser(torch.nn.Module):

    def __init__(self, head_count):
        """head_count (int): number of attention heads"""
        super(AlphaChooser, self).__init__()
        self.pre_alpha = nn.Parameter(torch.randn(head_count))

    def forward(self):
        alpha = 1 + torch.sigmoid(self.pre_alpha)
        return torch.clamp(alpha, min=1.01, max=2)

However, it's possible to have a single alpha per layer, or per transformer block!

from entmax.

alibabadoufu avatar alibabadoufu commented on August 20, 2024

Thanks so much! @goncalomcorreia
Nice work though!

from entmax.

hihihihiwsf avatar hihihihiwsf commented on August 20, 2024

Hello!

How can I compute the entmax_bisect when the size of alpha is larger than 1 ?
When I use this:
p_attn = entmax_bisect(x, alpha, n_iter=25)
where alpha=tensor([1.3691, 1.5766, 1.7588, 1.9206],grad_fn=), the shape of x is [batch_size, 4, d,d].
There arises the error that
The expanded size of the tensor (1) must match the existing size (4) at non-singleton dimension 3.

image

from entmax.

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.