sparknlp.annotator.seq2seq.summarization#
Contains classes for the Summarization annotator.
Module Contents#
Classes#
High-level, task-oriented document summarization. |
|
Fitted model produced by |
- class Summarization[source]#
High-level, task-oriented document summarization.
Summarizationis a zero-configuration estimator: state what you want (summary length, style, focus) and the annotator decides how to produce it (model selection, prompting, generation settings, long-document handling). No prompt writing or model choice is required:>>> summarizer = Summarization() \ ... .setInputCols(["document"]) \ ... .setOutputCol("summary")
fit()downloads the default (or user-overridden) pretrained model and returns aSummarizationModel.Three methods are supported, each with an automatically selected default model:
llm(default): an instruction-tuned GGUF LLM run with llama.cpp; the annotator owns the summarization prompt, system prompt, safe generation defaults and reasoning-mode suppression.encoder_decoder: a specialized abstractive summarization model (DistilBART fine-tuned on XSum).extractive: selects the most central sentences from the original document using sentence embeddings, position-augmented centrality and MMR redundancy control.
Documents longer than the model context are chunked at sentence boundaries, summarized per chunk, and the intermediate summaries are combined and summarized again (see
setLongDocumentStrategy).Input Annotation types
Output Annotation type
DOCUMENTDOCUMENTExamples
>>> import sparknlp >>> from sparknlp.base import * >>> from sparknlp.annotator import * >>> from pyspark.ml import Pipeline >>> documentAssembler = DocumentAssembler() \ ... .setInputCol("text") \ ... .setOutputCol("document") >>> summarizer = Summarization() \ ... .setInputCols(["document"]) \ ... .setOutputCol("summary") \ ... .setMethod("extractive") \ ... .setMaxSummaryLength(100) >>> pipeline = Pipeline().setStages([documentAssembler, summarizer]) >>> data = spark.createDataFrame([["Long document text ..."]]).toDF("text") >>> result = pipeline.fit(data).transform(data) >>> result.select("summary.result").show(truncate=False)
- class SummarizationModel(classname='com.johnsnowlabs.nlp.annotators.seq2seq.SummarizationModel', java_model=None)[source]#
Fitted model produced by
Summarization.Orchestrates the resolved summarization delegate: prompt building, long-document chunking, delegate inference, output cleanup and transparency metadata (method, model, engine, token estimates, chunk count) on each output annotation.
Saving this model persists the delegate (model weights included), so fitted pipelines reload without network access.
Input Annotation types
Output Annotation type
DOCUMENTDOCUMENT