Huggingface Transformers
✕Text Classification with Hugging Face
Question 1 of 3
- Write a function
is_spam(review_text)that uses text-classification pipeline with a model likedistilbert-base-uncased-finetuned-sst-2-english. If the score isabove 0.9and the label isNEGATIVE, return FLAG FOR REVIEW - Write a function
get_topic(news_snippet)that uses a zero-shot-classification pipeline. The function should take a snippet and a list of labels (e.g., ["politics", "economy", "sports"]) and return the label with the highest confidence score. - Write a function
detect_anger(text)using an emotion-specific model (likej-hartmann/emotion-english-distilrobert-base). If the "anger" score is the highest among all emotions, return True
- Write a function
Summarization with Hugging Face
Question 2 of 3
- Write a function
create_bullet_summary(long_text)that uses the summarization pipeline. Set the max_length to 50 and min_length to 10. The function should return the summary string stripped of any leading or trailing whitespace. - Write a function
summarize_csv_column(df, column_name)that takes a pandas DataFrame, iterates through the first 5 rows of a specific text column, and returns a Python list containing the summarized version of each row. - Write a function
dynamic_summarize(text)that checks the length of the input. If the text is more than 500 words, use the pipeline to compress it; if it is less than 500 words, return the original text as-is.
- Write a function
Question Answering with Hugging Face
Question 3 of 3
- Write a function
get_answer(context_text, question)that uses the "question-answering" pipeline. Test it by passing a paragraph about a company's fiscal year and asking, "What was the total revenue?" Return only the answer string from the output dictionary. - Write a function
verified_answer(context, question)that performs question-answering. If the score returned by the model is less than 0.5, the function should return "I am not confident in the answer" instead of the model's text. - Create a function
find_date(report_text)that specifically asks the model "On what date was this document signed?" and returns the start and end indices (start and end keys) of where that answer was found in the original text.
- Write a function
