Chinese-text-emotion-classifier-small

Large version(560M):Johnson8187/Chinese-Emotion

ๅคงๅƒๆ•ธ็‰ˆๆœฌๆจกๅž‹๏ผˆ560M๏ผ‰๏ผšJohnson8187/Chinese-Emotion

๐Ÿ“š Model Introduction

This model is fine-tuned based on the MoritzLaurer/mDeBERTa-v3-base-mnli-xnli model, specializing in Chinese text emotion analysis.
Through fine-tuning, the model can identify the following 8 emotion labels:

  • Neutral tone
  • Concerned tone
  • Happy tone
  • Angry tone
  • Sad tone
  • Questioning tone
  • Surprised tone
  • Disgusted tone

The model is applicable to various scenarios, such as customer service emotion monitoring, social media analysis, and user feedback classification.


๐Ÿ“š ๆจกๅž‹็ฐกไป‹

ๆœฌๆจกๅž‹ๅŸบๆ–ผMoritzLaurer/mDeBERTa-v3-base-mnli-xnli ๆจกๅž‹้€ฒ่กŒๅพฎ่ชฟ๏ผŒๅฐˆๆณจๆ–ผ ไธญๆ–‡่ชžๅฅๆƒ…ๆ„Ÿๅˆ†ๆžใ€‚
้€š้Žๅพฎ่ชฟ๏ผŒๆจกๅž‹ๅฏไปฅ่ญ˜ๅˆฅไปฅไธ‹ 8 ็จฎๆƒ…็ท’ๆจ™็ฑค๏ผš

  • ๅนณๆทก่ชžๆฐฃ
  • ้—œๅˆ‡่ชž่ชฟ
  • ้–‹ๅฟƒ่ชž่ชฟ
  • ๆ†คๆ€’่ชž่ชฟ
  • ๆ‚ฒๅ‚ท่ชž่ชฟ
  • ็–‘ๅ•่ชž่ชฟ
  • ้ฉšๅฅ‡่ชž่ชฟ
  • ๅŽญๆƒก่ชž่ชฟ

่ฉฒๆจกๅž‹้ฉ็”จๆ–ผๅคš็จฎๅ ดๆ™ฏ๏ผŒไพ‹ๅฆ‚ๅฎขๆœๆƒ…็ท’็›ฃๆŽงใ€็คพไบคๅช’้ซ”ๅˆ†ๆžไปฅๅŠ็”จๆˆถๅ้ฅ‹ๅˆ†้กžใ€‚


๐Ÿš€ Quick Start

Install Dependencies

Ensure that you have installed Hugging Face's Transformers library and PyTorch:

pip install transformers torch

###Load the Model Use the following code to load the model and tokenizer, and perform emotion classification:

from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch

# ๆทปๅŠ ่จญๅ‚™่จญๅฎš
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

# ๆจ™็ฑคๆ˜ ๅฐ„ๅญ—ๅ…ธ
label_mapping = {
    0: "ๅนณๆทก่ชžๆฐฃ",
    1: "้—œๅˆ‡่ชž่ชฟ",
    2: "้–‹ๅฟƒ่ชž่ชฟ",
    3: "ๆ†คๆ€’่ชž่ชฟ",
    4: "ๆ‚ฒๅ‚ท่ชž่ชฟ",
    5: "็–‘ๅ•่ชž่ชฟ",
    6: "้ฉšๅฅ‡่ชž่ชฟ",
    7: "ๅŽญๆƒก่ชž่ชฟ"
}

