Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add BART finetuned on CNN+DM for summarisation #1060

Merged
merged 4 commits into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions keras_nlp/models/bart/bart_presets.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,32 @@
"merges_url": "https://storage.googleapis.com/keras-nlp/models/bart_large_en/v1/merges.txt",
"merges_hash": "75a37753dd7a28a2c5df80c28bf06e4e",
},
"bart_large_en_cnn": {
mattdangerw marked this conversation as resolved.
Show resolved Hide resolved
"metadata": {
"description": (
"The `bart_large_en` backbone model fine-tuned on the CNN+DM "
"summarization dataset."
),
"params": 406287360,
"official_name": "BART",
"path": "bart",
"model_card": "https://github.com/facebookresearch/fairseq/blob/main/examples/bart/README.md",
},
"config": {
"vocabulary_size": 50264,
"num_layers": 12,
"num_heads": 16,
"hidden_dim": 1024,
"intermediate_dim": 4096,
"dropout": 0.1,
"max_sequence_length": 1024,
},
"preprocessor_config": {},
"weights_url": "https://storage.googleapis.com/keras-nlp/models/bart_large_en_cnn/v1/model.h5",
"weights_hash": "99782ecd9365956f016096fef9afd62c",
"vocabulary_url": "https://storage.googleapis.com/keras-nlp/models/bart_large_en_cnn/v1/vocab.json",
"vocabulary_hash": "be4d3c6f3f5495426b2c03b334334354",
"merges_url": "https://storage.googleapis.com/keras-nlp/models/bart_large_en_cnn/v1/merges.txt",
"merges_hash": "75a37753dd7a28a2c5df80c28bf06e4e",
},
}
8 changes: 8 additions & 0 deletions keras_nlp/models/bart/bart_seq_2_seq_lm_preprocessor.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,19 @@

"""BART Seq2Seq LM preprocessor layer."""

import copy

import tensorflow as tf
from absl import logging

from keras_nlp.api_export import keras_nlp_export
from keras_nlp.models.bart.bart_preprocessor import BartPreprocessor
from keras_nlp.models.bart.bart_presets import backbone_presets
from keras_nlp.utils.keras_utils import (
convert_inputs_to_list_of_tensor_segments,
)
from keras_nlp.utils.keras_utils import pack_x_y_sample_weight
from keras_nlp.utils.python_utils import classproperty


@keras_nlp_export("keras_nlp.models.BartSeq2SeqLMPreprocessor")
Expand Down Expand Up @@ -188,6 +192,10 @@ def call(self, x, y=None, sample_weight=None):
sample_weight = decoder_padding_mask[..., 1:]
return pack_x_y_sample_weight(x, y, sample_weight)

@classproperty
def presets(cls):
return copy.deepcopy(backbone_presets)

def generate_preprocess(
self,
x,
Expand Down
1 change: 1 addition & 0 deletions tools/checkpoint_conversion/convert_bart_checkpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
PRESET_MAP = {
"bart_base_en": "facebook/bart-base",
"bart_large_en": "facebook/bart-large",
"bart_large_en_cnn": "facebook/bart-large-cnn",
}

FLAGS = flags.FLAGS
Expand Down