הוסטינג עצמי לסנטימנט ורגש עבור DiscourseAI

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

Running with HuggingFace TEI

HuggingFace provides an awesome container image that can get you running quickly.

For example:

mkdir -p /opt/tei-cache
docker run --rm --gpus all --shm-size 1g -p 8081:80 \
  -v /opt/tei-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' \
    "{ \"inputs\": \"I am happy\" }"

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

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 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.

After that, enable the classification by toggling ai_sentiment_enabled.

2 לייקים

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

לייק 1

[ציטוט=“Falco, פוסט:1, נושא:334451”]
רוב הזמן, תפעיל את זה על שרת ייעודי בגלל ההאצה ב-GPU
[/ציטוט]

@Falco אם מחליטים להריץ את זה על אותו שרת שמריץ את Discourse (למשל, יש לנו פריסה מאוד קטנה עם כמה אלפי הודעות), תוכל לעדכן את ההוראות כדי לתאר

  1. כיצד יכול Discourse להשתלב עם תמונת מכולת של HuggingFace TEI מקומית
  2. הצעות לכמה זיכרון RAM ושטח דיסק נוסף נדרש להרצה של הדברים הנ״ל (למשל, אם ה-Discourse הבסיס רץ על 2GB RAM ו-20GB דיסק)

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

נתקלתי בקיר לבנים של חוסר ידיעה מה לעזאזל אני עושה בניסיון לגרום לזה לעבוד על מופע EC2 ללא GPU. לפחות כמיטב יכולותיי המוגבלות ביותר והבנתי כאן, ניסיון לעשות זאת עם מופע CPU בלבד פירושו הרבה יותר עבודת תצורה ממה שאני יכול להבין. גרסאות ה-cpu של ghcr.io/huggingface/text-embeddings-inference מסרבות לטעון את שני מודלי ההאזנה; קלוד ו-GPT5 אומרים לי שאני צריך להמיר אותם למודלי ONNX עם חבורה של כלי פייתון, ושם נכשלתי.

(זה גם מאוד אפשרי שאני פשוט טיפש ומפספס שלב ברור!)

אחד הדברים שאנו מתכננים הוא לאפשר ל-LLMs לפעול כניתוח סנטימנט

בצורה זו תוכלו לחבר מודל זול כמו Gemini Flash 2.5 (או אפילו nano) ולהשתמש בו לניתוח סנטימנט.

6 לייקים

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

כן, יש לנו יישום מאוד ספציפי, אנחנו חושבים איך להפוך אותו ליותר גנרי

אני אופטימי לגבי פשוט לאפשר ל-LLMs להחזיר פלט מובנה עבור סנטימנט, כי זה פותח דלתות לאפשרויות רבות שם ואני מרגיש שמגמה של ממשקי API “היפר-ספציפיים” מוחלפים על ידי ממשקי API “היפר-כלליים” ש-LLMs מספקים.

לייק 1

האם יש דרך פשוטה להפעיל את זה על WP באירוח עצמי ללא הגדרת מופע משלך לסיווג סנטימנט?

תודה סם - זה יהיה נהדר. בינתיים, נבחן הפעלת אחד מהמודלים הנתמכים של HuggingFace על מכונה וירטואלית של Azure…