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)

새로운 자체 호스팅 Discourse 인스턴스를 설정하고 감성 분석(sentiments)을 설정하려고 하고 있습니다. 제 ai_sentiment_model_configs는 다음과 같습니다.

모델 이름 cardiffnlp/twitter-roberta-base-sentiment-latest
엔드포인트 https://my_own_instance
api_key [비어 있음]

이것이 어느 정도 작동하여 감성 막대 그래프는 표시됩니다.

하지만 감정(Emotion) 테이블은 비어 있습니다. 이 문서는 제가 해야 할 일을 파악하기에는 불완전하거나 표현이 불분명해 보입니다.

다른 모델 ID(roberta-base-go_emotions?)를 사용하여 별도의 Docker 컨테이너를 실행해야 하는 건가요, 아니면 다른 조치를 취해야 하는 건가요? 그 감정 테이블을 채우려면 무엇을 해야 하나요?

가능하다면 이 서비스들도 자체 호스팅하는 것을 선호합니다. 올바른 방향으로 안내해 주시면 감사하겠습니다.

감정을 처리하려면 다음을 실행해야 합니다.

도.

3개의 좋아요

감사합니다. 그래서 다음과 같이 몇 가지 설정을 조정하여 두 번째 docker 컨테이너를 실행했습니다:

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

그리고 ai_sentiment_model_configs에 새 항목을 추가하니 이제 모든 것이 정상적으로 작동합니다. 감사합니다. :slight_smile:

1개의 좋아요

GPU 없이 EC2 인스턴스에서 이걸 작동시키는 방법을 모르겠다며 벽에 머리를 박고 부딪혔습니다. 적어도 제 극도로 제한된 능력과 이해 범위 내에서는, CPU 전용 인스턴스로 이 작업을 하려면 제가 이해할 수 있는 것보다 훨씬 더 많은 구성 작업이 필요해 보입니다. ghcr.io/huggingface/text-embeddings-inferencecpu 버전은 나열된 두 모델 중 어느 것도 로드하기를 거부합니다. Claude와 GPT5 모두 제가 일련의 Python 도구를 사용하여 모델들을 ONNX 모델로 변환해야 한다고 말했고, 바로 그 지점에서 저는 포기했습니다.

(아마도 저는 그저 멍청해서 자명한 단계를 놓치고 있는 것일 수도 있습니다!)

우리가 계획하고 있는 것 중 하나는 LLM을 감정 분석에 활용하는 것입니다.

이렇게 하면 Gemini Flash 2.5(또는 nano)와 같은 저렴한 모델을 감정 분석에 사용할 수 있습니다.

7개의 좋아요

자체 호스팅된 Discourse 인스턴스에서 Azure AI Language를 사용하여 이 기능을 적용하려고 하고 있습니다. 이미 GPT-4.5를 Discourse에 통합(요약 및 챗봇 기능)하기 위해 Azure 구독을 사용하고 있기 때문입니다:

  • 하지만 감정 분석 대시보드에 데이터가 표시되지 않으며, 로그에서 다음과 같은 오류를 확인할 수 있습니다:

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.

스택 트레이스에 따르면 Discourse가 HuggingFace를 사용하려고 시도하는 것 같습니다. 현재 지원되는 모델이 이것뿐인가요?

감사합니다.

N

네, 저희는 매우 구체적인 구현 방식을 가지고 있으며, 이를 더 범용적으로 만드는 방법에 대해 고민하고 있습니다.

감정 분석(sentiment)에 대해 LLM이 구조화된 출력을 반환하도록 하는 방식에는 낙관적입니다. 이 방식이 다양한 옵션을 열어주기 때문이죠. 또한, LLM이 제공하는 “초범용(hyper general)” API가 “초구체적(hyper specific)” API를 대체해 나가는 추세라고 느끼고 있습니다.

3개의 좋아요

감정 분류를 위한 인스턴스를 직접 설정하지 않고 자체 호스팅된 워드프레스에서 이 기능을 바로 실행할 수 있는 간단한 방법이 있나요?

샘, 감사합니다. 정말 좋겠습니다. 그 동안 Azure VM에서 지원되는 HuggingFace 모델 중 하나를 실행하는 방법을 알아볼 예정이랍니다…

셀프호스팅 감정 분석(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개 이하로 줄이려는 것이 제 목표이므로, 저에게는 문제가 되지 않습니다.