IMvision12 commited on
Commit
fb99dd0
·
verified ·
1 Parent(s): 78aa3a9

Add bart_base (zeromodels Keras 3 conversion)

Browse files
Files changed (4) hide show
  1. README.md +95 -0
  2. model.weights.h5 +3 -0
  3. tokenizer.json +0 -0
  4. zm_config.json +33 -0
README.md ADDED
@@ -0,0 +1,95 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ ---
2
+ pipeline_tag: text2text-generation
3
+ license: apache-2.0
4
+ base_model: facebook/bart-base
5
+ library_name: zeromodels
6
+ tags:
7
+ - keras
8
+ - zeromodels
9
+ - bart
10
+ - text2text-generation
11
+ - seq2seq
12
+ - arxiv:1910.13461
13
+ - pytorch
14
+ - jax
15
+ - tf
16
+ ---
17
+
18
+ # Run BART with Keras 3: JAX, PyTorch, or TensorFlow
19
+
20
+ [![GitHub](https://img.shields.io/badge/GitHub-ZeroModels-black?logo=github)](https://github.com/ZeroAIx/ZeroModels) [![Docs](https://img.shields.io/badge/Docs-BART-blue)](https://zeroaix.github.io/ZeroModels/bart/)
21
+
22
+ # zeromodels/bart_base
23
+
24
+ Paper: [BART: Denoising Sequence-to-Sequence Pre-training for Natural Language Generation, Translation, and Comprehension (arXiv:1910.13461)](https://arxiv.org/abs/1910.13461) · [HF Papers](https://huggingface.co/papers/1910.13461)
25
+
26
+ BART is a denoising seq2seq transformer: a bidirectional encoder (like BERT) and an autoregressive decoder (like GPT) trained to reconstruct corrupted text. It excels at summarization, translation, and other text-to-text tasks. Byte-level BPE tokenizer (shared with RoBERTa); the decoder starts from `</s>`.
27
+
28
+ For more details on the model, please go to the upstream [model card](https://huggingface.co/facebook/bart-base).
29
+
30
+ Pure-**Keras 3** conversion of [`facebook/bart-base`](https://huggingface.co/facebook/bart-base) for [zeromodels](https://github.com/ZeroAIx/ZeroModels). One implementation runs unmodified on **TensorFlow / Torch / JAX**.
31
+
32
+ This is a **conditional generation (base seq2seq)** checkpoint (`BartConditionalGenerate`). Other task heads load the shared backbone from this repo (start randomly initialized, ready for fine-tuning); fine-tuned task checkpoints load via the `hf:` prefix.
33
+
34
+ > Base checkpoint (not task fine-tuned): use it as a backbone (`BartModel`) for features, or fine-tune a task head.
35
+
36
+ ## ✨ Quick start
37
+
38
+ ```python
39
+ import os
40
+ os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
41
+
42
+ from zeromodels.models.bart import BartConditionalGenerate, BartTokenizer
43
+
44
+ model = BartConditionalGenerate.from_weights("zeromodels/bart_base")
45
+ tokenizer = BartTokenizer.from_weights("zeromodels/bart_base")
46
+
47
+ inputs = tokenizer('The quick brown fox jumps over the lazy dog.')
48
+ ids = model.generate(
49
+ inputs,
50
+ [[model.decoder_start_token_id]],
51
+ max_new_tokens=64,
52
+ eos_token_id=tokenizer.eos_token_id,
53
+ )
54
+ print(tokenizer.decode(ids[0], skip_special_tokens=True))
55
+ ```
56
+
57
+ Load any BART variant the same way with `from_weights("zeromodels/<variant>")`:
58
+
59
+ | Variant | Hub | Task |
60
+ |---|---|---|
61
+ | `bart_base` | [`zeromodels/bart_base`](https://huggingface.co/zeromodels/bart_base) | conditional generation (base seq2seq) |
62
+ | `bart_large` | [`zeromodels/bart_large`](https://huggingface.co/zeromodels/bart_large) | conditional generation (base seq2seq) |
63
+ | `bart_large_cnn` | [`zeromodels/bart_large_cnn`](https://huggingface.co/zeromodels/bart_large_cnn) | summarization (CNN / DailyMail) |
64
+ | `bart_large_xsum` | [`zeromodels/bart_large_xsum`](https://huggingface.co/zeromodels/bart_large_xsum) | extreme summarization (XSum, one-sentence) |
65
+
66
+ ## Available classes
67
+
68
+ Load any of these from this repo with `from_weights("zeromodels/bart_base")` (or on the fly via the `hf:` prefix). The pretrained backbone is shared; task heads not stored in this checkpoint start randomly initialized, ready for fine-tuning (or load a `hf:` fine-tune).
69
+
70
+ | Class | Task |
71
+ |---|---|
72
+ | `BartModel` | Encoder-decoder backbone |
73
+ | `BartConditionalGenerate` | Conditional generation (summarization / seq2seq) |
74
+ | `BartSequenceClassify` | Sequence classification (e.g. NLI / zero-shot) |
75
+ | `BartQnA` | Extractive question answering |
76
+
77
+ ```python
78
+ from zeromodels.models.bart import BartSequenceClassify
79
+ # zero-shot / NLI fine-tune loads on the fly via the hf: prefix
80
+ model = BartSequenceClassify.from_weights("hf:facebook/bart-large-mnli")
81
+ ```
82
+
83
+ ## Tips
84
+
85
+ - Set `KERAS_BACKEND` **before** importing Keras / zeromodels.
86
+ - Prefer `BartTokenizer.from_weights(...)` so the byte-level BPE matches.
87
+ - BART's decoder starts from `</s>` (`decoder_start_token_id = 2`); pass `eos_token_id=tokenizer.eos_token_id` to stop generation.
88
+ - See the [BART docs](https://zeroaix.github.io/ZeroModels/bart/) and [Loading Weights](https://zeroaix.github.io/ZeroModels/loading_weights/).
89
+ - Community / upstream safetensors still work via the `hf:` prefix, e.g. `BartConditionalGenerate.from_weights("hf:facebook/bart-base")`.
90
+
91
+ ## Special Thanks
92
+
93
+ A huge thank you to the Meta AI (FAIR) authors for creating and releasing BART.
94
+
95
+ License: apache-2.0.
model.weights.h5 ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ version https://git-lfs.github.com/spec/v1
2
+ oid sha256:e1e0d593fb453ef1ca3b062584479977e10f4581fa2ad9ade33d76ccb3c2173f
3
+ size 558301332
tokenizer.json ADDED
The diff for this file is too large to render. See raw diff
 
zm_config.json ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "library_name": "zeromodels",
3
+ "zeromodels_version": "1.3.0",
4
+ "model_module": "zeromodels.models.bart",
5
+ "model_class": "BartConditionalGenerate",
6
+ "variant": "bart_base",
7
+ "weights": "model.weights.h5",
8
+ "schema_version": 2,
9
+ "model_type": "bart",
10
+ "text_config": {
11
+ "vocab_size": 50265,
12
+ "hidden_dim": 768,
13
+ "encoder_num_layers": 6,
14
+ "decoder_num_layers": 6,
15
+ "encoder_attention_heads": 12,
16
+ "decoder_attention_heads": 12,
17
+ "encoder_ffn_dim": 3072,
18
+ "decoder_ffn_dim": 3072,
19
+ "max_position_embeddings": 1024,
20
+ "activation_function": "gelu",
21
+ "scale_embedding": false,
22
+ "layer_norm_eps": 1e-05,
23
+ "classifier_dropout": 0.0,
24
+ "num_labels": 3,
25
+ "pad_token_id": 1,
26
+ "bos_token_id": 0,
27
+ "eos_token_id": 2,
28
+ "decoder_start_token_id": 2
29
+ },
30
+ "generate_args": {
31
+ "max_new_tokens": 64
32
+ }
33
+ }