https://github.com/taishan1994/pytorch_peot_rnn
基于pytorch_rnn的古诗词生成
https://github.com/taishan1994/pytorch_peot_rnn
Last synced: 6 months ago
JSON representation
基于pytorch_rnn的古诗词生成
- Host: GitHub
- URL: https://github.com/taishan1994/pytorch_peot_rnn
- Owner: taishan1994
- Created: 2021-10-24T09:42:45.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-10-24T09:53:38.000Z (almost 4 years ago)
- Last Synced: 2025-02-14T17:42:18.958Z (8 months ago)
- Language: Python
- Size: 19.3 MB
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# pytorch_peot_rnn
基于pytorch_rnn的古诗词生成# 说明
config.py里面含有训练、测试、预测的参数,更改后运行:
```python
python main.py
```# 预测结果
```python
if config.do_predict:
result = trainer.generate('丽日照残春')
print("".join(result))
result = trainer.gen_acrostic('深度学习')
print("".join(result))
丽日照残春,
风光摇落时。
不知花发意,
不得见春风。深山高下有余灵,万里无人见钓矶。
度日茱萸人不得,一枝不得不相见。
学舞一枝花落叶,不知何处是君王。
习书不见金闺后,应是君王赐手间。
```# 参考
> https://github.com/chenyuntc/pytorch-book
其中第九章的古诗词生成,修改了以下地方:
1、重构了代码架构;
2、增加了数据集生成的过程;
3、RNN网络改为batch_first;
4、计算损失时不计算padding部分;