distilbart-cnn-12-6 for Kjarni
Summaries of English news-style text, packaged to run locally with Kjarni: one native library, with no Python runtime, server or cloud service. It is a distilled BART trained on CNN and Daily Mail articles, and it writes summaries of a few sentences, mostly by choosing and shortening sentences from the input. The model is about 1.2 GB and downloads on first use.
Usage
Tested with Kjarni 0.8.2. In Kjarni the model is called distilbart-cnn, and it is the
default summarisation model.
Command line
curl -fsSL https://kjarni.ai/install.sh | sh # Windows: irm https://kjarni.ai/install.ps1 | iex
kjarni summarize -q -m distilbart-cnn < article.txt
Python
# pip install kjarni
from kjarni import Summarizer
article = (
"The city council voted on Tuesday to turn the old railway yard into a public park. "
"The site, closed since 1998, covers twelve hectares near the river. Work will start next "
"spring and the first section, with a playground and a cycle path, should open in 2028. "
"The plan also keeps two of the original engine sheds, which will become a market hall and "
"a space for local clubs. Some residents had asked for housing on the site instead, and the "
"council said it would look for other land for new homes. The project will cost about "
"40 million euros, with a quarter coming from a national fund for green spaces."
)
summarizer = Summarizer(model="distilbart-cnn", quiet=True)
print(summarizer.summarize(article))
The site, closed since 1998, covers twelve hectares near the river . Work will start next spring and the first section should open in 2028 . The project will cost about 40 million euros, with a quarter coming from a national fund for green spaces . The plan also keeps two of the original engine sheds, which will become a market hall and space for local clubs .
The space before each full stop comes from the CNN and Daily Mail training data. The original model writes it too.
Rust
// cargo add kjarni anyhow tokio --features tokio/full
use kjarni::Summarizer;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let article =
"The city council voted on Tuesday to turn the old railway yard into a public park. \
The site, closed since 1998, covers twelve hectares near the river. Work will start next \
spring and the first section, with a playground and a cycle path, should open in 2028. \
The plan also keeps two of the original engine sheds, which will become a market hall and \
a space for local clubs. Some residents had asked for housing on the site instead, and the \
council said it would look for other land for new homes. The project will cost about \
40 million euros, with a quarter coming from a national fund for green spaces.";
let summarizer = Summarizer::new("distilbart-cnn").await?;
println!("{}", summarizer.summarize(article).await?);
Ok(())
}
C#
// dotnet add package Kjarni
using Kjarni;
var article =
"The city council voted on Tuesday to turn the old railway yard into a public park. " +
"The site, closed since 1998, covers twelve hectares near the river. Work will start next " +
"spring and the first section, with a playground and a cycle path, should open in 2028. " +
"The plan also keeps two of the original engine sheds, which will become a market hall and " +
"a space for local clubs. Some residents had asked for housing on the site instead, and the " +
"council said it would look for other land for new homes. The project will cost about " +
"40 million euros, with a quarter coming from a national fund for green spaces.";
using var summarizer = new Summarizer("distilbart-cnn", quiet: true);
Console.WriteLine(summarizer.Summarize(article));
C++ (C++23)
#include <kjarni.hpp>
#include <iostream>
int main() {
kjarni::SummarizerOptions options;
options.model = "distilbart-cnn";
auto summarizer = kjarni::Summarizer::create(options);
if (!summarizer) return 1;
auto summary = summarizer->summarize(
"The city council voted on Tuesday to turn the old railway yard into a public park. "
"The site, closed since 1998, covers twelve hectares near the river. Work will start next "
"spring and the first section, with a playground and a cycle path, should open in 2028. "
"The plan also keeps two of the original engine sheds, which will become a market hall and "
"a space for local clubs. Some residents had asked for housing on the site instead, and the "
"council said it would look for other land for new homes. The project will cost about "
"40 million euros, with a quarter coming from a national fund for green spaces.");
if (!summary) return 1;
std::cout << *summary << "\n";
}
Go
// go get github.com/kjarni-ai/kjarni-go
package main
import (
"fmt"
"log"
kjarni "github.com/kjarni-ai/kjarni-go"
)
const article = "The city council voted on Tuesday to turn the old railway yard into a public park. " +
"The site, closed since 1998, covers twelve hectares near the river. Work will start next " +
"spring and the first section, with a playground and a cycle path, should open in 2028. " +
"The plan also keeps two of the original engine sheds, which will become a market hall and " +
"a space for local clubs. Some residents had asked for housing on the site instead, and the " +
"council said it would look for other land for new homes. The project will cost about " +
"40 million euros, with a quarter coming from a national fund for green spaces."
func main() {
summarizer, err := kjarni.NewSummarizer("distilbart-cnn", kjarni.WithQuiet(true))
if err != nil {
log.Fatal(err)
}
defer summarizer.Close()
summary, err := summarizer.Summarize(article)
if err != nil {
log.Fatal(err)
}
fmt.Println(summary)
}
See the Kjarni documentation for other languages and installation details.
What changed from the original
This is not a new model. The weights are unchanged: every tensor is bit-for-bit the
same as in the original's pytorch_model.bin. Only the packaging differs:
- The weights are stored as safetensors, with the shared embedding kept once rather than three times.
- A
tokenizer.jsonis added, made from the original'svocab.jsonandmerges.txt. - The beam search settings (4 beams, length penalty 2.0, 56 to 142 tokens, no repeated
trigrams) moved from
config.jsontogeneration_config.json, where current transformers reads them. The values are the original's.
The files also load in transformers. On the example above, Kjarni's summary is word for word the one transformers writes with the original model.
Accuracy
From the original model card:
| Model | Parameters | ROUGE-2 | ROUGE-L |
|---|---|---|---|
| distilbart-cnn-12-6 | 306M | 21.26 | 30.59 |
| bart-large-cnn | 406M | 21.06 | 30.63 |
Attribution
The model is sshleifer/distilbart-cnn-12-6, by Sam Shleifer and Alexander M. Rush, distilled from Facebook AI's bart-large-cnn. All credit for the model, its training and its evaluation belongs to them. See the original model card for more.
Kjarni and this packaging are not affiliated with or endorsed by the authors or Meta.
This repository is released under the Apache License 2.0, the same license as the original model.
Citation
@misc{shleifer2020pretrained,
title={Pre-trained Summarization Distillation},
author={Sam Shleifer and Alexander M. Rush},
year={2020},
eprint={2010.13002},
archivePrefix={arXiv},
primaryClass={cs.CL}
}