SlideShare a Scribd company logo
1 of 44
Deep Learning Basic
#02 Next RNN
Terence Huang
自我介紹
學經歷
緯創資通 高級工程師 (2015/3 ~)
長庚醫院 研究助理 (2013/9 ~2014/11)
中山大學 應數系統計碩士 (2011/9 ~ 2013/7)
高雄師大 數學系學士 (2005/9 ~ 2009/7)
獲獎
2017 台南智慧黑客松智慧醫療組第二名
2012 中山高大統計新秀
特殊經歷
訪問 MIT 的工程師 (2017/10 ~ 2018/10)
Pytorch Kaohsiung 讀書會的社長
2
Terence Huang
進入 deep learning 文字分析前
• 怎麼把文字塞進 neural network
3
這
是
貓
進入 deep learning 文字分析前
• One-hot vector
4
這
是
貓
1,0,0
0,1,0
0,0,1
進入 deep learning 文字分析前
• One-hot vector by character
5
這
是
大
1,0,0,0
0,1,0,0
0,0,1,0
象 0,0,1,0
進入 deep learning 文字分析前
• One-hot vector by token
6
這
是
大象
1,0,0
0,1,0
0,0,1
進入 deep learning 文字分析前
• 只能放 one-hot vector 的 feature?
7
Feature 意義
BOW, Bag of word 文中每個字出現的次數/比例
TF-IDF 文中每個字的獨特程度
Word2vec 考慮上下文對每個字的意義影響,以向量做表示
Doc2vec 每個文章的意義,以向量做表示
LDA, Latent Dirichlet Allocation 每個文章中的主題比例
BOW, Bag of words
• 意義:文中每個字出現的次數/比例
• 用途:用詞習慣比較、文章抄襲、…
8
BOW, Bag of words
• 計算方式: Counting the number of times each meaningful word appears in each
document. Remove stop words.
9
"With all this stuff going down at the moment with MJ i've
started listening to his music, watching the odd
documentary here and there, watched The Wiz and
watched Moonwalker again. Maybe i just want to get a
certain insight into this guy who i thought was really cool
in the eighties just to maybe make up my mind whether he
is guilty or innocent. Moonwalker is part biography, part
feature film which i remember going to see at the cinema
when it was originally released. Some of it has subtle
messages about MJ's feeling towards the press and also
the obvious message of drugs are bad m'kay.
<br/><br/>..."
feature Count
also 2
bad 3
film 2
get 1
like 3
made 1
make 1
…
…
Document 1
𝑡1
𝑡2
𝑡7
⋮
⋮
BOW, Bag of words
• 計算方式: We have many documents, each document has different meaningful
words.
10
also bad film get like made …
2 3 2 1 3 1 …
film films like made man many …
1 2 1 1 1 2 …
also film get good movie one …
1 4 1 1 1 2 …
even film made movie much time …
3 1 1 1 1 1 …
Document 1
Document 2
Document 3
Document 4
BOW, Bag of words
• 計算方式: Use the most frequent words in all documents.
11
film movie one like good even …
Document 1 2 3 4 3 0 0 …
Document 2 1 1 2 1 0 0 …
Document 3 4 1 2 0 1 0 …
Document 4 1 1 0 0 0 3 …
…
…
…
…
…
…
…
Document 1000 0 2 0 3 1 2 …
1653 1630 1088 769 664 501 …
𝑡1 𝑡2 𝑡6⋯ ⋯
BOW, Bag of words
• 計算方式: Use the most frequent words in all documents.
12
film movie one like good even …
Document 1 2% 3% 4% 3% 0% 0% … 100%
Document 2 1% 1% 2% 1% 0% 0% … 100%
Document 3 4% 1% 2% 0% 1% 0% … 100%
Document 4 1% 1% 0% 0% 0% 3% … 100%
…
…
…
…
…
…
…
100%
Document 1000 0% 2% 0% 3% 1% 2% … 100%
TFIDF, Term frequency–inverse document frequency
• 意義:文中每個字的獨特程度,獨特性是跟其他的文一起比
• 用途:用來找出一篇文章中, 足以代表這篇文章的關鍵字的方法
13
TFIDF, Term frequency–inverse document frequency
• 計算方式:尋找這樣的關鍵字, 要考慮以下兩個要素
- TF, Term Frequency
• 這個字在這篇文章中出現的頻率
- IDF, Inverse-Document Frequency
• 在所有的文章中,有幾篇文章有這個字
• TF-IDF 值越大的, 越可以作為代表這篇文章的關鍵字
14
𝑇𝐹𝐼𝐷𝐹 = 𝑇𝐹 × Inv 𝐷𝐹 = 𝑛 𝑤
𝑑
× log2
𝑁
𝑁 𝑤
𝑛 𝑤
𝑑
:文章 𝑑 中,文字 𝑤 出現的次數
𝑁:表示總共有幾篇文章
𝑁 𝑤:表示有文字 𝑤 的文章有幾篇
TFIDF, Term frequency–inverse document frequency
• Example:Reuters Corpus (10788 篇文章)
- 其中某篇新聞內容
• GRAIN SHIPS LOADING AT PORTLAND
There were three grain ships loading and two ships were waiting to load at Portland , according to
the Portland Merchants Exchange .
- 𝑇𝐹𝐼𝐷𝐹portland = 3 × log2
10788
28
≈ 25.769, 10788 篇中有 28 篇出現 portland
- 𝑇𝐹𝐼𝐷𝐹𝑡𝑜 = 2 × log2
10788
6944
≈ 1.271, 10788 篇中有 6944 篇出現 to
15
Word2vec
• 意義:考慮上下文對每個字的意義影響,以向量做表示
• 用途:相似字、雙語翻譯、Analogies (ex."king - man + woman = queen.")
16
之前編碼 Word2vec
dog Id222 0,1,0,0,0,0,0,0 0.12,0.13,0.01,0.01,0.01
cat Id357 0,0,0,0,0,0,1,0 0.12,0.12,0.01,0.01,0.01
car Id358 0,0,0,0,0,0,0,1 0.01,0.01,0.33,0.40,0.25
Word2vec
• 計算方式: Skip-Gram
- ex. Doc1 = I have a cat. I love cat and dog.
- 7 個不同單字
8 個 pair
17
pair * i have i have a have a cat cat and dog
字 i have a ⋯ and
上下文 [*, have] [i, a] [have, cat] [cat, dog]
範例
Word2vec
• 計算方式: Skip-Gram
- ex. have a cat → a, [have, cat]
18
0
0
1
0
0
0
0
0.1
⋮
0.2
a
0
1
0
0
0
0
0
0
0
0
1
0
0
0
have
cat
0.1
0.9
0.0
0.0
0.1
0.3
0.2
0.1
0.1
0.0
0.0
0.1
0.4
0.2
∑
∑
∑
∑
∑
越像越好
轉出的向量
0.1
⋮
0.2
one hot
vector
one hot
vector
one hot
vector
越像越好
∑
∑
∑
Word2vec
• 意義:考慮上下文對每個字的意義影響,以向量做表示
• 用途:相似字、雙語翻譯、Analogies (ex."king - man + woman = queen.")
19
之前編碼 Word2vec
dog Id222 0,1,0,0,0,0,0,0 0.12,0.13,0.01,0.01,0.01
cat Id357 0,0,0,0,0,0,1,0 0.12,0.12,0.01,0.01,0.01
car Id358 0,0,0,0,0,0,0,1 0.01,0.01,0.33,0.40,0.25
Doc2vec
• 意義:每個文章的意義,以向量做表示
20
Doc2vec
• 計算方式: 借用 word2vec 的結果,平均內文 meaningful word 的向量
21
I have a cat. I love cat and dog.
Document 1
0.12,0.12,0.01,0.01,0.01
0.12,0.13,0.01,0.01,0.01
I
have
a
cat
cat
I
love
and
dog
0.12,0.12,0.01,0.01,0.01
0.01,0.01,0.01,0.01,0.95
0.01,0.01,0.01,0.01,0.95
0.01,0.01,0.01,0.95,0.01
0.39,0.40,0.06,1.00,1.00
0.39,0.40,0.06,1.00,1.00
6
文章的意義不單一?
LDA, Latent Dirichlet Allocation
• 意義:每個主題佔內文的比例
22
0.2
0.1
0.4
0.3
0.3
0.5
0.1
0.1
The William Randolph
Hearst Foundation will
give $1.25 million to
Lincoln Center,
Metropolitan …
''Our board felt that we
had a real opportunity to
make a mark on the
future of …
Documents
…
LDA
…
Arts
Budgets
Children
Education
LDA, Latent Dirichlet Allocation
• 意義:每個主題佔內文的比例
23
Arts
0.461 * music +
0.134 * movie + …
Budgets
0.211 * tax +
0.035 * money + …
Children
0.309 * children +
0.241 * family + …
Education
0.217 * school +
0.222 * teacher + …
The William Randolph
Hearst Foundation will
give $1.25 million to
Lincoln Center,
Metropolitan …
''Our board felt that we
had a real opportunity to
make a mark on the
future of …
Topics
Documents
…
LDA
LDA, Latent Dirichlet Allocation
• 意義:每個主題佔內文的比例
24
Arts
0.461 * music +
0.134 * movie + …
Budgets
0.211 * tax +
0.035 * money + …
Children
0.309 * children +
0.241 * family + …
Education
0.217 * school +
0.222 * teacher + …
0.2
0.1
0.4
0.3
0.3
0.5
0.1
0.1
The William Randolph
Hearst Foundation will
give $1.25 million to
Lincoln Center,
Metropolitan …
''Our board felt that we
had a real opportunity to
make a mark on the
future of …
Topics
Documents
…
LDA
進入 deep learning 文字分析前
• 只能放 one-hot vector 的 feature?
25
Feature 意義
BOW, Bag of word 文中每個字出現的次數/比例
TF-IDF 文中每個字的獨特程度
Word2vec 考慮上下文對每個字的意義影響,以向量做表示
Doc2vec 每個文章的意義,以向量做表示
LDA, Latent Dirichlet Allocation 每個文章中的主題比例
動手時間 Q&A
1. 程式碼理解
- Copy & Paste 範例程式: https://github.com/Terence0408/Teach_code
- 解析程式
- 改動程式
- 做點應用
26
正式進入 RNN/LSTM
• Motivation: Why Learn recurrent neural network?
- Language Modeling
- Key: speech recognition, machine translation, image captioning, …
27
RNN are popular models that have
shown great promise
in many Language Modeling tasks
正式進入 RNN/LSTM
• Task1: predict {Yes, No} by sentence
• Task2: predict next words by previous words in sentence
• Ponder the question “how is that even possible?”
28
Input Output
the clouds are in the sky
I grew up in France…… I speak fluent French
Input Output
the clouds are in the sky Yes
the clouds are in the ground No
RNN , recurrent neural networks
• RNN (Recurrent Neural Networks)
29
𝑿 𝟏
𝒉 𝟏
𝑿 𝟐
𝒉 𝟐
𝒉 𝟎 𝒉 𝟏
Pass
weight
……..
……..
RNN, recurrent neural networks
• RNN (Recurrent Neural Networks)
30
In this moment
– Input: 𝑋𝑡 & 𝒉 𝒕−𝟏
– Output: 𝒉 𝒕
RNN, recurrent neural networks
• RNN (Recurrent Neural Networks)
31
In this moment
– Input: 𝑋𝑡+1 & 𝒉 𝒕
– Output: 𝒉 𝒕+𝟏
In this moment
– Input: 𝑋𝑡 & 𝒉 𝒕−𝟏
– Output: 𝒉 𝒕
LSTM, Long Short Term Memory Networks
• RNN is Good. But …
- Sometimes, we only need to look at recent information to perform the present task.
- Long-Term Dependencies problem
32
Input Output
I grew up in France…… I speak fluent French
Important information, but …
Too far to pass information/weight to output
LSTM, Long Short Term Memory Networks
33
RNN
LSTM
LSTM, Long Short Term Memory Networks
• LSTM (Long Short Term Memory Networks)
34
Throw old info. Store new info. Update memory
𝑓𝑡: 上一步 memory cell
使用比例
C 𝑡: 更新這一步的
memory cell
𝑜𝑡: 下一步的 memory cell
使用比例
ℎ 𝑡: 輸入給下一步的資訊
LSTM, Long Short Term Memory Networks
• 權重計算
- Backpropagation: 傳遞 預測誤差 來更新權重
1. 計算預測誤差
2. 傳遞誤差讓前一層用 SGD 找最適權重
3. 計算更新前一層後的預測誤差
4. 一直把誤差傳遞給前面層做更新
35
LSTM, Long Short Term Memory Networks
• 修正權重: Backpropagation through time
• Problem: Compute cost & vanishing gradient
36
LSTM, Long Short Term Memory Networks
• 修正權重: Truncated Backpropagation through time
37
True
Sequence length: 6
Errors truncated to 3 steps
Tensorflow-style
Sequence length: 3
Errors truncated to 3 steps
解析程式
• imdb_lstm.py 電影評論預測
1. 引入 Keras 套件
2. 模型結構
3. 資料 (Image & label) 擺放
4. 預測結果
5. 參數調教
38
解析範例程式
2. 模型結構
39
建立 deep learning 環境叫 model
設定預測誤差參數
放入資料開始跑模型
同時預測 Test set 結果
與訓練模型間關係:獨立
批次跑,一次跑多少筆
解析範例程式
3. 資料 (Image & label) 擺放
40
Token 轉化向量的維度
一個句子要有幾個 token
從 imbd dataset
取出現次數前 20000的 token
處裡句子 token 數不足
Pad(通常補空格)
動手時間 Q&A
• Copy & Paste 範例程式:
https://github.com/keras-team/keras/blob/master/examples/imdb_lstm.py
• 嘗試各種參數組合
• 換筆資料
• 換別的模型結構
• 記得,把Epoch 設 1 & 資料切小一點
41
RNN/LSTM 應用
42
Signal, stock
Seq2seq: 對話機器人
POS/NER tagging
Keras Example
43
Q&A
Thanks for your attention!
44

More Related Content

What's hot

Recurrent Neural Networks
Recurrent Neural NetworksRecurrent Neural Networks
Recurrent Neural NetworksSharath TS
 
Sk t academy lecture note
Sk t academy lecture noteSk t academy lecture note
Sk t academy lecture noteSusang Kim
 
[DSC 2016] 系列活動:李宏毅 / 一天搞懂深度學習
[DSC 2016] 系列活動:李宏毅 / 一天搞懂深度學習[DSC 2016] 系列活動:李宏毅 / 一天搞懂深度學習
[DSC 2016] 系列活動:李宏毅 / 一天搞懂深度學習台灣資料科學年會
 
Recurrent Neural Networks (RNN) | RNN LSTM | Deep Learning Tutorial | Tensorf...
Recurrent Neural Networks (RNN) | RNN LSTM | Deep Learning Tutorial | Tensorf...Recurrent Neural Networks (RNN) | RNN LSTM | Deep Learning Tutorial | Tensorf...
Recurrent Neural Networks (RNN) | RNN LSTM | Deep Learning Tutorial | Tensorf...Edureka!
 
[2A4]DeepLearningAtNAVER
[2A4]DeepLearningAtNAVER[2A4]DeepLearningAtNAVER
[2A4]DeepLearningAtNAVERNAVER D2
 
