GithubHelp home page GithubHelp logo

Comments (14)

jessevig avatar jessevig commented on July 23, 2024 4

Good idea, and thanks for pointing me to that code. I've been experimenting with gradient-based sensitivity analysis on the attention weights (rather than the inputs), but the results weren't particularly interpretable. But I may revisit this with some of the newer fine-tuned models. I agree that this would be a useful analysis for the inputs, though it may overload the visualization. I'll think more about this. Thanks.

from bertviz.

koren-v avatar koren-v commented on July 23, 2024 4

Hi, I did the implementation of some gradient-based algorithms, you can check it here: https://github.com/koren-v/Interpret
(Integrated Gradients works pretty good compared to Smooth Grad)

from bertviz.

ssdorsey avatar ssdorsey commented on July 23, 2024 3

I can definitely recommend captum as well, they have an example using BERT: https://captum.ai/tutorials/Bert_SQUAD_Interpret

from bertviz.

Azharo avatar Azharo commented on July 23, 2024

I've been wondering how to do this as well as I want to try and visualize which words were most important to the classification. One idea I've had is (if I have 12 encoders in BERT and am only fine-tuning the 12th layer) to take the output of the 11th layer, the Wq, Wk, and Wv weights of the fine-tuned 12th layer and calculate the score manually. Would that be the correct way to think of it? I would essentially get the value score for each token in the input.

from bertviz.

zysNLP avatar zysNLP commented on July 23, 2024

Hi, @jessevig Thanks for your great work. As @lspataro @Azharo mentioned, I want to ask some more details. Lets see an example below:
As we know, BERT/GPT2 accept datas in the form of "sentence, label" or "prompt, inference, label", which maybe means a text classify task and a NLI task, like these sentences:

Text classifies:
s1: The girl wears a red hat and dresses up like a princess. ---label "clothing"
s2: He went to play basketball after class. It seems not many people today. ---label "sport"
As we expected, the words hat and dress in s1, basketball in s2 should get more attentions or a greater weight.

NLIs:
prompt: Some people think that strict punishments for driving offenses are the key to reducing traffic accidents.
inference: Government should invest more in non-profit advertisements, so that they would improve people’s safety awareness potentially
label: 1
As we expected, the words "driving offenses","traffic accidents" in prompt and "government","safety awareness" in inference maybe get more attentions or a greater weight, other words maybe get smaller weights.

We want to get results like these, maybe not a relatively complex visualization results as @jessevig showed, I think this work may need to be done in the last layer of Bert. Furthermore, I would like to see a process.
For example, when we focus on the word hat in s1 above, according to the result clothing, I would like to see how Bert focuses higher weight on hat step by step, which should be the result of a series of time series locking hat, but I am not clear about what it should be, hoping to get your answer. Thank you!

from bertviz.

diogocortiz avatar diogocortiz commented on July 23, 2024

Hi there, anyone working on this topic?

I am looking for a way to identify the most important words in a sentence classification task as well.

from bertviz.

dshahrokhian avatar dshahrokhian commented on July 23, 2024

+1

from bertviz.

koren-v avatar koren-v commented on July 23, 2024

+1

from bertviz.

LinkToPast1990 avatar LinkToPast1990 commented on July 23, 2024

same question here :)

from bertviz.

gcunhase avatar gcunhase commented on July 23, 2024

+1

from bertviz.

clairemcwhite avatar clairemcwhite commented on July 23, 2024

This package does word importance directly with huggingface transformers, using captum

https://github.com/cdpierse/transformers-interpret

Transformers Interpret is a model explainability tool designed to work exclusively with the 🤗 transformers package.

In line with the philosophy of the transformers package Transformers Interpret allows any transformers model to be explained in just two lines. It even supports visualizations in both notebooks and as savable html files.

from bertviz.

jessevig avatar jessevig commented on July 23, 2024

Closing this issue as I feel it's out of scope for BertViz given the other available libraries.

from bertviz.

er-vishalgour avatar er-vishalgour commented on July 23, 2024

Yeah Same question

from bertviz.

shoroukadel avatar shoroukadel commented on July 23, 2024

I try to use the code in this link https://github.com/cdpierse/transformers-interpret for a multi classification task for my pretrained model using bert function.I trained my model and save it using model.save(). then when I try to load the model path to model I got this error

  • `OSError: Can't load config for '/content/drive/Shared with me/Colab Notebooks/bert_visualization2.h5py'. Make sure that:

  • '/content/drive/Shared with me/Colab Notebooks/bert_visualization2.h5py' is a correct model identifier listed on 'https://huggingface.co/models'

  • or '/content/drive/Shared with me/Colab Notebooks/bert_visualization2.h5py' is the correct path to a directory containing a config.json file

  • `

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.