Fine tuning BART to generate Summary

Viewed 2003

I am trying to fine tune the BART model to generate news headlines.

I am taking the dataset from Kaggle News Summary

Fine tuning Colab notebook

However, in the validation section when trying to generate the text from encoded tokens, i am running into error

---------------------------------------------------------------------------
---------------------------------------------------------------------------
RuntimeError                              Traceback (most recent call last)
<ipython-input-22-059727516ce4> in <module>()
      1 for epoch in range(1):
----> 2     predictions, actuals = validate(epoch)
      3     writer(predictions, actuals)
      4     print('Output Files generated for review')

4 frames
<ipython-input-21-6738e7a3f1f9> in validate(epoch)
     10             mask = data['source_mask'].to(device, dtype = torch.long)
     11 
---> 12             generate_ids = model.generate(input_ids = ids,attention_mask = mask, num_beams=4,repetition_penalty=2.5,length_penalty=2.0,early_stopping=True)
     13             preds = [tokenizer.decode(g, skip_special_tokens=True, clean_up_tokenization_spaces=True) for g in generate_ids]
     14             target = [tokenizer.decode(t, skip_special_tokens=True, clean_up_tokenization_spaces=True)for t in y]

/usr/local/lib/python3.6/dist-packages/torch/autograd/grad_mode.py in decorate_context(*args, **kwargs)
     13         def decorate_context(*args, **kwargs):
     14             with self:
---> 15                 return func(*args, **kwargs)
     16         return decorate_context
     17 

/usr/local/lib/python3.6/dist-packages/transformers/modeling_utils.py in generate(self, input_ids, max_length, min_length, do_sample, early_stopping, num_beams, temperature, top_k, top_p, repetition_penalty, bad_words_ids, bos_token_id, pad_token_id, eos_token_id, length_penalty, no_repeat_ngram_size, num_return_sequences, attention_mask, decoder_start_token_id, use_cache, **model_specific_kwargs)
    914 
    915         # We cannot generate if the model does not have a LM head
--> 916         if self.get_output_embeddings() is None:
    917             raise AttributeError(
    918                 "You tried to generate sequences with a model that does not have a LM Head."

/usr/local/lib/python3.6/dist-packages/transformers/modeling_bart.py in get_output_embeddings(self)
   1021 
   1022     def get_output_embeddings(self):
-> 1023         return _make_linear_from_emb(self.model.shared)  # make it on the fly
   1024 
   1025 

/usr/local/lib/python3.6/dist-packages/transformers/modeling_bart.py in _make_linear_from_emb(emb)
    148     vocab_size, emb_size = emb.weight.shape
    149     lin_layer = nn.Linear(vocab_size, emb_size, bias=False)
--> 150     lin_layer.weight.data = emb.weight.data
    151     return lin_layer
    152 

RuntimeError: Attempted to call `variable.set_data(tensor)`, but `variable` and `tensor` have incompatible tensor type.

It will be great if i could get some guidance from the group. Thanks!

0 Answers
Related