What Deep Learning Means for Artificial Intelligence
What Deep Learning Means for Artificial IntelligenceWhat Deep Learning Means for Artificial Intelligence
What Deep Learning Means for Artificial IntelligenceJonathan Mugan
 
Study of End to End memory networks
Study of End to End memory networksStudy of End to End memory networks
Study of End to End memory networksASHISH MENKUDALE
 
Recurrent Neural Networks (D2L8 Insight@DCU Machine Learning Workshop 2017)
Recurrent Neural Networks (D2L8 Insight@DCU Machine Learning Workshop 2017)Recurrent Neural Networks (D2L8 Insight@DCU Machine Learning Workshop 2017)
Recurrent Neural Networks (D2L8 Insight@DCU Machine Learning Workshop 2017)Universitat Politècnica de Catalunya
 
Sequence to Sequence Learning with Neural Networks
Sequence to Sequence Learning with Neural NetworksSequence to Sequence Learning with Neural Networks
Sequence to Sequence Learning with Neural NetworksNguyen Quang
 
ACL読み会2014@PFI "Less Grammar, More Features"
ACL読み会2014@PFI "Less Grammar, More Features"ACL読み会2014@PFI "Less Grammar, More Features"
ACL読み会2014@PFI "Less Grammar, More Features"nozyh
 
Deep Learning and Design Thinking
Deep Learning and Design ThinkingDeep Learning and Design Thinking
Deep Learning and Design ThinkingYen-lung Tsai
 
Understanding RNN and LSTM
Understanding RNN and LSTMUnderstanding RNN and LSTM
Understanding RNN and LSTM健程 杨
 
Haplotyping and genotype imputation using Graphics Processing Units
Haplotyping and genotype imputation using Graphics Processing UnitsHaplotyping and genotype imputation using Graphics Processing Units
Haplotyping and genotype imputation using Graphics Processing UnitsUSC
 
Lecture 7: Recurrent Neural Networks
Lecture 7: Recurrent Neural NetworksLecture 7: Recurrent Neural Networks
Lecture 7: Recurrent Neural NetworksSang Jun Lee
 

What's hot (20)

Recurrent Neural Networks
Recurrent Neural NetworksRecurrent Neural Networks
Recurrent Neural Networks
 
Recurrent Neural Network
Recurrent Neural NetworkRecurrent Neural Network
Recurrent Neural Network
 
Sk t academy lecture note
Sk t academy lecture noteSk t academy lecture note
Sk t academy lecture note
 
LSTM Tutorial
LSTM TutorialLSTM Tutorial
LSTM Tutorial
 
[DSC 2016] 系列活動:李宏毅 / 一天搞懂深度學習
[DSC 2016] 系列活動:李宏毅 / 一天搞懂深度學習[DSC 2016] 系列活動:李宏毅 / 一天搞懂深度學習
[DSC 2016] 系列活動:李宏毅 / 一天搞懂深度學習
 
