Closed gaurav-95 closed 2 years ago
Hi, most of the pretrained models (e.g. BART here) have a maximum input length limit and they could not handle inputs longer than that limit. For example, the max input length for BART is 1024, and you simply need to truncate your input before feeding it to BART:
data = tokenizer(text, truncation=True, max_length=1024, return_tensors="pt")
Summarizing long documents is difficult and still an open research problem.
Thank you for the reply. It seems to have solved the problem. Closing the question, sorry for the delay!
Hello, I am trying to summarize longer documents. Despite using the huggingface version where I can control the output length using min_len and max_len parameters. I get an error when using longer text inputs.
Error
Code
I am running the code on a colab instance. I am also removing the tags using regex.
Appreciate any help with this.
Example input: "This month, Hong Kong saw its Covid-19 death rate become the highest in the world, topping 37 deaths per million people. The recent outbreak was a brutal shock to the 7.4 million residents of the bustling metropolis, which had until recently kept Covid-19 cases to admirably low levels. Hong Kong was once applauded for its response to Covid-19. Then it became the global epicenter of the pandemic. Other cities in China like Shenzhen and Shanghai have also seen huge surges in infections, and countries in the Eastern Pacific like South Korea, Vietnam, Singapore, and Australia have seen a surge in cases this month as well. That’s largely due to the rise of BA.2, a highly infectious, hard to identify subvariant of omicron, itself a more transmissible version of the virus that causes Covid-19. Some of these countries also started to relax restrictions on travel and public gatherings just as the new subvariant took root. But a towering spike in cases doesn’t necessarily mean that hospitalizations and deaths will see a similar jump. In South Korea, even while reaching a new daily record of 470 Covid-19 deaths in March, the death rate so far has been 6 per million residents. So Hong Kong stands out because its latest Covid-19 wave was especially deadly. Fortunately, cases and deaths are on the decline. But it’s worth asking: Why did the latest Covid-19 wave hit Hong Kong so hard? To find out, I spoke with Dr. Kelvin To, a clinical associate professor of microbiology at the University of Hong Kong. He’s both a researcher studying Covid-19 and a physician at Queen Mary Hospital who treats patients. To explained that residents took some of Hong Kong’s earlier successes for granted, making them complacent in critical public health measures, like vaccinating people at high risk of severe disease. The conversation has been edited for length and clarity. Umair Irfan What are the factors right now that seem to be the most significant for Hong Kong’s Covid-19 outbreak? Why are we seeing it now? What variables should we be paying attention to? Kelvin To I think the most important is the vaccination problem in Hong Kong, the extremely low vaccination rates among the elderly, especially those older than 80 years old. The vaccination rate for them was only about 20 percent by the end of 2021. That’s the most vulnerable population, and they’re not protected at all. The data from our pandemic on this wave is very clear: Those elderly who were not vaccinated actually had a much, much higher, death rate than those with the vaccination. Another reason is the incidence of infection in Hong Kong was so low in the past. By the end of 2021, we had about 12,000 cases out of 7.3 million people in Hong Kong, which is less than 0.2 percent. So basically in Hong Kong, very, very few people have natural immunity against the virus. Third, in the past waves, you got about a hundred or so cases in a day, and that’s already a lot. But in those days with only a hundred cases, you can actually put everybody in the hospital, in isolation, in quarantine camps. But when they are not hundreds but thousands of cases per day, then people can only be quarantined at home. And, you know, Hong Kong is very crowded. Basically most people live in apartments and many of them live in very, very small apartments. Unfortunately, there are many poor people who actually share a flat with many other people. So this space is kind of impossible for you to do any preventive measures in those settings. And of course, the virus this time is very different. In the past, we in Hong Kong see the virus, we see infections, and then we isolate people. Usually, the spread is very limited once you do that. But this time, especially at the beginning of the omicron wave, when we still had very, very few cases, we did a lot of investigations into each of the clusters. You can see that in a restaurant, an infected patient sitting in one corner of the restaurant and another customer sitting at the other end of the restaurant got infected. It’s not just spreading to people around you, but can actually spread over long distances. For example, there are cases in apartment buildings. And what people have found is that spread is not because of direct contact between neighbors but because infected air that got removed from a flat from an exhaust fan can go up through the air to the other apartments. Umair Irfan Given all those factors, was this preventable? Kelvin To If Hong Kong was much, much better vaccinated, then I believe this wave could’ve been prevented. In Hong Kong, the vaccination campaign was very aggressive. Almost every day, you heard on the news that you should get vaccinated. And the government is doing as much as they can to get people vaccines. They tried to have vaccine passes before you can go to certain restaurants, and things like that. But the problem is some people just don’t want to get vaccinated, or worse, they don’t want their elderly parents to get vaccinated. The reason is because they thought — and many are still thinking — that the Covid-19 vaccine is very dangerous. Another reason that people in Hong Kong don’t want to get vaccinated is they believe they won’t get the infection because the incidence of Covid-19 was so low in the past. So they thought, okay, if I stay indoors, I don’t go out, I always wear protection, then I won’t get infected. This is something that happens when you’re doing too well, in some ways, so people think it’s not important to get vaccinated. Umair Irfan Hong Kong is not the only place seeing an outbreak in China. There are outbreaks in Shenzhen and Shanghai. I’m wondering how distinct is Hong Kong’s outbreak, or what does it have in common with these other major cities? Kelvin To The major difference in Shenzhen or Shanghai is that they still have sufficient facilities to isolate or quarantine people. They also locked down the cities very early. They had PCR tests for the whole population, we’re talking about millions of people. Basically they could do a massive screening for the whole city in a short period of time. They isolated everyone who was infected very quickly. That’s why they were able to really stop it within a week. Of course, Shenzhen is much bigger than Hong Kong and not as crowded. Umair Irfan What does this mean for China’s zero-Covid strategy? Kelvin To It’s not really an absolute zero policy. The Chinese government calls it dynamic zero. What they mean is you try to catch it early and then try to stop it from spreading. It sort of worked well in that the Chinese economy and people are living quite normally. But of course, you cannot shut down from the rest of the world forever. It’s a question of timing of when to start to relax. If you suddenly open up now, then a lot of cities in China can just become like Hong Kong and suddenly the health care system can collapse in a matter of weeks. So a full opening-up is very dangerous right now. When to open up depends on a lot of things. And I think the most important is the vaccination rate and the availability of effective Covid-19 drugs. Umair Irfan What do you make of how the leadership in Hong Kong is handling this? How could they improve? Kelvin To I think there are obviously things that can be improved. For example, I think the government should review what has happened in this wave. Was there any moment that more aggressive measures could’ve been taken in the beginning, especially in the middle of February? Secondly, there should be better coordination in terms of quarantining or isolating people. You can never have enough place to isolate everyone in Hong Kong. It’s impossible. But at least the government should have plans for how to convert existing places into isolation facilities more quickly. Umair Irfan For those of us watching from the outside, what lessons do you think we should take away? Kelvin To In Hong Kong, people didn’t believe it would occur. People did not believe the health care system would collapse. The government had some plans, but they probably didn’t anticipate that it would collapse the way that it did in Hong Kong. For the rest of the world, no matter how good it is right now in terms of the pandemic, I can only say that Covid can just catch you by surprise. Omicron this time is fortunate in a way that it is milder than previous variants. But you never know, you may have a variant that is as transmissible or more transmissible than omicron, or even more severe than the previous strains. I think people around the world should not expect that you can just think it’s gone. I’m not saying that people should be scared, but at least there should be some kind of preparedness plan. The window of opportunity to stop an outbreak is very, very narrow. Once the health care system collapsed, everything is just like a domino effect. Umair Irfan How are you, your family, and your colleagues holding up through all this? Kelvin To We are okay. Of course, we lost our social life. I haven’t eaten out for a long, long time and I haven’t seen a lot of friends. One good thing about being a doctor is that I still have to go to work every day, just like normal life, but even more busy. For me, there’s still some social interactions at work, which I prefer. I myself do not like work from home because I prefer real face-to-face social interaction. I would say I’m very lucky. I’m a doctor and I didn’t lose my job. Many people in Hong Kong have, because of all the restrictions, basically lost their income. This wave has taken a toll on them, definitely."