L1_NLP_tasks_with_a_simple_interface error

from transformers import pipeline

get_completion = pipeline("summarization", model="sshleifer/distilbart-cnn-12-6")

def summarize(input):
    output = get_completion(input)
    return output[0]['summary_text']

Thanks for you guys. I’ve modified my code above. But I’ve been faced with the error below. Why ValueError occurs? Thanks!

----> 4 get_completion = pipeline(“summarization”, model=“sshleifer/distilbart-cnn-12-6”, use_auth_token=hf_api_key)
ValueError(f"Could not load model {model} with any of the following classes: {class_tuple}.") 279 280 if framework is None: ValueError: Could not load model sshleifer/distilbart-cnn-12-6 with any of the following classes: (, ).

I don’t know what is wrong with that code you’ve shared. Here’s one that works locally after pip install 'transformers[torch]'

>>> from transformers import pipeline
>>> p = pipeline('summarization', model='sshleifer/distilbart-cnn-12-6')
Downloading (…)lve/main/config.json: 100%|███████████████████████| 1.80k/1.80k [00:00<00:00, 3.23MB/s]
Downloading pytorch_model.bin: 100%|█████████████████████████████| 1.22G/1.22G [03:23<00:00, 6.01MB/s]
Downloading (…)okenizer_config.json: 100%|███████████████████████████████████████████████████████| 26.0/26.0 [00:00<00:00, 74.7kB/s]
Downloading (…)olve/main/vocab.json: 100%|███████████████████████████████████████████████████████| 899k/899k [00:00<00:00, 1.22MB/s]
Downloading (…)olve/main/merges.txt: 100%|███████████████████████████████████████████████████████| 456k/456k [00:00<00:00, 7.90MB/s]
# create content
>>> content
'Scientists believe that sea creatures could lead investigators to the wreck of the Malaysia Airlines flight MH370, whihc went missing in March 2014, becoming one of Malaysia\'s deadliest aviation incidents. All 239 people on board were presumed dead. \nAuthorities did not find any trace of the wreck, besides a few bits of debris that washed up on an island in the Indian Ocean. \nThe airliner, which was headed from Kuala Lumpur to Beijing, was carrying 227 passengers and 12 crew members. \nA new study suggests that barnacles found on a piece of plane debris might hold the key to discovering what happened to MH370. \n\nBarnacles are a type of arthropod constituting the subclass Cirripedia in the subphylum Crustacea and are related to crabs and lobsters. \n\nResearch published in AGU Advances found that MH370 might have drifted "far south" of where previous models have speculated. The study analysed barnacles found on a flaperon, whihc is the moving part of a wing. It is believed to be from the missing aircraft. \n\nA year after the disappearance, the aeroplane component washed up on the French island of Réunion in the Indian Ocean. \n\nAs the water temperature changes, the chemistry of the barnacle\'s shells changes every day. The location of the crustacean on any given day can then be ascertained using this information. \n'
>>> p(content)[0]['summary_text']
" MH370 went missing in March 2014, becoming one of Malaysia's deadliest aviation incidents . All 239 people on board were presumed dead . Authorities did not find any trace of the wreck, besides a few bits of debris that washed up on an island in the Indian Ocean . Study analysed barnacles found on a flaperon, believed to be from the missing aircraft ."
1 Like
from transformers import pipeline

p = pipeline('summarization', model='sshleifer/distilbart-cnn-12-6')

----> 2 p = pipeline(‘summarization’, model=‘sshleifer/distilbart-cnn-12-6’)

When I run above, the error occurs below. I don’t know what this error meansValueError: Could not load model sshleifer/distilbart-cnn-12-6 with any of the following classes: (, ).. I turned off and restarted it but same.

[c:\Users\user\anaconda3\lib\site-packages\transformers\pipelines_init_.py](file:///C:/Users/user/anaconda3/lib/site-packages/transformers/pipelines/init.py) in pipeline(task, model, config, tokenizer, feature_extractor, image_processor, framework, revision, use_fast, use_auth_token, device, device_map, torch_dtype, trust_remote_code, model_kwargs, pipeline_class, **kwargs) 786 if isinstance(model, str) or framework is None: 787 model_classes = {“tf”: targeted_task[“tf”], “pt”: targeted_task[“pt”]} → 788 framework, model = infer_framework_load_model( 789 model, 790 model_classes=model_classes, [c:\Users\user\anaconda3\lib\site-packages\transformers\pipelines\base.py](file:///C:/Users/user/anaconda3/lib/site-packages/transformers/pipelines/base.py) in infer_framework_load_model(model, config, model_classes, task, framework, **model_kwargs) 276 277 if isinstance(model, str): → 278 raise ValueError(f"Could not load model {model} with any of the following classes: {class_tuple}.") 279 280 if framework is None: ValueError: Could not load model sshleifer/distilbart-cnn-12-6 with any of the following classes: (, ).

Could you please remove the cached model and try again?
Google colab is an option as well.