Recurrent Neural Networks (RNN) | RNN LSTM | Deep Learning Tutorial | Tensorf...
Recurrent Neural Networks (RNN) | RNN LSTM | Deep Learning Tutorial | Tensorf...Recurrent Neural Networks (RNN) | RNN LSTM | Deep Learning Tutorial | Tensorf...
Recurrent Neural Networks (RNN) | RNN LSTM | Deep Learning Tutorial | Tensorf...
 
Rnn & Lstm
Rnn & LstmRnn & Lstm
Rnn & Lstm
 
Lstm
LstmLstm
Lstm
 
[2A4]DeepLearningAtNAVER
[2A4]DeepLearningAtNAVER[2A4]DeepLearningAtNAVER
[2A4]DeepLearningAtNAVER
 
What Deep Learning Means for Artificial Intelligence
What Deep Learning Means for Artificial IntelligenceWhat Deep Learning Means for Artificial Intelligence
What Deep Learning Means for Artificial Intelligence
 
Study of End to End memory networks
Study of End to End memory networksStudy of End to End memory networks
Study of End to End memory networks
 
Recurrent Neural Networks (D2L8 Insight@DCU Machine Learning Workshop 2017)
Recurrent Neural Networks (D2L8 Insight@DCU Machine Learning Workshop 2017)Recurrent Neural Networks (D2L8 Insight@DCU Machine Learning Workshop 2017)
Recurrent Neural Networks (D2L8 Insight@DCU Machine Learning Workshop 2017)
 
Sequence to Sequence Learning with Neural Networks
Sequence to Sequence Learning with Neural NetworksSequence to Sequence Learning with Neural Networks
Sequence to Sequence Learning with Neural Networks
 
Deep cv 101
Deep cv 101Deep cv 101
Deep cv 101
 
LSTM
LSTMLSTM
LSTM
 
ACL読み会2014@PFI "Less Grammar, More Features"
ACL読み会2014@PFI "Less Grammar, More Features"ACL読み会2014@PFI "Less Grammar, More Features"
ACL読み会2014@PFI "Less Grammar, More Features"
 
Deep Learning and Design Thinking
Deep Learning and Design ThinkingDeep Learning and Design Thinking
Deep Learning and Design Thinking
 
Understanding RNN and LSTM
Understanding RNN and LSTMUnderstanding RNN and LSTM
Understanding RNN and LSTM
 
Haplotyping and genotype imputation using Graphics Processing Units
Haplotyping and genotype imputation using Graphics Processing UnitsHaplotyping and genotype imputation using Graphics Processing Units
Haplotyping and genotype imputation using Graphics Processing Units
 
Lecture 7: Recurrent Neural Networks
Lecture 7: Recurrent Neural NetworksLecture 7: Recurrent Neural Networks
Lecture 7: Recurrent Neural Networks
 

Similar to #02 Next RNN

Deep Learning for Natural Language Processing
Deep Learning for Natural Language ProcessingDeep Learning for Natural Language Processing
Deep Learning for Natural Language ProcessingRoopal Garg
 
Deep Learning for Natural Language Processing by Roopal Garg
Deep Learning for Natural Language Processing by Roopal GargDeep Learning for Natural Language Processing by Roopal Garg
Deep Learning for Natural Language Processing by Roopal GargData Con LA
 
Deep learning nlp
Deep learning nlpDeep learning nlp
Deep learning nlpHeng-Xiu Xu
 
Dataworkz odsc london 2018
Dataworkz odsc london 2018Dataworkz odsc london 2018
Dataworkz odsc london 2018Olaf de Leeuw
 
DeepLearning 10章 回帰結合型ニューラルネットワークと再帰型ネットワーク
DeepLearning 10章 回帰結合型ニューラルネットワークと再帰型ネットワークDeepLearning 10章 回帰結合型ニューラルネットワークと再帰型ネットワーク
DeepLearning 10章 回帰結合型ニューラルネットワークと再帰型ネットワークhirono kawashima
 
Devoxx traitement automatique du langage sur du texte en 2019
Devoxx   traitement automatique du langage sur du texte en 2019 Devoxx   traitement automatique du langage sur du texte en 2019
Devoxx traitement automatique du langage sur du texte en 2019 Alexis Agahi
 
October hug
October hugOctober hug
October hughuguk
 
CSCE181 Big ideas in NLP
CSCE181 Big ideas in NLPCSCE181 Big ideas in NLP
CSCE181 Big ideas in NLPInsoo Chung
 
Quick tour all handout
Quick tour all handoutQuick tour all handout
Quick tour all handoutYi-Shin Chen
 
lecture1-intro.ppt
lecture1-intro.pptlecture1-intro.ppt
lecture1-intro.pptIshaXogaha
 
[246]QANet: Towards Efficient and Human-Level Reading Comprehension on SQuAD
[246]QANet: Towards Efficient and Human-Level Reading Comprehension on SQuAD[246]QANet: Towards Efficient and Human-Level Reading Comprehension on SQuAD
[246]QANet: Towards Efficient and Human-Level Reading Comprehension on SQuADNAVER D2
 
IE: Named Entity Recognition (NER)
IE: Named Entity Recognition (NER)IE: Named Entity Recognition (NER)
IE: Named Entity Recognition (NER)Marina Santini
 
Neural machine translation by jointly learning to align and translate.pptx
Neural machine translation by jointly learning to align and translate.pptxNeural machine translation by jointly learning to align and translate.pptx
Neural machine translation by jointly learning to align and translate.pptxssuser2624f71
 
Protocols of Interaction: Best Current Practices
Protocols of Interaction: Best Current PracticesProtocols of Interaction: Best Current Practices
Protocols of Interaction: Best Current PracticesC4Media
 
5_RNN_LSTM.pdf
5_RNN_LSTM.pdf5_RNN_LSTM.pdf
5_RNN_LSTM.pdfFEG
 
Balancing Infrastructure with Optimization and Problem Formulation
Balancing Infrastructure with Optimization and Problem FormulationBalancing Infrastructure with Optimization and Problem Formulation
Balancing Infrastructure with Optimization and Problem FormulationAlex D. Gaudio
 
Detecting Misleading Headlines in Online News: Hands-on Experiences on Attent...
Detecting Misleading Headlines in Online News: Hands-on Experiences on Attent...Detecting Misleading Headlines in Online News: Hands-on Experiences on Attent...
Detecting Misleading Headlines in Online News: Hands-on Experiences on Attent...Kunwoo Park
 
