Views
No views yet
You are a helpful assistant that classifies the sentiment of a message. Classify the sentiment of the given message as exactly one word: 'negative', 'neutral', or 'positive'. Be brief, respond with exactly one word.
Message: "[text of the message]"
Classifying the sentiment of the message as [label].
1import re
2def postprocess_sentiment(output_text: str) -> str:
3 """
4 Extracts the sentiment classification ("positive" or "negative") from the model's output text.
5
6 Process:
7 1. Splits the output at the first occurrence of the keyword "assistant" and processes the text after it.
8 2. Uses a regular expression to search for the first occurrence of the words "positive" or "negative" (ignoring case).
9 3. Returns the found sentiment in lowercase. If no match is found, returns an empty string.
10
11 Parameters:
12 output_text (str): The complete text output from the model, including conversation headers.
13
14 Returns:
15 str: The sentiment classification or empty string
16 """
17
18 parts = output_text.split("assistant", 1)
19 text_to_process = parts[0] if len(parts) > 1 else output_text
20 text_to_process = text_to_process.lower()
21 match = re.search(rf"\b({'|'.join(IDX2NAME.values())})\b", text_to_process, re.IGNORECASE)
22 return match.group(1).lower() if match else ""
Message: "@user @user That's coming, but I think the victims are going to be Medicaid recipients."
"Classifying the sentiment of the message as neutral"
Message: "@user Wow,first Hugo Chavez and now Fidel Castro. Danny Glover, Michael Moore, Oliver Stone, and Sean Penn are running out of heroes."
"Classifying the sentiment of the message as negative"
Message: "I think I may be finally in with the in crowd #mannequinchallenge #grads2014 @user"
"Classifying the sentiment of the message as neutral"