def predict_emotion(text, model_path="Johnson8187/Chinese-Emotion-Small"):
    # ่ผ‰ๅ…ฅๆจกๅž‹ๅ’Œๅˆ†่ฉžๅ™จ
    tokenizer = AutoTokenizer.from_pretrained(model_path)
    model = AutoModelForSequenceClassification.from_pretrained(model_path).to(device)  # ็งปๅ‹•ๆจกๅž‹ๅˆฐ่จญๅ‚™
    
    # ๅฐ‡ๆ–‡ๆœฌ่ฝ‰ๆ›็‚บๆจกๅž‹่ผธๅ…ฅๆ ผๅผ
    inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True).to(device)  # ็งปๅ‹•่ผธๅ…ฅๅˆฐ่จญๅ‚™
    
    # ้€ฒ่กŒ้ ๆธฌ
    with torch.no_grad():
        outputs = model(**inputs)
    
    # ๅ–ๅพ—้ ๆธฌ็ตๆžœ
    predicted_class = torch.argmax(outputs.logits).item()
    predicted_emotion = label_mapping[predicted_class]
    
    return predicted_emotion

if __name__ == "__main__":
    # ไฝฟ็”จ็ฏ„ไพ‹
    test_texts = [
        "้›–็„ถๆˆ‘ๅŠชๅŠ›ไบ†ๅพˆไน…๏ผŒไฝ†ไผผไนŽ็ธฝๆ˜ฏๅšไธๅˆฐ๏ผŒๆˆ‘ๆ„Ÿๅˆฐ่‡ชๅทฑไธ€็„กๆ˜ฏ่™•ใ€‚",
        "ไฝ ่ชช็š„้‚ฃไบ›่ฉฑ็œŸ็š„่ฎ“ๆˆ‘ๅพˆๅ›ฐๆƒ‘๏ผŒๅฎŒๅ…จไธ็Ÿฅ้“่ฉฒๆ€Ž้บผๅๆ‡‰ใ€‚",
        "้€™ไธ–็•Œ็œŸ็š„ๆ˜ฏ็„กๆƒ…๏ผŒ็‚บไป€้บผๆฏๆฌก้ƒฝ่ฆ็ตฆๆˆ‘้€™ๆจฃ็š„่€ƒ้ฉ—๏ผŸ",
        "ๆœ‰ๆ™‚ๅ€™๏ผŒๆˆ‘ๅชๅธŒๆœ›่ƒฝๆœ‰ไธ€้ปžๅฎ‰้œ๏ผŒไธ่ฆๅ†่ฝๅˆฐ้€™ไบ›็„ก่Š็š„่ฉฑ้กŒใ€‚",
        "ๆฏๆฌกๆƒณ่ตท้‚ฃๆฎต้ŽๅŽป๏ผŒๆˆ‘็š„ๅฟƒ้‚„ๆ˜ฏๆœƒ็—›๏ผŒ็œŸ็š„็„กๆณ•้‡‹ๆ‡ทใ€‚",
        "ๆˆ‘ๅพžไพ†ๆฒ’ๆœ‰ๆƒณ้Žๆœƒๆœ‰้€™้บผๅคง็š„ๆ”น่ฎŠ๏ผŒ็พๅœจๆˆ‘่ฆบๅพ—่‡ชๅทฑๅฎŒๅ…จๅคฑๆŽงไบ†ใ€‚",
        "ๆˆ‘ๅฎŒๅ…จๆฒ’ๆƒณๅˆฐไฝ ๆœƒ้€™้บผๅš๏ผŒ้€™่ฎ“ๆˆ‘้ฉš่จๅˆฐ็„กๆณ•่จ€ๅ–ปใ€‚",
        "ๆˆ‘็Ÿฅ้“ๆˆ‘ๆ‡‰่ฉฒๆ›ดๅ …ๅผท๏ผŒไฝ†ๆœ‰ไบ›ๆ™‚ๅ€™๏ผŒ้€™็จฎๆƒ…็ท’็œŸ็š„่ฎ“ๆˆ‘ๅฟซ่ฆๅดฉๆฝฐไบ†ใ€‚"
    ]

    for text in test_texts:
        emotion = predict_emotion(text)
        print(f"ๆ–‡ๆœฌ: {text}")
        print(f"้ ๆธฌๆƒ…็ท’: {emotion}\n")

๐Ÿš€ ๅฟซ้€Ÿ้–‹ๅง‹

ๅฎ‰่ฃไพ่ณด

่ซ‹็ขบไฟๅฎ‰่ฃไบ† Hugging Face ็š„ Transformers ๅบซๅ’Œ PyTorch๏ผš

pip install transformers torch

ๅŠ ่ผ‰ๆจกๅž‹

ไฝฟ็”จไปฅไธ‹ไปฃ็ขผๅŠ ่ผ‰ๆจกๅž‹ๅ’Œๅˆ†่ฉžๅ™จ๏ผŒไธฆ้€ฒ่กŒๆƒ…ๆ„Ÿๅˆ†้กž๏ผš

from transformers import AutoTokenizer, AutoModelForSequenceClassification
import torch

# ๆทปๅŠ ่จญๅ‚™่จญๅฎš
device = torch.device("cuda" if torch.cuda.is_available() else "cpu")

# ๆจ™็ฑคๆ˜ ๅฐ„ๅญ—ๅ…ธ
label_mapping = {
    0: "ๅนณๆทก่ชžๆฐฃ",
    1: "้—œๅˆ‡่ชž่ชฟ",
    2: "้–‹ๅฟƒ่ชž่ชฟ",
    3: "ๆ†คๆ€’่ชž่ชฟ",
    4: "ๆ‚ฒๅ‚ท่ชž่ชฟ",
    5: "็–‘ๅ•่ชž่ชฟ",
    6: "้ฉšๅฅ‡่ชž่ชฟ",
    7: "ๅŽญๆƒก่ชž่ชฟ"
}

def predict_emotion(text, model_path="Johnson8187/Chinese-Emotion-Small"):
    # ่ผ‰ๅ…ฅๆจกๅž‹ๅ’Œๅˆ†่ฉžๅ™จ
    tokenizer = AutoTokenizer.from_pretrained(model_path)
    model = AutoModelForSequenceClassification.from_pretrained(model_path).to(device)  # ็งปๅ‹•ๆจกๅž‹ๅˆฐ่จญๅ‚™
    
    # ๅฐ‡ๆ–‡ๆœฌ่ฝ‰ๆ›็‚บๆจกๅž‹่ผธๅ…ฅๆ ผๅผ
    inputs = tokenizer(text, return_tensors="pt", truncation=True, padding=True).to(device)  # ็งปๅ‹•่ผธๅ…ฅๅˆฐ่จญๅ‚™
    
    # ้€ฒ่กŒ้ ๆธฌ
    with torch.no_grad():
        outputs = model(**inputs)
    
    # ๅ–ๅพ—้ ๆธฌ็ตๆžœ
    predicted_class = torch.argmax(outputs.logits).item()
    predicted_emotion = label_mapping[predicted_class]
    
    return predicted_emotion