Anthiil Inside workshop on NLP
Anthiil Inside workshop on NLPAnthiil Inside workshop on NLP
Anthiil Inside workshop on NLPSatyam Saxena
 

Similar to #02 Next RNN (20)

Deep Learning for Natural Language Processing
Deep Learning for Natural Language ProcessingDeep Learning for Natural Language Processing
Deep Learning for Natural Language Processing
 
Deep Learning for Natural Language Processing by Roopal Garg
Deep Learning for Natural Language Processing by Roopal GargDeep Learning for Natural Language Processing by Roopal Garg
Deep Learning for Natural Language Processing by Roopal Garg
 
Deep learning nlp
Deep learning nlpDeep learning nlp
Deep learning nlp
 
Dataworkz odsc london 2018
Dataworkz odsc london 2018Dataworkz odsc london 2018
Dataworkz odsc london 2018
 
DeepLearning 10章 回帰結合型ニューラルネットワークと再帰型ネットワーク
DeepLearning 10章 回帰結合型ニューラルネットワークと再帰型ネットワークDeepLearning 10章 回帰結合型ニューラルネットワークと再帰型ネットワーク
DeepLearning 10章 回帰結合型ニューラルネットワークと再帰型ネットワーク
 
Devoxx traitement automatique du langage sur du texte en 2019
Devoxx   traitement automatique du langage sur du texte en 2019 Devoxx   traitement automatique du langage sur du texte en 2019
Devoxx traitement automatique du langage sur du texte en 2019
 
[系列活動] 資料探勘速遊
[系列活動] 資料探勘速遊[系列活動] 資料探勘速遊
[系列活動] 資料探勘速遊
 
October hug
October hugOctober hug
October hug
 
CSCE181 Big ideas in NLP
CSCE181 Big ideas in NLPCSCE181 Big ideas in NLP
CSCE181 Big ideas in NLP
 
Quick tour all handout
Quick tour all handoutQuick tour all handout
Quick tour all handout
 
lecture1-intro.ppt
lecture1-intro.pptlecture1-intro.ppt
lecture1-intro.ppt
 
lecture1-intro.ppt
lecture1-intro.pptlecture1-intro.ppt
lecture1-intro.ppt
 
[246]QANet: Towards Efficient and Human-Level Reading Comprehension on SQuAD
[246]QANet: Towards Efficient and Human-Level Reading Comprehension on SQuAD[246]QANet: Towards Efficient and Human-Level Reading Comprehension on SQuAD
[246]QANet: Towards Efficient and Human-Level Reading Comprehension on SQuAD
 
IE: Named Entity Recognition (NER)
IE: Named Entity Recognition (NER)IE: Named Entity Recognition (NER)
IE: Named Entity Recognition (NER)
 
Neural machine translation by jointly learning to align and translate.pptx
Neural machine translation by jointly learning to align and translate.pptxNeural machine translation by jointly learning to align and translate.pptx
Neural machine translation by jointly learning to align and translate.pptx
 
Protocols of Interaction: Best Current Practices
Protocols of Interaction: Best Current PracticesProtocols of Interaction: Best Current Practices
Protocols of Interaction: Best Current Practices
 
5_RNN_LSTM.pdf
5_RNN_LSTM.pdf5_RNN_LSTM.pdf
5_RNN_LSTM.pdf
 
Balancing Infrastructure with Optimization and Problem Formulation
Balancing Infrastructure with Optimization and Problem FormulationBalancing Infrastructure with Optimization and Problem Formulation
Balancing Infrastructure with Optimization and Problem Formulation
 
Detecting Misleading Headlines in Online News: Hands-on Experiences on Attent...
Detecting Misleading Headlines in Online News: Hands-on Experiences on Attent...Detecting Misleading Headlines in Online News: Hands-on Experiences on Attent...
Detecting Misleading Headlines in Online News: Hands-on Experiences on Attent...
 
Anthiil Inside workshop on NLP
Anthiil Inside workshop on NLPAnthiil Inside workshop on NLP
Anthiil Inside workshop on NLP
 

More from Terence Huang

# Can we trust ai. the dilemma of model adjustment
# Can we trust ai. the dilemma of model adjustment# Can we trust ai. the dilemma of model adjustment
# Can we trust ai. the dilemma of model adjustmentTerence Huang
 
# 手把手 Python 資料分析 I
# 手把手 Python 資料分析 I# 手把手 Python 資料分析 I
# 手把手 Python 資料分析 ITerence Huang
 
# From statistics to ai
# From statistics to ai# From statistics to ai
# From statistics to aiTerence Huang
 
Deep Learning Advance: # Capsule net
Deep Learning Advance: # Capsule netDeep Learning Advance: # Capsule net
Deep Learning Advance: # Capsule netTerence Huang
 
Deep Learning Advance: #01 Domain Adaptation
Deep Learning Advance: #01 Domain AdaptationDeep Learning Advance: #01 Domain Adaptation
Deep Learning Advance: #01 Domain AdaptationTerence Huang
 
Deep Learning Basic: #01 start from CNN
Deep Learning Basic: #01 start from CNNDeep Learning Basic: #01 start from CNN
Deep Learning Basic: #01 start from CNNTerence Huang
 
從統計到資料科學
從統計到資料科學從統計到資料科學
從統計到資料科學Terence Huang
 

More from Terence Huang (8)

# Can we trust ai. the dilemma of model adjustment
# Can we trust ai. the dilemma of model adjustment# Can we trust ai. the dilemma of model adjustment
# Can we trust ai. the dilemma of model adjustment
 
# 手把手 Python 資料分析 I
# 手把手 Python 資料分析 I# 手把手 Python 資料分析 I
# 手把手 Python 資料分析 I
 
# From statistics to ai
# From statistics to ai# From statistics to ai
# From statistics to ai
 
Deep Learning Advance: # Capsule net
Deep Learning Advance: # Capsule netDeep Learning Advance: # Capsule net
Deep Learning Advance: # Capsule net
 
Deep Learning Advance: #01 Domain Adaptation
Deep Learning Advance: #01 Domain AdaptationDeep Learning Advance: #01 Domain Adaptation
Deep Learning Advance: #01 Domain Adaptation
 
