Skip to content

A pytorch implementation of CapsNet for text classification 汽车行业用户观点主题及情感识别为例(subject-and-sentiment-analysis)

Notifications You must be signed in to change notification settings

binzhouchn/capsule-pytorch

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

CapsNet pytorch实现(文本多分类)

CapsNet based on Geoffrey Hinton's original paper Dynamic Routing Between Capsules

先读懂CapsNet架构然后用TensorFlow实现:全面解析Hinton提出的Capsule

Requirements

  • python 3.6+
  • pytorch 0.4.1+
  • gensim
  • tqdm

Run

python main.py

Train and test dataset should be included in data folder

DIY

If you need hard_sigmoid for GRU gate, just uncomment

from rnn_revised import *

in capsule_layer.py. You can also use whatever activation func or dropout/recurrent_dropout ratio you want and revise in rnn_revised.py doc. One more thing, the revise version is non-cuda, if you find a way out for cuda version please let me know.

注:

  1. PrimaryCapsLayer中的squash压缩的是向量size是[batch_size, 1152, 8],在最后一个维度上进行压缩即维度8 压缩率|Sj|2/(1+|Sj|2)/|Sj|大小为[batch_size, 1152],然后与原来的输入向量相乘即可

  2. 如果reconstruction为True,则loss由两部分组成margin_loss和reconstruction_loss

output, probs = model(data, target)
reconstruction_loss = F.mse_loss(output, data.view(-1, 784))
margin_loss = loss_fn(probs, target)
# 如果reconstruction为True,则loss由两部分组成margin_loss和reconstruction_loss
loss = reconstruction_alpha * reconstruction_loss + margin_loss

About

A pytorch implementation of CapsNet for text classification 汽车行业用户观点主题及情感识别为例(subject-and-sentiment-analysis)

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages