[NLP] νΉν λ°μ΄ν°λ‘ Topic Modelingμ μ§νν΄λ³΄μ
μμνλ©°
νλΆμμμ μ§ννλ Topic Modeling νλ‘μ νΈμ λν΄ μμ±νλ €κ³ νλ€.
NLPμ κ΄μ¬μ΄ μκΈ°κΈ° μμνμ¬ λ°μ΄ν°μ΄λΌλ¦¬ν±μ€ μμ
μ μκ°νλλ°, μ΄μ’κ²λ NLPμ λν κ°λ
κ³Ό, μ€μ΅μ μ§νν΄λ³Ό μμμλ€. κ·Έ μ§μμ λ°νμΌλ‘ μ¬λ¬κ°μ§ νλ‘μ νΈλ₯Ό μ§ννλλ°, κ·Έ μ€ νλμ΄λ€!
νλ‘μ νΈ λ§λ¬΄λ¦¬ λ¨κ³μ λ ν¬νΈλ‘ μμ±νμ¬ κ³Όμ λ‘ μ μΆν κ²½νμ΄ μμ΄μ, μκ°μ΄ μ§λ μ§κΈμλ μ΄λ κ² κΈλ‘ λ¨κΈΈ μ μκ²λμλ€. μλ£μ λ¬Έμνμ λν μ€μμ±μ λ€μκΈ κΉ¨λ«λ μκ°μ΄λ€ :)
-- λ³Έ νλ‘μ νΈλ νκ΅ κ³Όμ κ²Έ νλ‘μ νΈλ‘ μ§νν λ΄μ©μ λλ€ :)
1. μ£Όμ μ μ
1.1 νλ‘μ νΈ μ£Όμ
Quantum-dot Display κΈ°μ μ νΉν λ°μ΄ν°μ λν LDA
1.2 νλ‘μ νΈ λͺ©ν
Quantum dot displayμ κ΄ν 794κ°μ νΉνμ Topicμ λΉ λ₯΄κ² νμ ν μμλ Topic Modelingμ μ§ννκ³ μ νλ€.
νΉνλ°μ΄ν°λ λ무 λμ³λκ³ , κΈ°μ μ μΈ μ©μ΄κ° μ΄λ ΅κΈ° λλ¬Έμ μ΄ Topic Modeling μ΄ μ°μ μμ λ리 μ¬μ©λ μ μμ κ²μ΄λΌκ³ μκ°λλ€!
2. λΆμ κ³Όμ
2.1 λ°μ΄ν° μμ§
2.1.1 νμ© λ°μ΄ν°
λΆμ λ°μ΄ν°λ λ―Έκ΅ νΉνμ² νΉν DB λ΄ μ 체 κΈ°κ°λμ μΆμ, κ³΅κ° λ° λ±λ‘ λμ΄μλ νΉνλ€ μ€μ μ μ νμλ€. λκ΅λνκ΅μμ μ§μνλ νΉν κ²μ μ¬μ΄νΈ( λ¬΄μ¨ μ¬μ΄νΈμλμ§ κΉλ¨Ήμλ€... μ°Ύλλλ‘ μ λ‘λ νκ² μ΅λλ€.!) μ Quantum-dot displayμ μ μ¬ν μλ―Έλ‘ μ°μ΄λ λ¨μ΄λ₯Ό μλ <ν1>κ³Ό κ°μ΄ μ 리νμ¬ κ²μμμ μμ±νμλ€.
Quantum - dot display κ΄λ ¨ νΉν κ²μμ |
TI = ("Quantum*" or "QD") AND ("display*") or ("QLED" or "QLCD") |
<ν 1> Quantum-dot display νΉν κ²μμ
νΉν κ²μ κ²°κ³Ό μ΄ 794건μ νΉνκ° κ²μλμκ³ , ν΄λΉ νΉνμ λ²νΈ, λͺ μΉ, μμ½, μΆμλ²νΈ, μ 체μ²κ΅¬νμ κΈ°μ€ λ±μ csv ννμ λ°μ΄ν°λ‘ λ€μ΄λ°μλ€. λ³Έ λ ν¬νΈμμλ λ€μ΄λ°μ λ°μ΄ν°λ₯Ό λμμΌλ‘ LDAλ₯Ό μννλ€. <κ·Έλ¦Ό 2>λ νΉν κ²μ κ²°κ³Όλ₯Ό λνλΈ κ²μ΄κ³ , <κ·Έλ¦Ό 3>μ λ€μ΄λ°μ λ°μ΄ν°μ μμλ₯Ό λνλΈ κ²μ΄λ€.
2.2 LDA Topic Modeling
R studio νλ‘κ·Έλ¨μ μ΄μ©νμ¬ 2.1μμ μμ§ν λ°μ΄ν°λ₯Ό κΈ°λ°μΌλ‘ Topic Modelingμ μννμλ€. LDA Topic Modelingμ μ 체μ μΈ νλ‘μΈμ€λ LDA νκ²½ ꡬμ±, λ§λμΉ (Corpus) μμ±, Term-doc Matrix μμ±, LDAκ³μ°, LDA κ²°κ³Ό κ³μ° λμΆ μμΌλ‘ μ§ννμλ€.
2.2.1 LDA ν경ꡬμ±
R studioμμ LDA Topic Modelingμ νμν ldatuning, topicmodels, tm, slam, ida ν¨ν€μ§λ₯Ό μ€μΉ ν λΌμ΄λΈλ¬λ¦¬λ‘ λΆλ¬μ LDA Topic Modelingμ μν νκ²½μ ꡬμ±νμλ€. μ΄ν “quntum_dot_data.csv”νμΌμ λΆλ¬μ€κ³ “μ 체 μ²κ΅¬ν”μ΄μ λν λΆμμ μ§ννκΈ° μν΄ μ΄λ₯Ό target_docμΌλ‘ μ§μ νμλ€.
# ν¨ν€μ§ μ€μΉ λ° νΈμΆ
install.packages('ldatuning')
install.packages('topicmodels')
install.packages('tm')
install.packages('slam')
install.packages('lda')
library(ldatuning)
library(topicmodels)
library(tm)
library(slam)
library(lda)
# λ°μ΄ν° λΆλ¬μ€κΈ° λ° μ μ²λ¦¬
setwd("C:\\Users\\my\\Desktop")
lda_source<-read.csv("quantum_dot_data.csv",stringsAsFactors = FALSE, header = FALSE)
target_doc<-lda_source[,6]
2.2.2 λ§λμΉ (Corpus) μμ±
tmν¨ν€μ§μ VectorSource ν¨μλ₯Ό μ΄μ©νμ¬ Corpusλ₯Ό μμ±νλ€. μ΄ν, TermDocumentMatrix ν¨μλ₯Ό μ΄μ©νμ¬ μ«μλ κΈ°νΈ, λΉ λ°μ΄ν°λ₯Ό μ κ±°ν΄μ£Όμλ€. λν λ§μ΄ μ°μ΄λ ν΅μ¬κ΅¬μ‘°μΈ claim, comprising, including, includesλ₯Ό stop words λ‘ μ²λ¦¬ν΄ μ£Όμλ€.
# corpus μμ±
doc_vec<-VectorSource(target_doc)
corpus<-Corpus(doc_vec)
# term document matrix
tdm = TermDocumentMatrix(corpus, control = list(removeNumbers = T,
removePunctuation = T,
stemming = FALSE,
stopwords = c(stopwords('SMART'),
'comprising','including',
'includes'),
omit_empty = T))
word.count = as.array(rollup(tdm,2))
word.order = order(word.count, decreasing = T)[1:1000] ## λ§μ΄ μ°μΈ λ¨μ΄λλ‘ μ¬λ¦Όμ°¨μ
freq.word = word.order[1:1000]
2.2.3 Term-Doc Matrix μμ±
λΆμλ λ°μ΄ν°μ ν¬κΈ°κ° ν¬κΈ° λλ¬Έμ LDA λ₯Ό κ³μ°νλλ°μ μκ°μ΄ λ§μ΄ μμλλ€. μ΄λ₯Ό κ°μ νκΈ° μν΄ μμ 1000κ°μ λ¨μ΄λ§ μ¬μ©νκ²λ Term-Doc Matrixλ₯Ό μμ±νλ€.
# dtm μμ±
dtm = as.DocumentTermMatrix(tdm[freq.word,])
dtm.matrix<-as.matrix(dtm)
dtm
2.2.4 LDA κ³μ°
lda ν¨ν€μ§λ₯Ό μ¬μ©νμ¬ μμ μ€λΉν lda λ°μ΄ν°λ₯Ό κΈ°λ°μΌλ‘ lda λΆμμ μ€ννλ€. λΆμ μ Gibbs Samplingμ μ¬μ©νλ€. ν ν½ κ°μ Kλ 50κ°λ‘ μ§μ , interation κ°μ 500, burninκ° 100, λ¬Έμ λ΄ νλ₯ λΆν¬λ 0.01, νλμ topic μμμμ hyper parameterλ 0.01λ‘ κ΅¬μ±νμλ€.
ldaform=dtm2ldaformat(dtm, omit_empty=T) ## dtmμ LDA ν¬λ©§μ λ°μ΄ν°λ‘ λ³ν
result.lda = lda.collapsed.gibbs.sampler(documents = ldaform$documents,
K = 50,
vocab = ldaform$vocab,
num.iterations = 500,
burnin = 100,
alpha = 0.01,
eta = 0.01)
#alpha = λ¬Έμλ΄μ νλ₯ λΆν¬ / eta = λ¬Έμλ΄ μ£Όμ λ³ νλ₯ λΆν¬
2.2.5 LDA κ³μ° κ²°κ³Ό λμΆ
μ£Όμ λ³ ν€μλ 20κ°μ, μ£Όμ λ³ ν΅μ¬ λ¬Έμ 10κ°λ₯Ό λμΆν΄μ κ°κ°μ νμΌλ‘ μ μ₯νμλ€.
# λΆμ κ²°κ³Ό νμΈ
attributes(result.lda)
dim(result.lda$topics)
result.lda$topics
document_sums <- result.lda$document_sums
# μ£Όμ λ³ ν€μλ λμΆ λ° μ μ₯
topic_word <- top.topic.words(result.lda$topics, num.words = 20)
write.csv(topic_word, "topic_word.csv")
# μ£Όμ λ³ ν΅μ¬ λ¬Έμ λμΆ λ° μ μ₯
num.documents = 10
doc_topic <- top.topic.documents(document_sums, num.documents, alpha = 0.1)
write.csv(doc_topic, "doc_topic.csv")
3. κ²°κ³Ό λ° μμ¬μ
3.1 κ²°κ³Ό
λμΆλ κ²°κ³Όμ μΌλΆλ₯Ό λ°μ·νμ¬ μ£Όμ λ³ μμ ν€μλ λ° λ¬Έμμ μΌλΆλ₯Ό ν΄μν΄ λ³΄μλ€. λμΆλ κ²°κ³Όμ λ κ°μ νμΌμ μλ <κ·Έλ¦Ό 4> μ <κ·Έλ¦Ό 5> μ 첨λΆνμλ€.
3.2 ν΄μ
μλ <ν 2> λ₯Ό λ³΄κ³ λ€μκ³Ό κ°μ΄ ν΄μν μ μμλ€. μμμ (Quantum dot) displayμ pixel structureμ ꡬμ±(comprises)μ λν νΉνλΌλ κ²μ μ μΆν΄ λ³Ό μ μλ€. pixelμ΄ κ°μ(respective) λ€λ₯Έ diodeλ‘ configured λμ΄ μκ³ , pixelμ΄ κ²Ήκ²Ήμ΄ μμΈ layer ꡬ쑰μμ μ μ μλ€. μ΄ μ£Όμ λ₯Ό κ°κ³ μλ νΉνλ 303λ² νΉν, 656λ² νΉν, 420λ² νΉν, 265λ² νΉν λ±μ΄ μμΌλ©°, <ν 3>μ μ΄ μ£Όμ λ₯Ό κ°μ§ νΉν μμ 10κ°λ₯Ό ννν΄ λμλ€.
Topic 4 | pixel | plurality | computational | layers | type |
display | diode | defined | configured | polygon | |
claim | pixels | structure | system | portion | |
comprise | respective | regions | coupled | method |
<ν 2> Topic 4μ μ£Όμ λ³ μμ ν€μλ 20κ°
Topic 4 | 303 | 656 | 420 | 265 | 418 |
271 | 434 | 597 | 261 | 612 |
<ν 3> Topic 4μ μ£Όμ λ³ ν΅μ¬ μμ λ¬Έμ 10κ°
3.3 μμ¬μ
νΉν λ°μ΄ν°μ LDAλ₯Ό μ μ©ν¨μΌλ‘μ¨, μλ§μ νΉν μ€ μ¬μ©μκ° κ΄μ¬μλ νΉμ νΉν λ¬Έμλ₯Ό κ΅°μ§ν ν μ μλ€. μ΄λ₯Ό ν΅ν΄ νΉμ μ£Όμ μ λν νν©, λ¬Έμ μ , ν΄κ²°μ± μ νμ ν μ μλ μΈμ¬μ΄νΈλ₯Ό μ»μ μ μλ€. λ νΉμ μ£Όμ λ° κ΄λ ¨μ± λμ λ¨μ΄λ€μ λΆμνλ©΄μ ν΄λΉ κΈ°μ μ νν© νμ , μ°κ΅¬ λν₯μ νμ ν μ μμ κ²μ΄λ€.
4. κ²°λ‘
TV λ° κ°μ μ ν μμ₯μ μ°¨μΈλ κΈ°μ λ‘ μ£Όλͺ©λ°κ³ μλ quantum-dot display κΈ°μ μ λμ μ±μ₯λ₯ μ 보μ΄κ³ μλ€. λ°λΌμ quantum-dot displayμ κ΄ν νΉν λ°μ΄ν°λ₯Ό LDAλ‘ λΆμνμ¬ topicλ³λ‘ clustering νμλ€. λν ν΄λΉ topicμ λν ν΅μ¬ λ¬Έμλ λμΆνμλ€. μ΄λ₯Ό ν΅ν΄ quantum-dot displayμ λν ꡬ쑰λ₯Ό μ΄ν΄λ³Ό μ μμλ€. νΉν λ°μ΄ν°μ λν LDAλ₯Ό μνν¨μΌλ‘μ¨ ν΄λΉ μ£Όμ μ λν μ°κ΅¬λν₯, νμ¬ νν©μ νμ νκ³ , ν΅μ¬ μ£Όμ λ³λ‘ λ¬Άμ΄μ μ΄ν΄λ³Ό μ μμμΌλ©°, κ²°κ³Όλ₯Ό λ°νμΌλ‘ ν΄λΉ μ£Όμ μ κ΄ν μ°κ΅¬ λ°©ν₯κΉμ§ μ€κ³ν μ μμ κ²μ΄λ€.
λ§μΉλ©°
μ²μμΌλ‘ NLPμ κ΄μ¬μ κ°κ²λ κ³κΈ°μλ€. λ΄μ©μ λͺ¨λ νμ΄λ³΄μ§ μκ³ , λ΄μ©μ μ μΆν μ μλ€λ κ²μ κ΅μ₯ν νλͺ μΌλ‘ λ€κ°μλ€. NLPλ₯Ό λ§μ€ν°νλ κ·Έλ κΉμ§......... κΈ°μ΄μ μΈ μ§μλΆν° μκ³ κ³΅λΆν΄μΌμ§