DiscourseAI의 감정과 정서를 자체 호스팅하기

The Discourse AI plugin supports requesting emotion/sentiment classification for new posts, which is stored in the database and can be used in reports and admin dashboards.

Discourse AI supports two types of classification, each requiring its own model:

  • Sentiment — classifies posts as positive, negative, or neutral (using cardiffnlp/twitter-roberta-base-sentiment-latest)
  • Emotion — classifies posts across 28 emotion labels such as joy, anger, surprise, etc. (using SamLowe/roberta-base-go_emotions)

To get both sentiment and emotion data in your dashboards, you need to run both models.

Running with HuggingFace TEI

HuggingFace provides an excellent container image that allows you to get up and running quickly.

Sentiment model

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 \
  --revision refs/pr/30

This should get you up and running with a local instance of cardiffnlp/twitter-roberta-base-sentiment-latest, an open model that can classify posts into positive/negative/neutral.

You can check if it’s working with

curl http://localhost:8081/ \
    -X POST \
    -H 'Content-Type: application/json' \
    -d "{ \"inputs\": \"I am happy\" }"

Which should return an array of confidence scores for each label under normal operation.

Emotion model

To also get emotion classification, run a second container with the emotion model:

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

Supported models

Making it available for your Discourse instance

Most of the time, you will be running this on a dedicated server because of the GPU speed-up. When doing so, I recommend running a reverse proxy, doing TLS termination, and securing the endpoint so it can only be connected to by your Discourse instance.

Configuring Discourse AI

Discourse AI includes site settings to configure the inference server for open-source models. You should point it to your server using the ai_sentiment_model_configs setting.

This setting accepts a JSON array of model configurations. Each entry requires:

