Skip to content
This repository has been archived by the owner on Nov 17, 2023. It is now read-only.

Cannot print parameter summary of embedding layer #12778

Closed
haven-jeon opened this issue Oct 10, 2018 · 4 comments · Fixed by #12796
Closed

Cannot print parameter summary of embedding layer #12778

haven-jeon opened this issue Oct 10, 2018 · 4 comments · Fixed by #12796

Comments

@haven-jeon
Copy link

haven-jeon commented Oct 10, 2018

Description

0 parameter of Embedding layer, when print_summary()

Environment info (Required)

MXNet 1.3.0

Package used (Python/R/Scala/Julia):
I am using python

Minimum reproducible example

class SentClassificationModel(gluon.HybridBlock):
    def __init__(self, vocab_size, num_embed, **kwargs):
        super(SentClassificationModel, self).__init__(**kwargs)
        with self.name_scope():
            self.embed = nn.Embedding(input_dim=vocab_size, output_dim=num_embed)
            self.drop = nn.Dropout(0.3)
            self.fc = nn.Dense(100, activation='relu')
            self.out = nn.Dense(2)  
    def hybrid_forward(self, F ,inputs):
        em_out = self.drop(self.embed(inputs))
        fc_out = self.fc(em_out) 
        return(self.out(fc_out))

ctx = mx.gpu()

model = SentClassificationModel(vocab_size = len(vocab.idx_to_token), num_embed=50)

model.initialize(mx.init.Xavier(),ctx=ctx)
model.hybridize()

mx.viz.print_summary(
    model(mx.sym.var('data')), 
    shape={'data':(1,30)}, #set your shape here
)
________________________________________________________________________________________________________________________
Layer (type)                                        Output Shape            Param #     Previous Layer                  
========================================================================================================================
data(null)                                          30                      0                                           
________________________________________________________________________________________________________________________
sentclassificationmodel0_embedding0_fwd(Embedding)  30x50                   0           data                            
________________________________________________________________________________________________________________________
sentclassificationmodel0_dropout0_fwd(Dropout)      30x50                   0           sentclassificationmodel0_embeddi
________________________________________________________________________________________________________________________
sentclassificationmodel0_dense0_fwd(FullyConnected) 100                     3100        sentclassificationmodel0_dropout
________________________________________________________________________________________________________________________
sentclassificationmodel0_dense0_relu_fwd(Activation)100                     0           sentclassificationmodel0_dense0_
________________________________________________________________________________________________________________________
sentclassificationmodel0_dense1_fwd(FullyConnected) 2                       202         sentclassificationmodel0_dense0_
========================================================================================================================
Total params: 3302
________________________________________________________________________________________________________________________
@piyushghai
Copy link
Contributor

@haven-jeon Thank you submitting this issue. We will look into this

@mxnet-label-bot [Bug, Gluon]

@soeque1
Copy link
Contributor

soeque1 commented Oct 10, 2018

https://github.com/apache/incubator-mxnet/blob/master/python/mxnet/visualization.py

It seems that the Embedding layers is currently missing.
So It needs to be added at Line 162 as below.

elif op == 'Embedding':
    cur_param = int(node["attrs"]['input_dim']) * int(node["attrs"]['output_dim'])

@piyushghai
Copy link
Contributor

@soeque1 Thank you for your suggestion! Maybe you can raise a PR for this fix and contribute to the development of MXNet community :)

@soeque1
Copy link
Contributor

soeque1 commented Oct 11, 2018

Thank you for the quick reply. I will PR soon :)

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants