How to import gensim summarize

I got gensim to work in Google Collab by following this process:

!pip install gensim
from gensim.summarization import summarize

Then I was able to call summarize(some_text)

Now I'm trying to run the same thing in VS code:

I've installed gensim:pip3 install gensim

but when I run

from gensim.summarization import summarize

I get the error

Import "gensim.summarization" could not be resolvedPylancereportMissingImports

I've also tried from gensim.summarization.summarizer import summarize with same error. Regardless I haven't been able to call the function summarize(some_text) outside of Google Collab.

1

2 Answers

The summarization code was removed from Gensim 4.0. See:

12. Removed gensim.summarization

Despite its general-sounding name, the module will not satisfy the majority of use cases in production and is likely to waste people's time. See this Github ticket for more motivation behind this.

If you need it, you could try:

  • installing an older gensim version (such as 3.8.3, the last official release in which it remained); or…
  • copy the source code out to your own local module

However, I expect you'd likely be disappointed by its inflexibility and how little it can do.

It was only extractive summarization - choosing a few key sentences from those that already exist. That only gives impressive results when the source text was already well-written in an expository style mixing high-level overview sentences with separate detail sentences. And, its method of analyzing/ranking words was very crude & hard-to-customize – totally unconnected to the more generic/configurable/swappable approaches used elsewhere in Gensim or in other text libraries.

So I had to download specifically

pip3 install gensim==3.6.0

I was using gensim==4.1.0 and this function no longer seems to work in this later version

6

Your Answer

Sign up or log in

Sign up using Google Sign up using Facebook Sign up using Email and Password

Post as a guest

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

You Might Also Like