Discourse AI 插件支持请求新帖子的情感/情绪分类,这会存储在数据库中,并可用于报告和管理仪表板中。
Discourse AI 支持两种类型的分类,每种类型都需要自己的模型:
- 情绪(Sentiment)—— 将帖子分类为积极、消极或中性(使用
cardiffnlp/twitter-roberta-base-sentiment-latest) - 情感(Emotion)—— 将帖子分类为喜悦、愤怒、惊讶等 28 种情感标签之一(使用
SamLowe/roberta-base-go_emotions)
要在您的仪表板中获取情感和情绪数据,您需要运行两个模型。
使用 HuggingFace TEI 运行
HuggingFace 提供了一个很棒的容器镜像,可以帮助您快速启动并运行。
情绪模型
mkdir -p /opt/tei-sentiment-cache
docker run --rm --gpus all --shm-size 1g -p 8081:80 \
-v /opt/tei-sentiment-cache:/data \
ghcr.io/huggingface/text-embeddings-inference:latest \
--model-id cardiffnlp/twitter-roberta-base-sentiment-latest
这应该能让您使用本地的 cardiffnlp/twitter-roberta-base-sentiment-latest 实例,这是一个开源模型,可以将帖子分类为积极/消极/中性。
您可以使用以下命令检查它是否正常工作:
curl http://localhost:8081/ \
-X POST \
-H 'Content-Type: application/json' \
-d "{ \"inputs\": \"I am happy\" }"
在正常运行情况下,这应该会返回每个标签的置信度数组。
情感模型
要获取情感分类,请使用情感模型运行第二个容器:
mkdir -p /opt/tei-emotion-cache
docker run --rm --gpus all --shm-size 1g -p 8082:80 \
-v /opt/tei-emotion-cache:/data \
ghcr.io/huggingface/text-embeddings-inference:latest \
--model-id SamLowe/roberta-base-go_emotions
支持的模型
- cardiffnlp/twitter-roberta-base-sentiment-latest · Hugging Face — 情绪(积极/消极/中性)
- SamLowe/roberta-base-go_emotions · Hugging Face — 情感(28 个情感标签)
使其可用于您的 Discourse 实例
大多数情况下,由于 GPU 加速,您将在专用服务器上运行此服务。在这样做时,我建议运行一个反向代理,执行 TLS 终止,并保护端点,使其只能由您的 Discourse 实例连接。
配置 Discourse AI
Discourse AI 包含站点设置,用于配置开源模型的推理服务器。您应该使用 ai_sentiment_model_configs 设置将其指向您的服务器。
此设置接受模型配置的 JSON 数组。每个条目需要:
| 字段 | 描述 |
|---|---|
model_name |
HuggingFace 模型 ID(例如 cardiffnlp/twitter-roberta-base-sentiment-latest) |
endpoint |
TEI 实例的 URL(例如 https://your-server:8081) |
api_key |
端点的 API 密钥(如果不需要,可以留空) |
要同时获取情绪和情感仪表板,请为您正在运行的每个模型添加一个条目。例如,如果您在本地运行这两个模型:
- 条目 1:
model_name为cardiffnlp/twitter-roberta-base-sentiment-latest,endpoint为https://your-server:8081 - 条目 2:
model_name为SamLowe/roberta-base-go_emotions,endpoint为https://your-server:8082
之后,通过切换 ai_sentiment_enabled 来启用分类。
