Code Monkey home page Code Monkey logo

Comments (6)

DocIsenberg avatar DocIsenberg commented on July 22, 2024 1

Hey, I was able to load tensorflow checkpoints for both the pytorch-transformers v1.0.0 and the bertviz packaged version by editing modeling_bert.py as follows:
At line 105, change pointer = model to

        if len(name) == 1:                                                                                                                                                                                                                                                      
            if type(model).__name__ == "BertForSequenceClassification":                                                                                                                                                                                                         
                pointer = model.classifier                                                                                                                                                                                                                                      
            else:                                                                                                                                                                                                                                                               
                continue                                                                                                                                                                                                                                                        
        else:                                                                                                                                                                                                                                                                   
            pointer = model

Unfortunately, I got stuck here, see attached image. The "Layer" dialog box has no options in it, and there's no visualization nor error, just ...blank.

Screen Shot 2019-10-16 at 12 15 42 PM

EDITED/SOLVED:

I was running the notebook from outside the bertviz directory by adding bertviz to the PYTHONPATH and following instructions from there. I can fix my issue by running the notebook in the directory directly, although I frankly don't know why-

__location__ = os.path.realpath(
        os.path.join(os.getcwd(), os.path.dirname(__file__)))
print(__location__)

shows the correct path regardless of where the notebook is executing from. Anyway, my issue was resolved. I hope this helps someone.

from bertviz.

jessevig avatar jessevig commented on July 22, 2024

Hi,
Thanks for reporting this. A couple of things:

If you're getting this error in BertForSequenceClassification, and you can't find a solution in the issues above, you might consider opening an issue with pytorch_transformers (https://github.com/huggingface/pytorch-transformers) as they would probably be in a better position to help.

from bertviz.

Surabhi-Kumari avatar Surabhi-Kumari commented on July 22, 2024

Thanks for reply.
I had tried both things "num_labels" and "num_label", getting the same error.
I have referred to huggingface/pytorch-transformers#676, but unable to resolve this.

from bertviz.

jessevig avatar jessevig commented on July 22, 2024

Thanks for sharing. BTW, the latest version of BertViz allows you to load a model directly using the transformers library, so this shouldn't be an issue going forward.

from bertviz.

chikubee avatar chikubee commented on July 22, 2024

@jessevig
I fine-tuned bert for a classification task. (following https://github.com/google-research/bert)
I mean to convert the tensorflow checkpoints to pytorch so that i can load the model into BertForSequenceClassification for visualization.

I used the following script

Initialise a configuration according to your model

config = BertConfig.from_pretrained('bert-base-uncased')
config.num_labels=4

You will need to load a BertForSequenceClassification model

model = BertForSequenceClassification(config)

tf_checkpoint_path = init_checkpoint

Load weights from tf checkpoint

load_tf_weights_in_bert(model, config, tf_checkpoint_path)

pytorch_dump_path = "./pytorch_bert_output"

Save pytorch-model

print("Save PyTorch model to {}".format(pytorch_dump_path))
torch.save(model.state_dict(), pytorch_dump_path)

I am getting the following error
BertForSequenceClassification object has no attribute 'bias'

Please help me out.
Thanks

from bertviz.

shishishu avatar shishishu commented on July 22, 2024

@chikubee

Hello, I try to visualize fine-tuned BERT model with BertModel and similar error occurs: "AttributeError: 'BertModel' object has no attribute 'bias"

This error occurs in file: "...Lib\site-packages\transformers\modeling_bert.py" line 104 and you can disable related lines in source codes.

104

015

Let me know if any questions.

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.