taishi-i / nagisa

A Japanese tokenizer based on recurrent neural networks
https://huggingface.co/spaces/taishi-i/nagisa-demo
MIT License
379 stars 22 forks source link

Deferring loading of DyNet on import #10

Closed BLKSerene closed 2 years ago

BLKSerene commented 5 years ago

Hi, I'm using nagisa in my GUI-based project. When importing nagisa, it requires a few seconds to load DyNet, adding extra time to the loading time of my program, so I have to defer the import of nagisa until it is needed. I'm not sure whether DyNet is required by all functions of nagisa, but I think that it would be better if the loading of DyNet is deferred until it is needed by nagisa the first time.

taishi-i commented 5 years ago

Thanks for using nagisa. I understand the problem that takes a few seconds to import. Actually, it takes a few seconds to build neural networks when importing.

Could you tell me your execution environment and how many seconds will it take in it? Could you also tell me the version of Python? Python 2 takes longer than Python 3. So, I recommend you use nagisa on Python3.6.

For your information, it takes 1.24 s in my desktop PC environment using Python3.6 to imoprt nagisa.

BLKSerene commented 5 years ago

Hi, I'm using Python 3.7.1 64-bit on Windows 10 Enterprise. The laptop I'm using was bought more than 5 years ago, so it is extremely underpowered now. I did a simple test with the following snippet.

import time
time_start = time.time()
import nagisa
print(time.time() - time_start)

The results are (after running this several times): [dynet] random seed: 1234 [dynet] allocating memory: 32MB [dynet] memory allocation done. # The first 3 lines are omitted in the output of the following tests. 6.289936780929565 4.928969860076904 4.965949058532715 4.973945379257202 5.052893877029419 4.922978639602661 4.925974130630493 4.860015153884888 4.918976783752441 4.93596887588501

So around 5 seconds. It's okay with this since I can specify when to import nagisa particularly in my program. It's just an enhancement proposal.