(Sentiment Analysis with Streamlit)
Advanced streamlit apps with streamlit components
NLP with Transformers and others
(Crash course: Docker) and Assignment (1)
NLP 具影響力的應用之一是情緒分析 (sentiment analysis)。情緒分析是指將自然語言的文字轉換成情緒的極度分數 (polarity),例如:正面、負面、中性等等。厲害的情緒辭典可以應付許多場合了。
NLP 較有影響的,除了劃時代的
演算模型,另外就是基礎語言資源(language resources)。
categorical and dimensional (continuous) approaches
Categorical: (sentiment) positive, negative, neutral/ (emotion) happy, sad, angry, etc. (cf. Ekman 1971)
Dimensional: valence and arousal.(cf. Russell 1980)
從現存的語言資源來看,(1) 方法有幾種架構:
ANEW (the Affective Norms for English Words),LIWC(and Sa?), NRC emotion lexicon
SentiWordNet,SenticNet.
以上資源都有中文(嘗試)版,不見得完整。中文情緒資源整理回顧可見這篇
從認知語言的角度,要知道我們是在關心說者還是聽者的情緒。
有 Chinese EmoBank: containing 5512 words from six different source domains.
--
構式與情緒
(cf: Sentimental Constructions; 2022/LREC:CxLM: A Construction and Context-aware Language Mode)
Aspect-based Sentiment Analysis
情緒分析的進階發展,是 aspect-based sentiment analysis,也就是說,我們不只要知道說者的情緒,還要知道說者對於哪些方面的情緒。
用程式玩看看 ABSA (via: colab)
[https://pypi.org/project/aspect-based-sentiment-analysis/]
> pip install aspect-based-sentiment-analysis
Sentiment (dependency) Parser
--
"我很擔心,但是保持樂觀。也許有一天好運厄運一起降臨,誰說得準呢?"
中文的情與意,與假情假意處理。
情意共構,可以共同表徵。
全球唯一大規模人工標記中文詞義知識庫。
> cd nlp_web/assignments/twNLP-app
> pip3 install -r requirements.txt
> streamlit run ./src/app.py
(ckip requires: python 3.7.5 or above)
第一次資料與模型下載會花較久時間
> docker pull lopentu/twnlp-app
> docker-compose up
> GO TO http://localhost
中華電產學合作計畫
(identification/classification/generation) of toxic comments
用語言模型來
簡單的版本 (from lopethon 2019)
(觀看以下網站 建議擁有強固玻璃心 XD)
中文計算情意資源 (Chinese semantic-affective resources):歡迎加入我們的團隊,一起建構中文/台灣語言計算情意資源,讓中文 NLP 更進步!
上週大家已經透過簡單的情緒分析模型,了解了用 streamlit 開發 NLP-Web app 的基本流程。,這週我們要來看看如何使用
HuggingFace來建立自己的模型。
Steps to Build Your Streamlit App
或參考民間文件
近年來,Transformer 模型 (Transformer model) 成為 NLP 領域的一大革命,其主要特色是使用 attention 來處理序列資料 (sequence data)。
變成資源之一。
Huggingface 是一個開源的 NLP 模型庫,提供了許多 NLP 模型的預訓練權重 (pre-trained weights)。透過 Huggingface 的 transformers 套件,我們可以輕鬆地使用這些模型,並且進行微調 (fine-tuning)。
先註冊一個帳號。
玩玩官方提供豐富的筆記教學(建議直接開啟其提供的colab)。
Load any Hugging Face model and build cool UIs using Streamlit.(參考官方文件)
上週提到 copilot 這種 pair-programming,背後的語言模型就是 transformer 架構。我們來練習另外一個應用:重刻 writing with transformer(https://huggingface.co/spaces/merve/write-with-transformer)
然後調整一下介面,想要練習的話,Hosting your Models on Hugging Face Spaces
二選一:
以 LOPE app 為參考,用 streamlit 完善一個正體中文 NLP 處理管線 app
【挑戰題】:使用 streamlit 建立一個輿情警訊處理管線 app
繳交:
share.streamlit.io , 或 Huggingface spae 部署你的 app,一樣寫在註解。