I cant parse my input into my model

What I’m trying to do:
I am trying to parse input holding a conversation into a summary model but it throws an error

What I’ve tried and what’s not working:
Hello community, I have a problem with passing an input to a summary model. I fine-tuned a Bart model to some meeting notes, and i am building an anvil app around it. The model returns the correct output when i pass a variable object holding sentences but throws an error when i pass in a dict holding the sentences. It also throws an error when i pass either the dict or senetcnes to the model wrapped in a defined function. The error it throws is "have the wrong format. The should be either of type str or type list " This is the link to my kaggle notebook so anyone can access the code

Code Sample:

# this is a formatted code snippet.
#define a function that uses model to summarize conversations
@anvil.server.callable
def summarize(context_text):
    question_set = {
            
            'context': context_text
}
    results = nlp_pipeline(question_set)
    return results['answer']

document = [
        "The extractive summarization feature uses natural language processing techniques to locate key sentences in an unstructured text document. "
        "These sentences collectively convey the main idea of the document. This feature is provided as an API for developers. " 
        "They can use it to build intelligent solutions based on the relevant information extracted to support various use cases. "
        "In the public preview, extractive summarization supports several languages. It is based on pretrained multilingual transformer models, part of our quest for holistic representations. "
        "It draws its strength from transfer learning across monolingual and harness the shared nature of languages to produce models of improved quality and efficiency. "
    ]

summary_set = {
            
            'context': document
}

summarize(summary_set)

# paste your code between ``` 

Clone link:
share a copy of your app

In your summarize function, I suggest you add a line to print context_text

I suspect it’s not quite what you expect it to be.

Thanks for the reply.

The context_text is the same text because it’s holding the text I want to pass into the summary().

At this point, I am just confused.

Have you done as I suggested? Paste the result here.

yes, i did.
This is the error below

“ValueError: args[0]: {‘context’: [‘\n William Samoei Arap Ruto (born 21 December 1966) is a Kenyan politician who is the president-elect of Kenya.[1] He has served as the deputy president of Kenya since 2013.[2][3][4] In the 2013 presidential election, he was elected the Deputy President alongside President Uhuru Kenyatta under the Jubilee Alliance ticket. Ruto was a Member of Parliament (MP) from 1998 to 2013. He served as Minister for Home Affairs in the Daniel Arap Moi administration from August to December 2002. He later served in the Mwai Kibaki administration as Minister of Agriculture from 2008 to 2010 and as Minister for Higher Education from April to October 2010. He was elected president of Kenya in the 2022 presidential election.’]} have the wrong format. The should be either of type str or type list

1 Like

Well, the answer is right there. That’s neither a str or a list. It’s a dict.

1 Like

I have converted the input text using str(), I have also serialized using json.dumps(), they both return this error ‘’ list indices must be integers or slices, not str’’

the error also occurs if I set the input to a string type.

In the code you’ve shown, your are passing a dict (summary_set) into your function.

In the function body, you are then adding that dict to another dict (question_set) which you then pass to nlp_pipeline.

I figured it out. The problem itself was returning the wrong key in the function. I was supposed to return “summary_text” which is the name of the key returned in the results object.

About the code, i have cleaned it up.

Thanks for the help, appreciate it.

I have cleaned it up.

If you want to clean up this post, too, you can mark it as done. :wink: (See the checkbox in “…”.)