This article is participating in Python Theme Month. See the link to the event for more details
This article is to recommend a few Baidu fly pulp open source projects
- Love talk generation model
- Generation model of Tibetan acropoem
- Poetry generation model
- Couplet generation model
Installation environment
For Example, if you have a MAC, go to official for Windows and Linux
First, prepare the environment
1. Current environment supported by the paddle
- MacOS 10.11/10.12/10.13/10.14 (64-bit) (GPU version not supported)
- Python version 3.6/3.7/3.8/3.9 (64-bit)
- PIP or PIP3 20.2.2 or later (64 bit)
- PaddlePaddle does not support M1 chip (ARM64 architecture)
2. Python version
python --version
Copy the code
The Python version must be in, 3.6.x-3.9.x
3. The PIP version
python -m pip --version
Copy the code
PIP version must >= 20.2.2
2. Start installation
1. Install
Python -m PIP install paddlepaddle = = 0.0.0 -f https://www.paddlepaddle.org.cn/whl/mac/cpu/develop.htmlCopy the code
2. Verify
import paddle
paddle.utils.run_check()
Copy the code
If PaddlePaddle is installed successfully! , the installation is successful.
Projects show
One, love words generation model
-
code
import paddlehub as hub module = hub.Module(name="ernie_gen_lover_words") test_texts = ['Valentine's Day'.'home'.'I love you and you love me'] results = module.generate(texts=test_texts, use_gpu=True, beam_width=5) for result in results: print(result) Copy the code
-
The effect
-
Principle And source code
Set the official
Second, the generation model of Tibetan first poems
-
code
import paddlehub as hub When the model is defined, you can set line=4 or 8 to specify the output quatrains or regulated poems, and set word=5 or 7 to specify the output of five or seven words. # Default line=4, word=7 module = hub.Module(name="ernie_gen_acrostic_poetry", line=4, word=7) test_texts = ['The best gold digger'] results = module.generate(texts=test_texts, use_gpu=True, beam_width=5) for result in results: print(result) Copy the code
-
The effect
Dig ditch water to irrigate garden, golden valley root-less seed seedlings. Best to move roots to the old room, the cow head in the morning afternoon crow.Copy the code
Dig ditch water to irrigate garden, golden valley root-less seed seedlings. The most bitter year spring rain rest, countless cow doves full barn buried.Copy the code
-
Principle And source code
Set the official
Third, poetry generation model
-
code
import paddlehub as hub module = hub.Module(name="ernie_gen_poetry") test_texts = [In front of his bed, there was a bright moonlight, and Li Bai was the king of Scroll. '] results = module.generate(texts=test_texts, use_gpu=True, beam_width=5) for result in results: print(result) Copy the code
-
The effect
The book is in bed, and the month is in bed. Go to bed and play the piano. The sound of the piano plays a song, the moonlight shines a song. The end of the scattered, dew drop banana green.Copy the code
The book is in bed, and the month is in bed. Go to bed and play the piano. The sound of the piano plays a song, the moonlight shines a song. The moon was about to set, and the wind of the osmanthus blew.Copy the code
The book is in bed, and the month is in bed. Go to bed and play the piano. The sound of the piano plays a song, the moonlight shines a song. The moon is about to fall, and the laurel boughs sleep.Copy the code
-
Principle And source code
Set the official
Fourth, couplet generation model
-
code
import paddlehub as hub module = hub.Module(name="ernie_gen_couplet") test_texts = ["The wind blows the clouds in tears."] results = module.generate(texts=test_texts, use_gpu=True, beam_width=5) for result in results: print(result) Copy the code
-
The effect
Rain dozen flower remnant sad, rain dozen flower remnant frown, rain dozen flower remnant moved, rain dozen frost deceiving ground moved, rain dozen flower remnant sprinkled sorrow.Copy the code
-
Principle And source code
Set the official