Code Monkey home page Code Monkey logo

Comments (6)

jessevig avatar jessevig commented on August 23, 2024

Hi, I assume you are still using the Huggingface XLMModel class, but just with your own saved model weights? In that case you can still use the code in https://github.com/jessevig/bertviz/blob/master/head_view_xlm.ipynb but just change following lines, so that model_version is the directory in which your model is saved.

model_version = 'xlm-mlm-ende-1024'
model = XLMModel.from_pretrained(model_version, output_attentions=True)

Just be sure to set output_attentions=True, as above. Does that answer your question?

from bertviz.

akshaysadanand avatar akshaysadanand commented on August 23, 2024

No, I am not using huggingface's model. I am running the model found on the facebookresearch repo.

from bertviz.

jessevig avatar jessevig commented on August 23, 2024

If that is the case, and you are using the head view or model view, you can still use the notebook above, but you would need to call your model instead of the huggingface one and somehow retrieve the attention weights and reformat them as specified in head_view.py:

def head_view(attention, tokens, sentence_b_start = None, prettify_tokens=True):
    """Render head view
        Args:
            attention: list of ``torch.FloatTensor``(one for each layer) of shape
                ``(batch_size(must be 1), num_heads, sequence_length, sequence_length)``
            tokens: list of tokens
            sentence_b_index: index of first wordpiece in sentence B if input text is sentence pair (optional)
            prettify_tokens: indicates whether to remove special characters in wordpieces, e.g. Ġ
    """

I haven't worked with the FB model so not sure how to implement that on the model end.

from bertviz.

akshaysadanand avatar akshaysadanand commented on August 23, 2024

Okay, I'll try that. Thanks for the help!

from bertviz.

jessevig avatar jessevig commented on August 23, 2024

The other option is to try to convert your model to a huggingface-compatible model but I'm not sure how easy that would be either. It seems like something others might have done though.

from bertviz.

akshaysadanand avatar akshaysadanand commented on August 23, 2024

I will look into that. Thank you!

from bertviz.

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.