aymie-oh commited on
Commit
456d8c1
·
verified ·
1 Parent(s): f14dcbf

Update README.md

Browse files

another readme update

Files changed (1) hide show
  1. README.md +11 -11
README.md CHANGED
@@ -51,35 +51,35 @@ def predict_emotions(text, model_name, threshold=0.35):
51
  probabilities = torch.sigmoid(logits).numpy()[0]
52
 
53
  # Map probabilities to emotions
54
- emotions = {{emotion: float(prob) for emotion, prob in zip(model.config.id2label.values(), probabilities)}}
55
 
56
  # Get emotions above threshold and sort by probability
57
  predicted_emotions = [(emotion, prob) for emotion, prob in emotions.items() if prob >= threshold]
58
  predicted_emotions.sort(key=lambda x: x[1], reverse=True)
59
 
60
- return {{
61
- "text": {{text}},
62
- "predicted_emotions": {{predicted_emotions}},
63
- "all_probabilities": {{dict(sorted(emotions.items(), key=lambda x: x[1], reverse=True))}},
64
- "threshold_used": {{threshold}}
65
- }}
66
 
67
  # Example usage
68
  result = predict_emotions(
69
  "I'm feeling really excited and happy about this news!",
70
- "model-name",
71
  threshold=0.35 # Customize threshold here
72
  )
73
 
74
  # Print results
75
- print(f"Text: {{result['text']}}")
76
  print("\nDetected emotions (sorted by probability):")
77
  for emotion, prob in result['predicted_emotions']:
78
- print(f" - {{emotion.upper()}} ({{prob:.4f}})")
79
 
80
  print("\nAll emotion probabilities (sorted):")
81
  for emotion, prob in result['all_probabilities'].items():
82
- print(f" {{'*' if prob >= result['threshold_used'] else ' '}} {{emotion}}: {{prob:.4f}}")
83
  ```
84
 
85
 
 
51
  probabilities = torch.sigmoid(logits).numpy()[0]
52
 
53
  # Map probabilities to emotions
54
+ emotions = {emotion: float(prob) for emotion, prob in zip(model.config.id2label.values(), probabilities)}
55
 
56
  # Get emotions above threshold and sort by probability
57
  predicted_emotions = [(emotion, prob) for emotion, prob in emotions.items() if prob >= threshold]
58
  predicted_emotions.sort(key=lambda x: x[1], reverse=True)
59
 
60
+ return {
61
+ "text": text,
62
+ "predicted_emotions": predicted_emotions,
63
+ "all_probabilities": dict(sorted(emotions.items(), key=lambda x: x[1], reverse=True)),
64
+ "threshold_used": threshold
65
+ }
66
 
67
  # Example usage
68
  result = predict_emotions(
69
  "I'm feeling really excited and happy about this news!",
70
+ "your-username/model-name",
71
  threshold=0.35 # Customize threshold here
72
  )
73
 
74
  # Print results
75
+ print(f"Text: {result['text']}")
76
  print("\nDetected emotions (sorted by probability):")
77
  for emotion, prob in result['predicted_emotions']:
78
+ print(f" - {emotion.upper()} ({prob:.4f})")
79
 
80
  print("\nAll emotion probabilities (sorted):")
81
  for emotion, prob in result['all_probabilities'].items():
82
+ print(f" {'' if prob >= result['threshold_used'] else ' '} {emotion}: {prob:.4f}")
83
  ```
84
 
85