Search code examples
pythonpipelinehuggingface-transformerstransformer-model

How to use pipeline from transformers, summarization? Python


I am trying to use pipeline from transformers to summarize the text. But what I can get is only truncated text from original one. My code is:

from transformers import pipeline
summarizer = pipeline("summarization")
summarizer("The present invention discloses a pharmaceutical composition comprising therapeutically effective amount of, or an extract consisting essentially therapeutically effective amount of at least one cannabinoid selected from the group consisting of: Cannabidiol (CBD) or a derivative thereof, Tetrahydrocannabinol (THC) or a derivative thereof, and any combination thereof, for use in the treatment of multiple myeloma (MM). The present invention further discloses methods and uses of the aforementioned composition.", 
       min_length=5, max_length=10)

The output is

[{'summary_text': ' The present invention discloses a pharmaceutical'}]

That is just a beginning of the text for analysis. What I am doing wrong?


Solution

  • You gave as an argument max_length=10, meaning that the maximum length of the generated text should be no longer than 10 tokens. By increasing this number, the generated summaries will get longer.