Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

Learn Python to learn to write


Jun 01, 2021 Article blog



This article was reproduced to Know ID: Charles (Bai Lu) knows his personal column

Download the W3Cschool Mobile App, 0 Foundation Anytime, Anywhere Learning Programming >> Poke this to learn

Lead

T_T people who don't have a scientific research dream come to the water in the middle of the night

Let Python learn to write songs and create songs

It's pure entertainment

Adapted from a tutorial on PyTorch's official website, but I wrote it in TF, and then the generated English became the generated Chinese

Let's Go~~~


Related documents

Baidu web download link: https://pan.baidu.com/s/1VUEFR82CqyDj2w9SS4xnFA

Password: 3dmx


Develop tools

Python version: 3.6.4

Related modules:

tensorflow-gpu module;

numpy module;

and some Python's own modules.

The TensorFlow-GPU version is:

1.6.0


Environment construction

Install Python and add it to the environment variable, and pip installs the relevant modules that are required.

Introduction to the principle

For an introduction to RNN, please refer to my previous article:

Python implements a simple machine translation model (click on the blue word to enter)

Here we train using the Char RNN model.

That is, the special case input and output in the Seq2Seq model is equally long.

That's what it looks like in the following image (source network):

 Learn Python to learn to write1

The implementation process is detailed in the source code in the relevant file.


Use the demo

Run the Char_RNN.py file in the cmd window and enter the relevant information as prompted.

The training-related parameters should be adjusted in the config.py file:

 Learn Python to learn to write2

The data path used for the training and the warm-up data used to generate the new text are adjusted in the Char_RNN.py file:

 Learn Python to learn to write3

Training demo video:


Because it took so long, I only recorded the first part of the training.

The final training result is shown in the following image:

 Learn Python to learn to write4  Learn Python to learn to write5


The results are shown

Because time and resources are limited.

Only all of Jay Chou's lyrics are shown here as samples for post-training tests.

Of course, you can find other text as training material to generate different styles of "articles", "lyrics" and so on

The results are as follows:

( Warm up the lyrics as: it's the eaves that have escaped the rain with you )

 Learn Python to learn to write6

Well, I don't know what it's talking about T_T

A case of failure T_T

Probably the model is too low. A nd the training data was downloaded directly from the Internet, and there was no pre-processed T_T. In the middle of the sudden emergence of a bracket I am also a T_T


more

Play around with the T_T

Interested students can try to change the more complex model

Then the training of the language is best to deal with the . .

Haven't written TF for a long time, the code may be a little bad T_T

That's it