LDA(Latent Dirichlet Allocation)


매번 공부해야지 했던 LDA
결국 논문을 읽진 않고 간단하게 개념만 학습하기 위하여 인터넷으로 찾아봤다.
대충 토픽 클러스터링 정도로 알고 있었는데 어쨌든 이번 기회에 조금 더 잘 알게 된 것 같다.

LDA는 간단히 말하면 Unsupervised generative topic model. 문서를 모델링하는 기법이다.
문서 컬렉션(corpus)을 표현하는 방법을 generative한 방법으로 찾는 것이며, 주제 분류나 문서간 유사도 계산에 많이 쓰인다.

LDA는 각각의 문서를 토픽들의 집합으로 본다는 것이 특징.
즉, document는 mixture of topics.

<LDA 모델>

LDA가 문서를 모델링하는 방법:
1. 문서의 토픽들을 정하고
2. 각 단어의 토픽을 정하며
3. 토픽을 형성하는 단어의 집합에서 단어를 뽑아 문서에 쓴다.



참고한 블로그:

http://www.4four.us/article/2010/11/latent-dirichlet-allocation-simply

http://arongdari.tistory.com/entry/Latent-Dirichlet-Allocation

Seq2seq가 내가 하려는 연구의 기초가 되기 때문에

직접 짜지는 않고..... 

있는 코드 돌려보기로 했다.


https://github.com/macournoyer/neuralconvo


코드는 torch 코드



그리고 겪게 되는 에러들 포스팅


1. 

/home/xx/torch/install/share/lua/5.1/nn/Select.lua:10: bad argument #3 to 'select' (out of range at /tmp/luarocks_cutorch-scm-1-5327/cutorch/lib/THC/generic/THCTensor.c:386)


흠.. 잘은 모르겠지만 Select.lua의 10번째 줄에서 에러가 나는 것 같다.


https://github.com/torch/nn/blob/master/Select.lua



근데 웹에 나온 Select.lua랑 코드가 달랐다.


local Select, parent = torch.class('nn.Select', 'nn.Module')

function Select:__init(dimension,index)
   parent.__init(self)
   self.dimension = dimension
   self.index = index 
end

function Select:updateOutput(input)
   local index = self.index < 0 and input:size(self.dimension) + self.index + 1 or self.index
   local output = input:select(self.dimension, index);
   self.output:resizeAs(output)
   return self.output:copy(output)
end

function Select:updateGradInput(input, gradOutput)
   local index = self.index < 0 and input:size(self.dimension) + self.index + 1 or self.index
   self.gradInput:resizeAs(input)  
   self.gradInput:zero()
   self.gradInput:select(self.dimension,index):copy(gradOutput) 
   return self.gradInput
end 

여기서 


local index = self.index < 0 and input:size(self.dimension) + self.index + 1 or self.index

이 부분의 코드가 없고, 대신 select에 인자로 주는 index가 local index가 아니고 self.index



사실 여기가 문제란 걸 발견한 건,

우선 이 값을 찍어봐야 할 것 같아서

self.dimension과 self.index를 찍어봤다.


각각 1과 -1의 값이 나오길래, 왠지 -1이 index이면 안 될 것 같아서 ㅋㅋㅋㅋ

그래서 저 없는 줄을 넣었더니 문제 해결.


nn 패키지를 업데이트를 안 해서 그런 것 같기도 하고.


우선 대충 해결데쓰! 


매번 까먹는다...

이젠 정말 안 까먹을 수 있을듯!


링크 ▶ http://langrang.tistory.com/14

+ Recent posts