Deep Learning Basic: #01 start from CNN
Deep Learning Basic: #01 start from CNNDeep Learning Basic: #01 start from CNN
Deep Learning Basic: #01 start from CNN
 
從統計到資料科學
從統計到資料科學從統計到資料科學
從統計到資料科學
 
SQL 語言簡介
SQL 語言簡介 SQL 語言簡介
SQL 語言簡介
 

Recently uploaded

DBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfDBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfJohn Sterrett
 
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPramod Kumar Srivastava
 
9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home Service9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home ServiceSapana Sha
 
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degreeyuu sss
 
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改yuu sss
 
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一F sss
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptxthyngster
 
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Sapana Sha
 
RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.natarajan8993
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxStephen266013
 
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...Boston Institute of Analytics
 
GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]📊 Markus Baersch
 
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝soniya singh
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfSocial Samosa
 
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls DubaiDubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls Dubaihf8803863
 
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDINTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDRafezzaman
 
Predicting Salary Using Data Science: A Comprehensive Analysis.pdf
Predicting Salary Using Data Science: A Comprehensive Analysis.pdfPredicting Salary Using Data Science: A Comprehensive Analysis.pdf
Predicting Salary Using Data Science: A Comprehensive Analysis.pdfBoston Institute of Analytics
 
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...dajasot375
 

Recently uploaded (20)

DBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdfDBA Basics: Getting Started with Performance Tuning.pdf
DBA Basics: Getting Started with Performance Tuning.pdf
 
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptxPKS-TGC-1084-630 - Stage 1 Proposal.pptx
PKS-TGC-1084-630 - Stage 1 Proposal.pptx
 
9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home Service9654467111 Call Girls In Munirka Hotel And Home Service
9654467111 Call Girls In Munirka Hotel And Home Service
 
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
毕业文凭制作#回国入职#diploma#degree澳洲中央昆士兰大学毕业证成绩单pdf电子版制作修改#毕业文凭制作#回国入职#diploma#degree
 
Call Girls in Saket 99530🔝 56974 Escort Service
Call Girls in Saket 99530🔝 56974 Escort ServiceCall Girls in Saket 99530🔝 56974 Escort Service
Call Girls in Saket 99530🔝 56974 Escort Service
 
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
专业一比一美国俄亥俄大学毕业证成绩单pdf电子版制作修改
 
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
办理学位证中佛罗里达大学毕业证,UCF成绩单原版一比一
 
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptxEMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM  TRACKING WITH GOOGLE ANALYTICS.pptx
EMERCE - 2024 - AMSTERDAM - CROSS-PLATFORM TRACKING WITH GOOGLE ANALYTICS.pptx
 
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
Saket, (-DELHI )+91-9654467111-(=)CHEAP Call Girls in Escorts Service Saket C...
 
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
Deep Generative Learning for All - The Gen AI Hype (Spring 2024)
 
RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.RABBIT: A CLI tool for identifying bots based on their GitHub events.
RABBIT: A CLI tool for identifying bots based on their GitHub events.
 
B2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docxB2 Creative Industry Response Evaluation.docx
B2 Creative Industry Response Evaluation.docx
 
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
NLP Data Science Project Presentation:Predicting Heart Disease with NLP Data ...
 
GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]GA4 Without Cookies [Measure Camp AMS]
GA4 Without Cookies [Measure Camp AMS]
 
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
Call Girls in Defence Colony Delhi 💯Call Us 🔝8264348440🔝
 
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdfKantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
Kantar AI Summit- Under Embargo till Wednesday, 24th April 2024, 4 PM, IST.pdf
 
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls DubaiDubai Call Girls Wifey O52&786472 Call Girls Dubai
Dubai Call Girls Wifey O52&786472 Call Girls Dubai
 
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTDINTERNSHIP ON PURBASHA COMPOSITE TEX LTD
INTERNSHIP ON PURBASHA COMPOSITE TEX LTD
 
Predicting Salary Using Data Science: A Comprehensive Analysis.pdf
Predicting Salary Using Data Science: A Comprehensive Analysis.pdfPredicting Salary Using Data Science: A Comprehensive Analysis.pdf
Predicting Salary Using Data Science: A Comprehensive Analysis.pdf
 
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
Indian Call Girls in Abu Dhabi O5286O24O8 Call Girls in Abu Dhabi By Independ...
 

