mikeizbicki / cmc-csci181-deeplearning

deep learning course materials
15 stars 6 forks source link

'BertFineTuning' object has no attribute 'fc_class' #57

Open clayton-north opened 4 years ago

clayton-north commented 4 years ago

When I run:

python3 names.py --embed --warm_start=(my model) --log_dir=embeddings
 File "names.py", line 659, in <module>
    category_embedding = torch.cat([model.fc_class.weight, torch.unsqueeze(model.fc_class.bias,dim=1)],dim=1)
  File "/Users/claytonnorth/opt/anaconda3/lib/python3.7/site-packages/torch/nn/modules/module.py", line 576, in __getattr__
    type(self).__name__, name))
AttributeError: 'BertFineTuning' object has no attribute 'fc_class'

I was wondering if anyone else had this issue/ what is the best way to get around this ?

Here is my part 3 code

category_embedding = torch.cat([model.fc_class.weight, torch.unsqueeze(model.fc_class.bias,dim=1)],dim=1)
    if args.log_dir == None:
        raise ValueError('must supply --log_dir to visualize an embedding')
    writer = SummaryWriter(log_dir = args.log_dir)
    writer.add_embedding(
        mat = category_embedding,
        metadata = all_categories,
        tag = 'category embedding'
    )
zhh1997zhh commented 4 years ago

You can change model.fc_class to something you defined (for example, model.fc) in your BertFineTuning object. I think that should fix your problem.

kielong commented 4 years ago

In your code, wherever you have fc_class, change it to fc.