使用PyTroch RNN的文本应用程序的高级接口。
abdoTheBest的Python项目详细描述
根恩
GeNN(generative neural networks)是使用pytorchrnn的文本应用程序的高级接口
特点
- 预处理:
- 解析txt、json和csv文件。在
- NLTK、regex和spacy标记化支持。在
- GloVe和fastText预训练的嵌入,能够为您的数据进行微调。在
- 体系结构和定制:
- GPT-2有小型、中型和大型变体。在
- LSTM和GRU,大小可变。在
- 层数和批次可变。在
- 辍学。在
- 文本生成:
- 从所有实例中的n个第一个令牌或最频繁令牌进行随机种子采样。在
- 使用变量K进行下一个令牌预测的Top-K采样
- 变概率门限下一个令牌预测的核抽样。在
入门
如何安装
pip install genn
先决条件
- Pythorch 1.4.0版
- Pythorch变压器
pip install pytorch_transformers
- NumPy公司
pip install numpy
- 快速文本
pip install fasttext
使用包管理器pip安装genn。在
使用
fromgennimportPreprocessing,LSTMGenerator,GPT2#LSTM exampleds=Preprocessing("data.txt")gen=LSTMGenerator(ds,nLayers=2,batchSize=16,embSize=64,lstmSize=16,epochs=20)#Train the modelgen.run()# Generate 5 new documentsprint(gen.generate_document(5))#GPT-2 examplegen=GPT2("data.txt",taskToken="Movie:",epochs=7,variant="medium")#Train the modelgen.run()#Generate 10 new documentsprint(gen.generate_document(10))
有关如何使用预处理的更多示例,请参阅this file。
有关如何使用LSTMGenerator和GRUGenerator的更多示例,请参阅this file。
有关如何使用GPT2的更多示例,请参考this file
贡献
欢迎拉取请求。对于重大变化,请先打开一个问题,讨论您希望更改的内容。在
许可证
根据麻省理工学院的许可证分发。有关详细信息,请参见LICENSE。在
- 项目
标签: