没有

pytorch-fast-elmo的Python项目详细描述


Pythorch快速elmo

https://img.shields.io/pypi/v/pytorch_fast_elmo.svghttps://img.shields.io/travis/cnt-dev/pytorch-fast-elmo.svghttps://img.shields.io/badge/License-MIT-yellow.svg

简介

一个具有以下功能的快速elmo实现:

  • 更低的执行开销。核心组件在libtorch中重新实现,以减少python执行开销(45%加速)。
  • {STR 1 }更灵活的设计。通过重新设计工作流,用户可以很容易地扩展或更改EMO行为。

基准

硬件:

  • CPU:I7-7800X
  • GPU:1080ti

选项:

  • 批量:32
  • 预热迭代:20
  • 测试迭代次数:1000
  • 字长:[1,20]
  • 句子长度:[1,30]
  • 随机种子:10000
ItemMean Of Durations (ms)cumtime(synchronize)%
Fast ELMo (CUDA, no synchronize)31N/A
AllenNLP ELMo (CUDA, no synchronize)56N/A
Fast ELMo (CUDA, synchronize)4726.13%
AllenNLP ELMo (CUDA, synchronize)570.02%
Fast ELMo (CPU)1277N/A
AllenNLP ELMo (CPU)1453N/A

使用量

请先安装torch==1.0.0。然后,只需运行此命令进行安装。

pip install pytorch-fast-elmo

FastElmo的行为应该与allennlp的ELMo相同。

frompytorch_fast_elmoimportFastElmo,batch_to_char_idsoptions_file='/path/to/elmo_2x4096_512_2048cnn_2xhighway_options.json'weight_file='/path/to/elmo_2x4096_512_2048cnn_2xhighway_weights.hdf5'elmo=FastElmo(options_file,weight_file)sentences=[['First','sentence','.'],['Another','.']]character_ids=batch_to_ids(sentences)embeddings=elmo(character_ids)

如果已禁用bilm-tf中的char_cnn,或已将char cnn表示导出到权重文件,请使用FastElmoWordEmbedding

frompytorch_fast_elmoimportFastElmoWordEmbedding,load_and_build_vocab2id,batch_to_word_idsoptions_file='/path/to/elmo_2x4096_512_2048cnn_2xhighway_options.json'weight_file='/path/to/elmo_2x4096_512_2048cnn_2xhighway_weights.hdf5'vocab_file='/path/to/vocab.txt'embedding_file='/path/to/cached_elmo_embedding.hdf5'elmo=FastElmoWordEmbedding(options_file,weight_file,# Could be omitted if the embedding weight is in `weight_file`.word_embedding_weight_file=embedding_file,)vocab2id=load_and_build_vocab2id(vocab_file)sentences=[['First','sentence','.'],['Another','.']]word_ids=batch_to_word_ids(sentences,vocab2id)embeddings=elmo(word_ids)

cli命令:

# Cache the Char CNN representation.
fast-elmo cache-char-cnn ./vocab.txt ./options.json ./lm_weights.hdf5 ./lm_embd.hdf5

# Export word embedding.
fast-elmo export-word-embd ./vocab.txt ./no-char-cnn.hdf5 ./embd.txt

学分

这个包是用Cookiecutteraudreyr/cookiecutter-pypackage项目模板创建的。

历史记录

0.1.0(2019-01-02)

  • pypi上的第一个版本。

欢迎加入QQ群-->: 979659372 Python中文网_新手群

推荐PyPI第三方库


热门话题
java Android同步不同页面上的按钮   java评测每个类收集的垃圾对象实例数   java(Spring MVC+Hibernate 4+Test 4)自动连线DAO返回NULL   java Android编辑文本和虚拟键盘   java Selenium与BrowserMobProxy   JAVAlang.NoClassDefFoundError:com/sun/jersey/spi/inject/Errors$关闭原因?   java为什么在我成功登录后仍然会出现“不正确的帐户或密码或用户类型”   安卓应用程序在重新启动java时崩溃。网UnknownHostException:无法解析主机   多线程在Java中同步共享静态对象的正确方法是什么?   未调用自定义注释的java类验证(约束类)   java如何将指定目录的存档文件放入所需位置?   java如何识别Selenium中的每个编辑文本字段,如果它们的Xpath都相同   使用gwtmockito/mockito的java简单单选按钮单元测试?