Field Description
model_name The HuggingFace model ID (e.g. cardiffnlp/twitter-roberta-base-sentiment-latest)
endpoint The URL of your TEI instance (e.g. https://your-server:8081)
api_key API key for the endpoint (can be left blank if not required)

To get both sentiment and emotion dashboards, add an entry for each model you are running. For example, if you’re running both models locally:

  • Entry 1: model_name cardiffnlp/twitter-roberta-base-sentiment-latest, endpoint https://your-server:8081
  • Entry 2: model_name SamLowe/roberta-base-go_emotions, endpoint https://your-server:8082

After that, enable the classification by toggling ai_sentiment_enabled.

3개의 좋아요

Are there plans to support other models in languages ​​other than English?

1개의 좋아요

@Falco if one decides to run this on the same server running discourse (e.g. we have a very small deployment with a few thousand posts), could you update the instructions to outline

  1. How can discourse integrate with a local instance of HuggingFace TEI container image
  2. Suggestions on how much additional RAM/disk is required to run the above (e.g. if the base Discourse is running on 2GB RAM with 20GB disk)

So I have setup a new self hosted Discourse instance and trying to setup sentiments. This is my ai_sentiment_model_configs -

Key Value
model name cardiffnlp/twitter-roberta-base-sentiment-latest
endpoint https://my_own_instance
api_key [blank]

And it works, sort of, I get the sentiment bar graph.

However, the Emotion table is empty. This doc looks incomplete, or poorly worded for me to grasp what needs to be done.

Do I run another Docker container, with a different model ID (roberta-base-go_emotions?), or something else? What do I need to do get that emotion table filled up?

Would prefer to self host these services if possible. TIA if anybody can point me in the right direction.

For emotions you need to run the

too.

3개의 좋아요

Thank you. So I just run a second docker container with some tweaks, like so:

mkdir -p /opt/tei-cache2
docker run --detach --rm --gpus all --shm-size 1g -p 8082:80 \
  -v /opt/tei-cache2:/data \
  ghcr.io/huggingface/text-embeddings-inference:latest \
  --model-id SamLowe/roberta-base-go_emotions

and add a new entry in ai_sentiment_model_configs and it’s all working now. Thank you. :slight_smile:

1개의 좋아요

Ran face-first into a brick wall of not knowing what the hell I’m doing in trying to get this working on an EC2 instance without a GPU. At least to the best of my extremely limited abilities and understanding here, trying to do this with a CPU-only instance means a lot more configuration work than I can understand. The cpu versions of ghcr.io/huggingface/text-embeddings-inference refuse to load either of the two listed models; Claude and GPT5 both tell me I need to convert them to ONNX models with a bunch of python tools, and that’s where I noped out.

(It’s also very possible I’m just dumb and missing an obvious step!)

One thing we are planning is allowing LLMs to act as sentiment analysis

That way you can plug in a cheap model like Gemini Flash 2.5 (or even nano) and use it for sentiment analysis.

7개의 좋아요

We are trying to use this feature with Azure AI Language (from our self-hosted Discourse instance) - as we are already using our Azure subscription to integrate GPT-4.5 with Discourse (for summarization and chat-bot functionality):

  • but we are getting no data in the the sentiment dashboard, and can see these errors in the logs:

Discourse AI: Errors during bulk classification: Failed to classify 208 posts (example ids: 2256, 909, 2270, 2260, 2797) : JSON::ParserError : An empty string is not a valid JSON string.

The backtrace shows that Discourse might be trying to use HuggingFace - are these the only models supported at the moment?

Thanks,

N

Yeah we have a very specific implementation, we are thinking about how to make it more generic

I am bullish on just letting LLMs return structured output for sentiment, cause it opens the doors to many options there and I feel that as a trend “hyper specific” APIs are being replaced by “hyper general” APIs LLMs provide.

3개의 좋아요

Is there any straightforward way to get this up and running on self-hosted WP without setting up your own instance for the sentiment classification?

Thanks Sam - that would be great. In the meantime, we will look into running one of the supported HuggingFace models on an Azure VM…

셀프호스팅 감정 분석(sentiment)을 설정하려고 하는데, Docker 이미지를 실행하면 오류가 발생합니다:

0: request error: HTTP status client error (404 Not Found) for url (https://huggingface.co/cardiffnlp/twitter-roberta-base-sentiment-latest/resolve/main/tokenizer.json)
1: HTTP status client error (404 Not Found) for url (https://huggingface.co/cardiffnlp/twitter-roberta-base-sentiment-latest/resolve/main/tokenizer.json)

사용 중인 명령어는 다음과 같습니다: docker run --rm --shm-size 1g -p 8083:80 -v /opt/tei-sentiment-cache:/data ghcr.io/huggingface/text-embeddings-inference:cpu-1.9 --model-id cardiffnlp/twitter-roberta-base-sentiment-latest

GPU 지원이 없는 환경에서는 지원되지 않는 건가요, 아니면 설정 방식이 변경된 건가요?

음, 아직 모델에 대한 내 PR이 병합되지 않은 것 같으니, 내 브랜치를 직접 지정해야 합니다. 위에서 감정 분석 모델용 docker 명령어를 업데이트했으니, 브랜치를 가리키기 위한 추가 줄과 함께 시도해 보세요.

2개의 좋아요

고마워요, 성공한 것 같아요!

1개의 좋아요

2025년 8월에 보낸 이 메시지에 대한 후속 질문입니다. 다른 LLM과의 연결에 대한 예상 완료일(ETA)이 혹시 있으신가요?

현재 Gemini 3 Flash를 사용하고 있으며, AI를 직접 호스팅하지 않아도 임베딩을 수행할 수 있어 긍정적인 경험을 하고 있습니다. 비용을 절감하기 위해 곧 Gemini 3.1 Flash-Lite로 전환할 예정입니다. 감정 분석에 이러한 Gemini LLM을 사용할 수 있기를 진심으로 희망합니다. 매일 Discourse를 사용하는 것이 정말 좋습니다. 사용 경험이 매우 훌륭합니다.

감사합니다.

1개의 좋아요

어제 추가했는데, 곧 웹사이트에 표시될 것입니다.

2개의 좋아요

감정 분류기를 더 적은 이모지로 줄이는 것이 가능할까요?

대시보드의 일부 이모지가 완전히 표시되지 않을 수 있다는 점은 알고 있습니다. 하지만 28개에서 10개 이하로 줄이려는 것이 제 목표이므로, 저에게는 문제가 되지 않습니다.