Instructions to use zeromodels/bart_large_xsum with libraries, inference providers, notebooks, and local apps. Follow these links to get started.
- Libraries
- ZeroModels
How to use zeromodels/bart_large_xsum with ZeroModels:
# pip install -U zeromodels # ZeroModels is pure Keras 3, so pick a backend: "jax", "torch" or "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" from zeromodels import AutoZModel # AutoZModel reads the repo's model_type and loads the matching class. # For a task head use the matching loader, e.g. AutoZMImageClassify / AutoZMDetect / # AutoZMSemanticSegment / AutoZMTextGenerate (see zeromodels.auto). model = AutoZModel.from_weights("zeromodels/bart_large_xsum") - Keras
How to use zeromodels/bart_large_xsum with Keras:
# Available backend options are: "jax", "torch", "tensorflow". import os os.environ["KERAS_BACKEND"] = "jax" import keras model = keras.saving.load_model("hf://zeromodels/bart_large_xsum") - Notebooks
- Google Colab
- Kaggle
Add bart_large_xsum (zeromodels Keras 3 conversion)
Browse files- README.md +92 -0
- model.weights.h5 +3 -0
- tokenizer.json +0 -0
- zm_config.json +33 -0
README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
---
|
| 2 |
+
pipeline_tag: summarization
|
| 3 |
+
license: mit
|
| 4 |
+
base_model: facebook/bart-large-xsum
|
| 5 |
+
library_name: zeromodels
|
| 6 |
+
tags:
|
| 7 |
+
- keras
|
| 8 |
+
- zeromodels
|
| 9 |
+
- bart
|
| 10 |
+
- summarization
|
| 11 |
+
- arxiv:1910.13461
|
| 12 |
+
- pytorch
|
| 13 |
+
- jax
|
| 14 |
+
- tf
|
| 15 |
+
---
|
| 16 |
+
|
| 17 |
+
# Run BART with Keras 3: JAX, PyTorch, or TensorFlow
|
| 18 |
+
|
| 19 |
+
[](https://github.com/ZeroAIx/ZeroModels) [](https://zeroaix.github.io/ZeroModels/bart/)
|
| 20 |
+
|
| 21 |
+
# zeromodels/bart_large_xsum
|
| 22 |
+
|
| 23 |
+
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)
|
| 24 |
+
|
| 25 |
+
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>`.
|
| 26 |
+
|
| 27 |
+
For more details on the model, please go to the upstream [model card](https://huggingface.co/facebook/bart-large-xsum).
|
| 28 |
+
|
| 29 |
+
Pure-**Keras 3** conversion of [`facebook/bart-large-xsum`](https://huggingface.co/facebook/bart-large-xsum) for [zeromodels](https://github.com/ZeroAIx/ZeroModels). One implementation runs unmodified on **TensorFlow / Torch / JAX**.
|
| 30 |
+
|
| 31 |
+
This is a **extreme summarization (XSum, one-sentence)** 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.
|
| 32 |
+
|
| 33 |
+
## ✨ Quick start
|
| 34 |
+
|
| 35 |
+
```python
|
| 36 |
+
import os
|
| 37 |
+
os.environ["KERAS_BACKEND"] = "torch" # or "jax" / "tensorflow"
|
| 38 |
+
|
| 39 |
+
from zeromodels.models.bart import BartConditionalGenerate, BartTokenizer
|
| 40 |
+
|
| 41 |
+
model = BartConditionalGenerate.from_weights("zeromodels/bart_large_xsum")
|
| 42 |
+
tokenizer = BartTokenizer.from_weights("zeromodels/bart_large_xsum")
|
| 43 |
+
|
| 44 |
+
inputs = tokenizer('The tower is 324 metres tall, about the same height as an 81-storey building, and the tallest structure in Paris.')
|
| 45 |
+
ids = model.generate(
|
| 46 |
+
inputs,
|
| 47 |
+
[[model.decoder_start_token_id]],
|
| 48 |
+
max_new_tokens=64,
|
| 49 |
+
eos_token_id=tokenizer.eos_token_id,
|
| 50 |
+
)
|
| 51 |
+
print(tokenizer.decode(ids[0], skip_special_tokens=True))
|
| 52 |
+
```
|
| 53 |
+
|
| 54 |
+
Load any BART variant the same way with `from_weights("zeromodels/<variant>")`:
|
| 55 |
+
|
| 56 |
+
| Variant | Hub | Task |
|
| 57 |
+
|---|---|---|
|
| 58 |
+
| `bart_base` | [`zeromodels/bart_base`](https://huggingface.co/zeromodels/bart_base) | conditional generation (base seq2seq) |
|
| 59 |
+
| `bart_large` | [`zeromodels/bart_large`](https://huggingface.co/zeromodels/bart_large) | conditional generation (base seq2seq) |
|
| 60 |
+
| `bart_large_cnn` | [`zeromodels/bart_large_cnn`](https://huggingface.co/zeromodels/bart_large_cnn) | summarization (CNN / DailyMail) |
|
| 61 |
+
| `bart_large_xsum` | [`zeromodels/bart_large_xsum`](https://huggingface.co/zeromodels/bart_large_xsum) | extreme summarization (XSum, one-sentence) |
|
| 62 |
+
|
| 63 |
+
## Available classes
|
| 64 |
+
|
| 65 |
+
Load any of these from this repo with `from_weights("zeromodels/bart_large_xsum")` (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).
|
| 66 |
+
|
| 67 |
+
| Class | Task |
|
| 68 |
+
|---|---|
|
| 69 |
+
| `BartModel` | Encoder-decoder backbone |
|
| 70 |
+
| `BartConditionalGenerate` | Conditional generation (summarization / seq2seq) |
|
| 71 |
+
| `BartSequenceClassify` | Sequence classification (e.g. NLI / zero-shot) |
|
| 72 |
+
| `BartQnA` | Extractive question answering |
|
| 73 |
+
|
| 74 |
+
```python
|
| 75 |
+
from zeromodels.models.bart import BartSequenceClassify
|
| 76 |
+
# zero-shot / NLI fine-tune loads on the fly via the hf: prefix
|
| 77 |
+
model = BartSequenceClassify.from_weights("hf:facebook/bart-large-mnli")
|
| 78 |
+
```
|
| 79 |
+
|
| 80 |
+
## Tips
|
| 81 |
+
|
| 82 |
+
- Set `KERAS_BACKEND` **before** importing Keras / zeromodels.
|
| 83 |
+
- Prefer `BartTokenizer.from_weights(...)` so the byte-level BPE matches.
|
| 84 |
+
- BART's decoder starts from `</s>` (`decoder_start_token_id = 2`); pass `eos_token_id=tokenizer.eos_token_id` to stop generation.
|
| 85 |
+
- See the [BART docs](https://zeroaix.github.io/ZeroModels/bart/) and [Loading Weights](https://zeroaix.github.io/ZeroModels/loading_weights/).
|
| 86 |
+
- Community / upstream safetensors still work via the `hf:` prefix, e.g. `BartConditionalGenerate.from_weights("hf:facebook/bart-large-xsum")`.
|
| 87 |
+
|
| 88 |
+
## Special Thanks
|
| 89 |
+
|
| 90 |
+
A huge thank you to the Meta AI (FAIR) authors for creating and releasing BART.
|
| 91 |
+
|
| 92 |
+
License: mit.
|
model.weights.h5
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
version https://git-lfs.github.com/spec/v1
|
| 2 |
+
oid sha256:d9d7fcc8473550a909be10c7d5f6e0bcaa7a4e9c08dd9220812fe6ddabb0bc16
|
| 3 |
+
size 1626174800
|
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_large_xsum",
|
| 7 |
+
"weights": "model.weights.h5",
|
| 8 |
+
"schema_version": 2,
|
| 9 |
+
"model_type": "bart",
|
| 10 |
+
"text_config": {
|
| 11 |
+
"vocab_size": 50264,
|
| 12 |
+
"hidden_dim": 1024,
|
| 13 |
+
"encoder_num_layers": 12,
|
| 14 |
+
"decoder_num_layers": 12,
|
| 15 |
+
"encoder_attention_heads": 16,
|
| 16 |
+
"decoder_attention_heads": 16,
|
| 17 |
+
"encoder_ffn_dim": 4096,
|
| 18 |
+
"decoder_ffn_dim": 4096,
|
| 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 |
+
}
|