#02 Next RNN

  • 1. Deep Learning Basic #02 Next RNN Terence Huang
  • 2. 自我介紹 學經歷 緯創資通 高級工程師 (2015/3 ~) 長庚醫院 研究助理 (2013/9 ~2014/11) 中山大學 應數系統計碩士 (2011/9 ~ 2013/7) 高雄師大 數學系學士 (2005/9 ~ 2009/7) 獲獎 2017 台南智慧黑客松智慧醫療組第二名 2012 中山高大統計新秀 特殊經歷 訪問 MIT 的工程師 (2017/10 ~ 2018/10) Pytorch Kaohsiung 讀書會的社長 2 Terence Huang
  • 3. 進入 deep learning 文字分析前 • 怎麼把文字塞進 neural network 3 這 是 貓
  • 4. 進入 deep learning 文字分析前 • One-hot vector 4 這 是 貓 1,0,0 0,1,0 0,0,1
  • 5. 進入 deep learning 文字分析前 • One-hot vector by character 5 這 是 大 1,0,0,0 0,1,0,0 0,0,1,0 象 0,0,1,0
  • 6. 進入 deep learning 文字分析前 • One-hot vector by token 6 這 是 大象 1,0,0 0,1,0 0,0,1
  • 7. 進入 deep learning 文字分析前 • 只能放 one-hot vector 的 feature? 7 Feature 意義 BOW, Bag of word 文中每個字出現的次數/比例 TF-IDF 文中每個字的獨特程度 Word2vec 考慮上下文對每個字的意義影響,以向量做表示 Doc2vec 每個文章的意義,以向量做表示 LDA, Latent Dirichlet Allocation 每個文章中的主題比例
  • 8. BOW, Bag of words • 意義:文中每個字出現的次數/比例 • 用途:用詞習慣比較、文章抄襲、… 8
  • 9. BOW, Bag of words • 計算方式: Counting the number of times each meaningful word appears in each document. Remove stop words. 9 "With all this stuff going down at the moment with MJ i've started listening to his music, watching the odd documentary here and there, watched The Wiz and watched Moonwalker again. Maybe i just want to get a certain insight into this guy who i thought was really cool in the eighties just to maybe make up my mind whether he is guilty or innocent. Moonwalker is part biography, part feature film which i remember going to see at the cinema when it was originally released. Some of it has subtle messages about MJ's feeling towards the press and also the obvious message of drugs are bad m'kay. <br/><br/>..." feature Count also 2 bad 3 film 2 get 1 like 3 made 1 make 1 … … Document 1 𝑡1 𝑡2 𝑡7 ⋮ ⋮
  • 10. BOW, Bag of words • 計算方式: We have many documents, each document has different meaningful words. 10 also bad film get like made … 2 3 2 1 3 1 … film films like made man many … 1 2 1 1 1 2 … also film get good movie one … 1 4 1 1 1 2 … even film made movie much time … 3 1 1 1 1 1 … Document 1 Document 2 Document 3 Document 4
  • 11. BOW, Bag of words • 計算方式: Use the most frequent words in all documents. 11 film movie one like good even … Document 1 2 3 4 3 0 0 … Document 2 1 1 2 1 0 0 … Document 3 4 1 2 0 1 0 … Document 4 1 1 0 0 0 3 … … … … … … … … Document 1000 0 2 0 3 1 2 … 1653 1630 1088 769 664 501 … 𝑡1 𝑡2 𝑡6⋯ ⋯
  • 12. BOW, Bag of words • 計算方式: Use the most frequent words in all documents. 12 film movie one like good even … Document 1 2% 3% 4% 3% 0% 0% … 100% Document 2 1% 1% 2% 1% 0% 0% … 100% Document 3 4% 1% 2% 0% 1% 0% … 100% Document 4 1% 1% 0% 0% 0% 3% … 100% … … … … … … … 100% Document 1000 0% 2% 0% 3% 1% 2% … 100%
  • 13. TFIDF, Term frequency–inverse document frequency • 意義:文中每個字的獨特程度,獨特性是跟其他的文一起比 • 用途:用來找出一篇文章中, 足以代表這篇文章的關鍵字的方法 13
  • 14. TFIDF, Term frequency–inverse document frequency • 計算方式:尋找這樣的關鍵字, 要考慮以下兩個要素 - TF, Term Frequency • 這個字在這篇文章中出現的頻率 - IDF, Inverse-Document Frequency • 在所有的文章中,有幾篇文章有這個字 • TF-IDF 值越大的, 越可以作為代表這篇文章的關鍵字 14 𝑇𝐹𝐼𝐷𝐹 = 𝑇𝐹 × Inv 𝐷𝐹 = 𝑛 𝑤 𝑑 × log2 𝑁 𝑁 𝑤 𝑛 𝑤 𝑑 :文章 𝑑 中,文字 𝑤 出現的次數 𝑁:表示總共有幾篇文章 𝑁 𝑤:表示有文字 𝑤 的文章有幾篇
  • 15. TFIDF, Term frequency–inverse document frequency • Example:Reuters Corpus (10788 篇文章) - 其中某篇新聞內容 • GRAIN SHIPS LOADING AT PORTLAND There were three grain ships loading and two ships were waiting to load at Portland , according to the Portland Merchants Exchange . - 𝑇𝐹𝐼𝐷𝐹portland = 3 × log2 10788 28 ≈ 25.769, 10788 篇中有 28 篇出現 portland - 𝑇𝐹𝐼𝐷𝐹𝑡𝑜 = 2 × log2 10788 6944 ≈ 1.271, 10788 篇中有 6944 篇出現 to 15
  • 16. Word2vec • 意義:考慮上下文對每個字的意義影響,以向量做表示 • 用途:相似字、雙語翻譯、Analogies (ex."king - man + woman = queen.") 16 之前編碼 Word2vec dog Id222 0,1,0,0,0,0,0,0 0.12,0.13,0.01,0.01,0.01 cat Id357 0,0,0,0,0,0,1,0 0.12,0.12,0.01,0.01,0.01 car Id358 0,0,0,0,0,0,0,1 0.01,0.01,0.33,0.40,0.25
  • 17. Word2vec • 計算方式: Skip-Gram - ex. Doc1 = I have a cat. I love cat and dog. - 7 個不同單字 8 個 pair 17 pair * i have i have a have a cat cat and dog 字 i have a ⋯ and 上下文 [*, have] [i, a] [have, cat] [cat, dog] 範例
  • 18. Word2vec • 計算方式: Skip-Gram - ex. have a cat → a, [have, cat] 18 0 0 1 0 0 0 0 0.1 ⋮ 0.2 a 0 1 0 0 0 0 0 0 0 0 1 0 0 0 have cat 0.1 0.9 0.0 0.0 0.1 0.3 0.2 0.1 0.1 0.0 0.0 0.1 0.4 0.2 ∑ ∑ ∑ ∑ ∑ 越像越好 轉出的向量 0.1 ⋮ 0.2 one hot vector one hot vector one hot vector 越像越好 ∑ ∑ ∑
  • 19. Word2vec • 意義:考慮上下文對每個字的意義影響,以向量做表示 • 用途:相似字、雙語翻譯、Analogies (ex."king - man + woman = queen.") 19 之前編碼 Word2vec dog Id222 0,1,0,0,0,0,0,0 0.12,0.13,0.01,0.01,0.01 cat Id357 0,0,0,0,0,0,1,0 0.12,0.12,0.01,0.01,0.01 car Id358 0,0,0,0,0,0,0,1 0.01,0.01,0.33,0.40,0.25
  • 21. Doc2vec • 計算方式: 借用 word2vec 的結果,平均內文 meaningful word 的向量 21 I have a cat. I love cat and dog. Document 1 0.12,0.12,0.01,0.01,0.01 0.12,0.13,0.01,0.01,0.01 I have a cat cat I love and dog 0.12,0.12,0.01,0.01,0.01 0.01,0.01,0.01,0.01,0.95 0.01,0.01,0.01,0.01,0.95 0.01,0.01,0.01,0.95,0.01 0.39,0.40,0.06,1.00,1.00 0.39,0.40,0.06,1.00,1.00 6 文章的意義不單一?
  • 22. LDA, Latent Dirichlet Allocation • 意義:每個主題佔內文的比例 22 0.2 0.1 0.4 0.3 0.3 0.5 0.1 0.1 The William Randolph Hearst Foundation will give $1.25 million to Lincoln Center, Metropolitan … ''Our board felt that we had a real opportunity to make a mark on the future of … Documents … LDA … Arts Budgets Children Education
  • 23. LDA, Latent Dirichlet Allocation • 意義:每個主題佔內文的比例 23 Arts 0.461 * music + 0.134 * movie + … Budgets 0.211 * tax + 0.035 * money + … Children 0.309 * children + 0.241 * family + … Education 0.217 * school + 0.222 * teacher + … The William Randolph Hearst Foundation will give $1.25 million to Lincoln Center, Metropolitan … ''Our board felt that we had a real opportunity to make a mark on the future of … Topics Documents … LDA
  • 24. LDA, Latent Dirichlet Allocation • 意義:每個主題佔內文的比例 24 Arts 0.461 * music + 0.134 * movie + … Budgets 0.211 * tax + 0.035 * money + … Children 0.309 * children + 0.241 * family + … Education 0.217 * school + 0.222 * teacher + … 0.2 0.1 0.4 0.3 0.3 0.5 0.1 0.1 The William Randolph Hearst Foundation will give $1.25 million to Lincoln Center, Metropolitan … ''Our board felt that we had a real opportunity to make a mark on the future of … Topics Documents … LDA
  • 25. 進入 deep learning 文字分析前 • 只能放 one-hot vector 的 feature? 25 Feature 意義 BOW, Bag of word 文中每個字出現的次數/比例 TF-IDF 文中每個字的獨特程度 Word2vec 考慮上下文對每個字的意義影響,以向量做表示 Doc2vec 每個文章的意義,以向量做表示 LDA, Latent Dirichlet Allocation 每個文章中的主題比例
  • 26. 動手時間 Q&A 1. 程式碼理解 - Copy & Paste 範例程式: https://github.com/Terence0408/Teach_code - 解析程式 - 改動程式 - 做點應用 26
  • 27. 正式進入 RNN/LSTM • Motivation: Why Learn recurrent neural network? - Language Modeling - Key: speech recognition, machine translation, image captioning, … 27 RNN are popular models that have shown great promise in many Language Modeling tasks
  • 28. 正式進入 RNN/LSTM • Task1: predict {Yes, No} by sentence • Task2: predict next words by previous words in sentence • Ponder the question “how is that even possible?” 28 Input Output the clouds are in the sky I grew up in France…… I speak fluent French Input Output the clouds are in the sky Yes the clouds are in the ground No
  • 29. RNN , recurrent neural networks • RNN (Recurrent Neural Networks) 29 𝑿 𝟏 𝒉 𝟏 𝑿 𝟐 𝒉 𝟐 𝒉 𝟎 𝒉 𝟏 Pass weight …….. ……..
  • 30. RNN, recurrent neural networks • RNN (Recurrent Neural Networks) 30 In this moment – Input: 𝑋𝑡 & 𝒉 𝒕−𝟏 – Output: 𝒉 𝒕
  • 31. RNN, recurrent neural networks • RNN (Recurrent Neural Networks) 31 In this moment – Input: 𝑋𝑡+1 & 𝒉 𝒕 – Output: 𝒉 𝒕+𝟏 In this moment – Input: 𝑋𝑡 & 𝒉 𝒕−𝟏 – Output: 𝒉 𝒕
  • 32. LSTM, Long Short Term Memory Networks • RNN is Good. But … - Sometimes, we only need to look at recent information to perform the present task. - Long-Term Dependencies problem 32 Input Output I grew up in France…… I speak fluent French Important information, but … Too far to pass information/weight to output
  • 33. LSTM, Long Short Term Memory Networks 33 RNN LSTM
  • 34. LSTM, Long Short Term Memory Networks • LSTM (Long Short Term Memory Networks) 34 Throw old info. Store new info. Update memory 𝑓𝑡: 上一步 memory cell 使用比例 C 𝑡: 更新這一步的 memory cell 𝑜𝑡: 下一步的 memory cell 使用比例 ℎ 𝑡: 輸入給下一步的資訊
  • 35. LSTM, Long Short Term Memory Networks • 權重計算 - Backpropagation: 傳遞 預測誤差 來更新權重 1. 計算預測誤差 2. 傳遞誤差讓前一層用 SGD 找最適權重 3. 計算更新前一層後的預測誤差 4. 一直把誤差傳遞給前面層做更新 35
  • 36. LSTM, Long Short Term Memory Networks • 修正權重: Backpropagation through time • Problem: Compute cost & vanishing gradient 36
  • 37. LSTM, Long Short Term Memory Networks • 修正權重: Truncated Backpropagation through time 37 True Sequence length: 6 Errors truncated to 3 steps Tensorflow-style Sequence length: 3 Errors truncated to 3 steps
  • 38. 解析程式 • imdb_lstm.py 電影評論預測 1. 引入 Keras 套件 2. 模型結構 3. 資料 (Image & label) 擺放 4. 預測結果 5. 參數調教 38
  • 39. 解析範例程式 2. 模型結構 39 建立 deep learning 環境叫 model 設定預測誤差參數 放入資料開始跑模型 同時預測 Test set 結果 與訓練模型間關係:獨立 批次跑,一次跑多少筆
  • 40. 解析範例程式 3. 資料 (Image & label) 擺放 40 Token 轉化向量的維度 一個句子要有幾個 token 從 imbd dataset 取出現次數前 20000的 token 處裡句子 token 數不足 Pad(通常補空格)
  • 41. 動手時間 Q&A • Copy & Paste 範例程式: https://github.com/keras-team/keras/blob/master/examples/imdb_lstm.py • 嘗試各種參數組合 • 換筆資料 • 換別的模型結構 • 記得,把Epoch 設 1 & 資料切小一點 41
  • 42. RNN/LSTM 應用 42 Signal, stock Seq2seq: 對話機器人 POS/NER tagging
  • 44. Q&A Thanks for your attention! 44