---
slug: /use-cases/summarizer
sidebar_position: 2
---

# Summarizer

In Therix, the "Summarizer" topic serves as a fundamental component designed to condense lengthy texts into concise summaries. This versatile tool streamlines information retrieval and aids in comprehension across various applications.

Within the realm of the Summarizer topic, we delve into two distinct methodologies: "Extractive" and "Abstractive" summarization techniques. These approaches cater to different use cases and preferences, offering flexibility and precision in summarization tasks.

**Steps to follow:**

Import Necessary Modules: Begin by importing the required modules for configuring the Summarizer.

```
from therix.summarizer import SummarizerConfig, SummarizerTypeMaster
from your_model_module import TopicModel  # Import your Pydantic model if needed
```

Instantiate SummarizerConfig:

Create an instance of the SummarizerConfig class by specifying the type of summarizer and, optionally, the Pydantic model for structuring the JSON output.

**For Extractive Summarizer with custom Pydantic model**
```
summarizer_config = SummarizerConfig(SummarizerTypeMaster.EXTRACTIVE.value, TopicModel)
```

**For Abstractive Summarizer**
```
summarizer_config = SummarizerConfig(SummarizerTypeMaster.ABSTRACTIVE.value)
```

Add Summarizer Configuration to Pipeline: Use the .add() method to add the SummarizerConfig to your Therix pipeline.

```
pipeline.add(summarizer_config)
```

# Example

```
pipeline = Pipeline(name="Summarizer Pipeline")
    (pipeline
    .add(SummarizerConfig(SummarizerTypeMaster.EXTRACTIVE.value,TopicModel))
    .add(// Any other configuration you want to add)
    .save())

    pipeline.publish()
    print(pipeline.id)
    ans = pipeline.invoke(text,'SUMMARIZER')
```

By following these steps and adjusting the parameters as needed, you can seamlessly integrate the Summarizer into your Therix pipeline. Whether you require Extractive or Abstractive summarization, with or without a custom Pydantic model, Therix provides the flexibility and functionality to meet your summarization needs effectively.

# Summarizer - Extractive

In the Extractive Summarizer type of Therix, the primary goal is to distill the essence of a given text into a JSON format while maintaining the integrity of the original content. This process involves selecting key sentences or phrases from the input text that encapsulate its main ideas and conveying them in a structured JSON representation. 

When utilizing the Extractive Summarizer without specifying a Pydantic model, the system employs an internal logic to generate a JSON structure suitable for the content. This structure aims to organize the extracted information in a coherent manner, ensuring that the resulting JSON format provides a concise yet informative summary of the input text.

However, users also have the option to supply a Pydantic model to customize the structure of the extracted information according to their specific requirements. By providing a Pydantic model, users can define the fields and data types they wish to include in the JSON output, allowing for greater flexibility and control over the summarization process.

Whether utilizing the default JSON structure generated by the Extractive Summarizer or supplying a custom Pydantic model, the end result is a well-organized and informative summary in JSON format that captures the key elements of the input text. This capability enables users to easily extract valuable insights from large volumes of text data, facilitating decision-making and information retrieval across various domains.

# Summarizer - Abtractive

Abstractive Summarization in Therix is a sophisticated technique that simplifies text into concise summaries. Unlike Extractive Summarization, which rearranges existing content, Abstractive Summarization goes a step further. It understands the input text deeply, grasping its meaning, context, and core ideas. By doing so, it generates original summaries that capture the essence of the text in a new way. This method allows for creativity in summarizing, providing summaries that are not limited by the original text's structure. Abstractive Summarization is valuable for distilling complex information into easy-to-understand summaries, making it useful for decision-making and knowledge sharing in various fields.
