YAML Metadata Warning: empty or missing yaml metadata in repo card (https://huggingface.co/docs/hub/model-cards#model-card-metadata)

🎯 Tone Detection using yiyanghkust/finbert-tone

This project demonstrates how to perform Tone Detection using the [yiyanghkust/finbert-tone].

This approach enables you to classify emotional tone (e.g., Positive, Negative, Neutral, etc.) without training, by framing it as a textual entailment task.


πŸ“Œ Model Details

  • Model: yiyanghkust/finbert-tone
  • Task: Detect the tone of financial text
  • Approach: Checks if the input sentence entails a hypothesis (e.g., "Positive" or Negative)
  • Strength: No labeled training data required

πŸ“‚ Dataset Used

For benchmarking and scoring, we use the go_emotions dataset:

from datasets import load_dataset

dataset = load_dataset("go_emotions")

🧠 Tone Detection (Inference)

from transformers import pipeline

classifier = pipeline("zero-shot-classification", model="yiyanghkust/finbert-tone")

labels = ["positive", "neutral", "negative"]

text = "I can't believe this is happening again. So frustrating."

result = classifier(text, candidate_labels=labels, hypothesis_template="This text expresses {}.")
print(result)

πŸ§ͺ Evaluation with Scoring

from sklearn.metrics import accuracy_score

# Mapping GoEmotions label indices to names
id2label = dataset["train"].features["labels"].feature.names

# Evaluate on a small sample
def evaluate(dataset, candidate_labels):
    correct = 0
    total = 0
    for row in dataset.select(range(100)):  # Use more samples as needed
        text = row["text"]
        true_labels = [id2label[i] for i in row["labels"]]
        result = classifier(text, candidate_labels=candidate_labels, hypothesis_template="This text expresses {}.")
        predicted = result["labels"][0]
        if predicted in true_labels:
            correct += 1
        total += 1
    return correct/total

accuracy = evaluate(dataset["test"], candidate_labels=labels)
print(f"Zero-shot Accuracy: {accuracy:.2%}")

βš™οΈ Use Cases

Customer support tone analysis

Chat moderation for emotional tone

Feedback sentiment detection

Real-time conversation emotion tagging

Downloads last month
8
Safetensors
Model size
110M params
Tensor type
F16
Β·
Inference Providers NEW
This model isn't deployed by any Inference Provider. πŸ™‹ Ask for provider support