Skip to content

Instantly share code, notes, and snippets.

@pszemraj
Last active August 31, 2023 03:46
Show Gist options
  • Save pszemraj/722a7ba443aa3a671b02d87038375519 to your computer and use it in GitHub Desktop.
Save pszemraj/722a7ba443aa3a671b02d87038375519 to your computer and use it in GitHub Desktop.
Document Summarization Demo - Guide - Draft

Document Summarization Demo - Guide - Draft



tl;dr parameters table

Parameter What It Does Accuracy Speed
Model Name Chooses the summarization model. Different models work better for different texts. Some models are faster than others.
Beam Search Considers multiple summaries at each step. More options can improve the summary. More options slow down the process.
Token Batch Length Processes a set number of words at once. More words can improve the summary. More words slow down the process.
Length Penalty Discourages long summaries. Higher penalty makes summaries shorter. Shorter summaries are faster.
Repetition Penalty Discourages repeating words or phrases. Higher penalty reduces repetition. Doesn't affect speed.
No Repeat Ngram Size Sets a limit on repeating word groups. Higher limit reduces repetition. Doesn't affect speed.
Max Input Length Sets a limit on the length of the input text. Too short can miss important details. Shorter inputs are faster.
Max Pages Sets a limit on the number of pages from a PDF. Too short can miss important details. Fewer pages are faster.

This table is designed to be a quick reference for those new to NLP.


How to Use

This is a guide on how to use the Document Summarization space, which uses pre-trained transformer models to summarize long documents. The space provides an interactive interface for text summarization using the Gradio library.

usage

  1. Input Text: Enter the text you want to summarize in the provided text box. The text will be cleaned and truncated based on spaces. The text can be narrative, academic (both papers and lecture transcription), and article text.

  2. Model Selection: Choose the transformer model you want to use for summarization from the dropdown menu. Different models may have different performance characteristics and may be better suited to different types of text.

  3. Beam Search: Choose the number of beams to use for the beam search strategy. A higher number can lead to better results but also increases computation time.

  4. Token Batch Length: Choose the number of tokens (words or parts of words) that the model processes at once. A larger batch size can slow down processing but may also lead to higher quality results (the model is able to see a larger global context, and 'understand' more)

  5. Length Penalty: Adjust the slider to control how much the model is penalized for producing longer sequences. A higher penalty (which is a decimal number BELOW 1.0, like 0.5) leads to shorter summaries.

  6. Repetition Penalty: Adjust the slider to control how much the model is penalized for repeating the same sequence. A higher penalty reduces repetition in the summary.

  7. No Repeat Ngram Size: Choose the length of the sequence that the model should not repeat. A higher value reduces repetition but may also omit important information if it needs to be repeated.

  8. Summarize: Click the "Summarize!" button to start the summarization process. The summarization should take ~1-2 minutes for most settings, but may extend up to 5-10 minutes in some scenarios.

  9. Output: The summarized text will appear in the "Summary" section. The scores can be thought of as representing the quality of the summary. Less-negative numbers (closer to 0) are better.

  10. Download: You can download the summarized text as a text file by clicking on the "Download as Text File" button.

Additional Features

  • Load Example: You can load an example text to summarize by selecting an example from the dropdown menu and clicking the "Load Example in Dropdown" button.

  • Upload File: You can upload a text file (.txt, .md) or a PDF document to summarize by clicking the "Load an Uploaded File" button. See the below image for details

byod

Note

The quality of the summarization and the runtime can be significantly impacted by the choice of parameters. It may take some experimentation to find the best settings for your specific use case.

Models

  1. pszemraj/long-t5-tglobal-base-16384-book-summary: This model is trained on the BookSum dataset. It is designed to summarize long-form narrative texts such as novels, plays, and stories. The model is capable of handling very long documents and understanding non-trivial causal and temporal dependencies, as well as rich discourse structures.

  2. pszemraj/long-t5-tglobal-base-sci-simplify: This model is trained on the Lay Summaries dataset (PLOS subset). It is designed to summarize and simplify scientific literature, making it more comprehensible to non-experts. The model is capable of handling biomedical journal articles and producing summaries that are more readable and understandable for a general audience.

  3. pszemraj/long-t5-tglobal-base-sci-simplify-elife: This model is also trained on the Lay Summaries dataset, specifically the eLife subset. Similar to the previous model, it is designed to summarize and simplify scientific literature. However, it might be more specialized in handling eLife biomedical journal articles.

  4. pszemraj/long-t5-tglobal-base-16384-booksci-summary-v1: This model is trained on a combination of the BookSum and Lay Summaries datasets. It is designed to handle both long-form narrative texts and scientific literature. This model could be useful for summarizing a wide range of documents, from novels to scientific articles.

  • this is an initial test, open to feedback.
  1. pszemraj/pegasus-x-large-book-summary: This model is trained on the BookSum dataset. It uses the Pegasus-X architecture, which is designed for abstractive text summarization. This model is capable of summarizing long-form narrative texts such as novels, plays, and stories.

Parameters

Here's a layman's guide to the parameters/options in the script and how they impact quality and runtime:

  1. Model Name: This is the name of the pre-trained transformer model used for summarization. Different models may have different performance characteristics and may be better suited to different types of text. The choice of model can significantly impact both the quality of the summarization and the runtime.

  2. Beam Search: This is a search strategy used in machine learning to improve the quality of output. It controls the number of alternative sequences at each step that the model considers. A higher number can lead to better results but also increases computation time.

  3. Token Batch Length: This is the number of tokens (words or parts of words) that the model processes at once. A larger batch size can slow down processing but may also lead to higher quality results (the model is able to see a larger global context, and 'understand' more)

  4. Length Penalty: This parameter controls how much the model is penalized for producing longer sequences. A higher penalty (which is a decimal number BELOW 1.0, like 0.5) leads to shorter summaries.

  5. Repetition Penalty: This parameter controls how much the model is penalized for repeating the same sequence. A higher penalty reduces repetition in the summary.

  6. No Repeat Ngram Size: This parameter specifies the length of the sequence that the model should not repeat. A higher value reduces repetition but may also omit important information if it needs to be repeated.

  7. Max Input Length: This is the maximum number of words from the input text that the model will consider. If the input text is longer than this, it will be truncated. This can significantly impact both the quality of the summarization and the runtime.

  • you cannot directly adjust this parameter in the space itself, but can be set with an environmental variable should you duplicate the space.
  1. Max Pages: This is the maximum number of pages to load from a PDF document. This can significantly impact both the quality of the summarization and the runtime.
  • you cannot directly adjust this parameter in the space itself, but can be set with an environmental variable should you duplicate the space.

Remember, the quality of the summarization and the runtime can be significantly impacted by the choice of parameters. It may take some experimentation to find the best settings for your specific use case.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment