hello , Hello, everyone ~
In the eyes of ordinary people, we programmers are all dull , They all wear a pair of glasses , Like to wear inch clothes ,T T-shirts are generally black, white and grey . Today I will teach you how to use python Generate Love words 、 Hide the head poem 、 Couplets .
python --version
python Version must be in ,3.6.x - 3.9.x
python -m pip --version
pip Version must >= 20.2.2
python -m pip install paddlepaddle==0.0.0 -f https://www.paddlepaddle.org.cn/whl/mac/cpu/develop.html
import paddle paddle.utils.run_check()
If appear PaddlePaddle is installed successfully!, Indicates that you have successfully installed .
import paddlehub as hub module = hub.Module(name="ernie_gen_lover_words") test_texts = [' Valentine's Day ', ' In my hometown ', ' I love you, you love me '] results = module.generate(texts=test_texts, use_gpu=True, beam_width=5) for result in results: print(result)
Step by step official
import paddlehub as hub # When defining the model , Can be set by line=4 or 8 Specify the output quatrains or rhymes , Set up word=5 or 7 Specify to output five or seven words . # Default line=4, word=7 That is, output seven character quatrains . module = hub.Module(name="ernie_gen_acrostic_poetry", line=4, word=7) test_texts = [' Nuggets are the best '] results = module.generate(texts=test_texts, use_gpu=True, beam_width=5) for result in results: print(result)
Dig ditches to divert water and irrigate vegetable gardens , Golden Valley rootless seedling . You'd better move your roots to the old room , A cow's head crows in the morning .
Dig ditches to divert water and irrigate vegetable gardens , Golden Valley rootless seedling . The most bitter year, the spring rain breaks , Countless cow doves are buried in the warehouse .
Step by step official
import paddlehub as hub module = hub.Module(name="ernie_gen_poetry") test_texts = [' abed, I see a silver light , Li Bai is the king of volumes .'] results = module.generate(texts=test_texts, use_gpu=True, beam_width=5) for result in results: print(result)
The king's book is in bed , Month in bed . Go to bed and play the piano , Play a song with the sound of the piano . Play a song with the sound of the piano , The moonlight is bright . At the end of the song, each is scattered , Dew drop banana green .
The king's book is in bed , Month in bed . Go to bed and play the piano , Play a song with the sound of the piano . Play a song with the sound of the piano , The moonlight is bright . After the song, the moon wants to fall , The wind is blowing in the cinnamon tree .
The king's book is in bed , Month in bed . Go to bed and play the piano , Play a song with the sound of the piano . Play a song with the sound of the piano , The moonlight is bright . After the song, the moon wants to fall , The laurel tree sleeps on its branches .
import paddlehub as hub module = hub.Module(name="ernie_gen_couplet") test_texts = [" The wind blows the clouds and the sky is full of tears "] results = module.generate(texts=test_texts, use_gpu=True, beam_width=5) for result in results: print(result)
The rain beat the flowers and hurt the ground , The rain beat the flowers and frowned , The rain beat the flowers and the ground moved , The rain beat the frost and bullied the ground , The rain beat flowers and scattered sorrow on the ground . Copy code
Step by step official