if __name__ == "__main__":
    # ไฝฟ็”จ็ฏ„ไพ‹
    test_texts = [
        "้›–็„ถๆˆ‘ๅŠชๅŠ›ไบ†ๅพˆไน…๏ผŒไฝ†ไผผไนŽ็ธฝๆ˜ฏๅšไธๅˆฐ๏ผŒๆˆ‘ๆ„Ÿๅˆฐ่‡ชๅทฑไธ€็„กๆ˜ฏ่™•ใ€‚",
        "ไฝ ่ชช็š„้‚ฃไบ›่ฉฑ็œŸ็š„่ฎ“ๆˆ‘ๅพˆๅ›ฐๆƒ‘๏ผŒๅฎŒๅ…จไธ็Ÿฅ้“่ฉฒๆ€Ž้บผๅๆ‡‰ใ€‚",
        "้€™ไธ–็•Œ็œŸ็š„ๆ˜ฏ็„กๆƒ…๏ผŒ็‚บไป€้บผๆฏๆฌก้ƒฝ่ฆ็ตฆๆˆ‘้€™ๆจฃ็š„่€ƒ้ฉ—๏ผŸ",
        "ๆœ‰ๆ™‚ๅ€™๏ผŒๆˆ‘ๅชๅธŒๆœ›่ƒฝๆœ‰ไธ€้ปžๅฎ‰้œ๏ผŒไธ่ฆๅ†่ฝๅˆฐ้€™ไบ›็„ก่Š็š„่ฉฑ้กŒใ€‚",
        "ๆฏๆฌกๆƒณ่ตท้‚ฃๆฎต้ŽๅŽป๏ผŒๆˆ‘็š„ๅฟƒ้‚„ๆ˜ฏๆœƒ็—›๏ผŒ็œŸ็š„็„กๆณ•้‡‹ๆ‡ทใ€‚",
        "ๆˆ‘ๅพžไพ†ๆฒ’ๆœ‰ๆƒณ้Žๆœƒๆœ‰้€™้บผๅคง็š„ๆ”น่ฎŠ๏ผŒ็พๅœจๆˆ‘่ฆบๅพ—่‡ชๅทฑๅฎŒๅ…จๅคฑๆŽงไบ†ใ€‚",
        "ๆˆ‘ๅฎŒๅ…จๆฒ’ๆƒณๅˆฐไฝ ๆœƒ้€™้บผๅš๏ผŒ้€™่ฎ“ๆˆ‘้ฉš่จๅˆฐ็„กๆณ•่จ€ๅ–ปใ€‚",
        "ๆˆ‘็Ÿฅ้“ๆˆ‘ๆ‡‰่ฉฒๆ›ดๅ …ๅผท๏ผŒไฝ†ๆœ‰ไบ›ๆ™‚ๅ€™๏ผŒ้€™็จฎๆƒ…็ท’็œŸ็š„่ฎ“ๆˆ‘ๅฟซ่ฆๅดฉๆฝฐไบ†ใ€‚"
    ]

    for text in test_texts:
        emotion = predict_emotion(text)
        print(f"ๆ–‡ๆœฌ: {text}")
        print(f"้ ๆธฌๆƒ…็ท’: {emotion}\n")

Dataset

  • The fine-tuning dataset consists of 4,000 annotated Traditional Chinese emotion samples, covering various emotion categories to ensure the model's generalization capability in emotion classification.
  • Johnson8187/Chinese_Multi-Emotion_Dialogue_Dataset

ๆ•ธๆ“š้›†

  • ๅพฎ่ชฟๆ•ธๆ“šไพ†่‡ช4000ๅ€‹่‡ช่กŒๆจ™่จป็š„้ซ˜่ณช้‡็น้ซ”ไธญๆ–‡ๆƒ…ๆ„Ÿ่ชžๅฅๆ•ธๆ“š๏ผŒ่ฆ†่“‹ไบ†ๅคš็จฎๆƒ…็ท’้กžๅˆฅ๏ผŒ็ขบไฟๆจกๅž‹ๅœจๆƒ…ๆ„Ÿๅˆ†้กžไธŠ็š„ๆณ›ๅŒ–่ƒฝๅŠ›ใ€‚
  • Johnson8187/Chinese_Multi-Emotion_Dialogue_Dataset

๐ŸŒŸ Contact and Feedback If you encounter any issues while using this model, please contact:

Email: fable8043@gmail.com Hugging Face Project Page: chinese-text-emotion-classifier

๐ŸŒŸ ่ฏ็นซ่ˆ‡ๅ้ฅ‹

ๅฆ‚ๆžœๆ‚จๅœจไฝฟ็”จ่ฉฒๆจกๅž‹ๆ™‚ๆœ‰ไปปไฝ•ๅ•้กŒ๏ผŒ่ซ‹่ฏ็นซ๏ผš

  • ้ƒต็ฎฑ๏ผšfable8043@gmail.com
  • Hugging Face ้ …็›ฎ้ ้ข๏ผšchinese-Emotion-Small
Downloads last month
2,326
Safetensors
Model size
0.3B params
Tensor type
F32
ยท
Inference Providers NEW

Model tree for Johnson8187/Chinese-Emotion-Small

Finetuned
(22)
this model

Dataset used to train Johnson8187/Chinese-Emotion-Small

Collection including Johnson8187/Chinese-Emotion-Small