Introduction to the Seq2Seq-Couplet Project
The Seq2Seq-Couplet project is an engaging and innovative endeavor that leverages the power of sequence-to-sequence models to craft poetic couplets. These couplets are a traditional form of Chinese poetry and the project uses the machine learning framework TensorFlow to achieve this creative output. Those interested in exploring the project further can try a live demo here.
Pre-requirements
Before delving into the project, there are a few prerequisites that need to be met:
- TensorFlow: The project is built using this efficient machine learning library.
- Python 3.6: The programming language version required to run the code.
- Dataset: An essential component for training the model, which can be obtained from a specified GitHub repository.
It's important to note that if you decide to use your own dataset, you must prepend <s>
and <\s>
to the first two lines in the vocabulary file to ensure compatibility.
Usage
Training the Model
To train the model, users need to make specific configurations. This process involves:
- Editing the
couplet.py
File: Here, users can set the locations for files and adjust hyperparameters. - Running the Training Command: Execute
python couplet.py
to initiate the training process.
As the model trains, users can monitor its performance through metrics such as training loss and BLEU score, viewable on Tensorboard. Should the loss plateau, adjusting the learning_rate
may be necessary to maintain progress. Here's a visual example of how the loss might appear over time:
In cases where training is paused and later resumed, setting restore_model
to True
allows continuation with the command m.train(<epochs>, start=<start>)
, with start
representing previously completed steps. Notably, the model's training on a Nvidia GTX-1080 GPU spanned about four days.
Running the Trained Model
Once training is completed, deploying the model involves:
- Configuring
server.py
: Set paths for thevocab_file
andmodel_dir
. - Executing the Server Command: Launch the web service using
python server.py
, enabling real-time couplet generation.
Alternatively, users can construct a Docker image using a Dockerfile and execute it through Docker. This requires accurately mounting the model file paths into the Docker container for proper functionality.
Examples
The following table showcases some of the couplets generated by this model, reflecting its ability to produce literary and contextually relevant outputs:
Upper Line | Lower Line |
---|---|
殷勤怕负三春意 | 潇洒难书一字愁 |
如此清秋何吝酒 | 这般明月不须钱 |
天朗气清风和畅 | 云蒸霞蔚日光辉 |
梦里不知身是客 | 醉时已觉酒为朋 |
千秋月色君长看 | 一夜风声我自怜 |
These examples illustrate the model's proficiency in generating couplets that maintain the spirit and structure of traditional Chinese poetry.