codewithkyrian/transformers
A Laravel-friendly transformers package for turning models, arrays, and API responses into consistent, reusable output. Define transformer classes, map fields, nest relations, and format data cleanly for JSON APIs, with minimal boilerplate and flexible customization.
Summarization is the process of shortening a set of data computationally, to create a subset (a summary) that represents the most important or relevant information within the original content. This task is particularly beneficial in situations where quick understanding of large volumes of text is required, such as news articles, legal documents, or scientific papers. Models used for summarization can either extract key sentences from the original text ( extraction-based) or generate new text that summarizes the content (abstraction-based).
summarizationXenova/distilbart-cnn-6-6Summarization can be applied in various scenarios, including but not limited to:
Fine-tuned models, in particular, demonstrate remarkable performance by adapting to the nuances of specific domains or styles, thereby providing highly accurate summaries. Eg. CNN fine-tuned models for news articles, etc.
To use the Summarization pipeline, you'll need to provide a piece of text. Here's an example:
use function Codewithkyrian\Transformers\Pipelines\pipeline;
$summarizer = pipeline('summarization', 'Xenova/distilbart-cnn-6-6');
$article = 'The Amazon rainforest, known as the "lungs of the Earth," is the largest tropical rainforest in the world, ' .
'covering over 5.5 million square kilometers. It is home to millions of species of flora and fauna, many of which are ' .
'still undiscovered. The rainforest plays a crucial role in regulating the planet\'s climate by absorbing large ' .
'amounts of carbon dioxide. However, it is under threat from deforestation due to logging, mining, and farming, ' .
'leading to a loss of biodiversity and contributing to global warming. Conservation efforts are underway to protect ' .
'this vital ecosystem, including initiatives to promote sustainable land use and reduce human impact.';
$summary = $summarizer($article, maxNewTokens: 512, temperature: 0.7);
All options available for the standard Text-To-Text generation are also available for the summarization pipeline.
The output is an array where each element corresponds to an input text and contains a key summarized_text with the
generated summary. For a single input text, you'll receive an array containing one element: a string with the summary.
[
"summarized_text" => "The Amazon rainforest is the largest tropical rainforest, crucial for regulating the climate by absorbing CO2. Despite its importance, it faces threats from deforestation, impacting biodiversity and global warming. Conservation efforts are essential for its protection."
]
The number of elements in the output array corresponds to the number of input texts.
How can I help you explore Laravel packages today?