File size: 1,715 Bytes
b1acf7e |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
"""
Sentiment mapping utilities for different model outputs.
"""
from typing import Dict
from ..config.settings import SENTIMENT_MAPPINGS
def get_sentiment_mapping(num_classes: int) -> Dict[int, str]:
"""
Get the sentiment mapping based on number of classes.
Args:
num_classes: Number of output classes from the model
Returns:
Dictionary mapping class indices to sentiment labels
"""
return SENTIMENT_MAPPINGS.get(
num_classes, {i: f"Class_{i}" for i in range(num_classes)}
)
def get_sentiment_colors() -> Dict[str, str]:
"""
Get color-coded sentiment display mapping.
Returns:
Dictionary mapping sentiment labels to emoji indicators
"""
return {
"Positive": "π’",
"Negative": "π΄",
"Neutral": "π‘",
"Angry": "π΄",
"Sad": "π΅",
"Happy": "π’",
"Fear": "π£",
"Disgust": "π ",
"Surprise": "π‘",
}
def format_sentiment_result(
sentiment: str, confidence: float, input_info: str = "", model_name: str = ""
) -> str:
"""
Format sentiment analysis result for display.
Args:
sentiment: Predicted sentiment label
confidence: Confidence score
input_info: Information about the input
model_name: Name of the model used
Returns:
Formatted result string
"""
colors = get_sentiment_colors()
emoji = colors.get(sentiment, "β")
result = f"{emoji} Sentiment: {sentiment}\n"
result += f"Confidence: {confidence:.2f}\n"
if input_info:
result += f"Input: {input_info}\n"
if model_name:
result += f"Model: {model_name}\n"
return result
|