The premise of this article is that you have to have a girlfriend. If not, keep a girlfriend.

Tanabata festival is the source of Liang Shanbo and Zhu Yingtai beautiful legend, into a pair of butterfly ~ beautiful myth! Although it is usually valentine’s Day now, but have to say, the ancient traditional cultural heritage, or to inherit ah ~

In Internet companies, the main types of programmers include front-end engineers, back-end engineers and algorithm engineers.

For the specific professional function division is not very clear, let’s briefly introduce the responsibilities of different programmer positions:

Front end programmer: draw UI interface, interface requirements with design and product manager, draw specific front end interface to the user

Back-end programmer: receives front-end JSON string, connects to database, and pushes JSON to the front-end for display

Algorithm engineer: carry out specific rule mapping, optimize the algorithm model of function, improve and improve the accuracy of mapping.

Tanabata festival arrived, how to combine their professional skills, coax girlfriend happy?

Front end engineer: I first, draw a dynamic sunset page!

1. Define the style style:

.star {
  width: 2px;
  height: 2px;
  background: #f7f7b6;
  position: absolute;
  left: 0;
  top: 0;
  backface-visibility: hidden;
}
Copy the code

2. Define animation features

@keyframes rotate {
  0% {
    transform: perspective(400px) rotateZ(20deg) rotateX(-40deg) rotateY(0);
  }

  100% {
    transform: perspective(400px) rotateZ(20deg) rotateX(-40deg) rotateY(-360deg); }}Copy the code

3. Define starry style data

export default {
  data() {
    return {
      starsCount: 800.// Number of stars
      distance: 900./ / spacing}}}Copy the code

4. Define star speed and rules:

starNodes.forEach((item) = > {
      let speed = 0.2 + Math.random() * 1;
      let thisDistance = this.distance + Math.random() * 300;
      item.style.transformOrigin = ` 0 0${thisDistance}px`;
      item.style.transform =
          ` translate3d (0, 0, -${thisDistance}px)
		        rotateY(The ${Math.random() * 360}deg)
		        rotateX(The ${Math.random() * -50}deg)
		        scale(${speed}.${speed}) `;
    });

Copy the code

Front-end preview renderings:

After the back-end engineer looked at it, he nodded his head first and then refused to accept it. The drawing page was too superficial. I developed an interface to send a blessing email at the time of my girlfriend’s birthday.

1. Import the POM. XML file

<! -- mail Service initiator --><dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-mail</artifactId>
        </dependency>
Copy the code

2. Add internal configuration links to application-dev.properties

#QQ\u90AE\u7BB1\u90AE\u4EF6\u53D1\u9001\u670D\u52A1\u914D\u7F6E
spring.mail.host=smtp.qq.com
spring.mail.port=587## here fill in the authorization code of mailbox spring.mail.password=#yourpassword#Copy the code

3. Configure the mail sending tool class mailutils.java

@Component
public class MailUtils {
    @Autowired
    private JavaMailSenderImpl mailSender;
    
    @Value("${spring.mail.username}")
    private String mailfrom;

    // Send a simple email
    public void sendSimpleEmail(String mailto, String title, String content) {
        // Customize the email sending content
        SimpleMailMessage message = new SimpleMailMessage();
        message.setFrom(mailfrom);
        message.setTo(mailto);
        message.setSubject(title);
        message.setText(content);
        // Send an emailmailSender.send(message); }}Copy the code

4. The test is annotated with timed annotations

@Component
class DemoApplicationTests {

    @Autowired
    private MailUtils mailUtils;

    /** * Regular mail delivery task, the first day of each month 12 noon to send mail */
    @Scheduled(cron = "0, 0, 12, 1 *?")
    void sendmail(){
        // Customize the message content
        StringBuffer content = new StringBuffer();
        content.append("HelloWorld");
        // Are the recipient email address, title, and content respectively
        mailUtils.sendSimpleEmail("[email protected]"."Custom title",content.toString()); }}Copy the code

Cron: seconds, minutes, hours, days, months, years. * indicates that all times match

5. Package the project and deploy it in a server container.

Algorithm engineer, and develop interface, and draw pages, I will train an automatic poem writing robot!

1. Define the structure of neural network RNN

def neural_network(model = 'gru', rnn_size = 128, num_layers = 2) : cell = tf.contrib.rnn.BasicRNNCell(rnn_size, state_is_tuple = True) cell = tf.contrib.rnn.MultiRNNCell([cell] * num_layers, state_is_tuple = True) initial_state = cell.zero_state(batch_size, tf.float32)with tf.variable_scope('rnnlm'):
        softmax_w = tf.get_variable("softmax_w", [rnn_size, len(words)])
        softmax_b = tf.get_variable("softmax_b", [len(words)])
        embedding = tf.get_variable("embedding", [len(words), rnn_size])
        inputs = tf.nn.embedding_lookup(embedding, input_data)
    outputs, last_state = tf.nn.dynamic_rnn(cell, inputs, initial_state = initial_state, scope = 'rnnlm')
    output = tf.reshape(outputs, [-1, rnn_size])
    logits = tf.matmul(output, softmax_w) + softmax_b
    probs = tf.nn.softmax(logits)
    return logits, last_state, probs, cell, initial_state

Copy the code

2. Define model training methods:

def train_neural_network():
    logits, last_state, _, _, _ = neural_network()
    targets = tf.reshape(output_targets, [-1])
    loss = tf.contrib.legacy_seq2seq.sequence_loss_by_example([logits], [targets], \
        [tf.ones_like(targets, dtype = tf.float32)], len(words))
    cost = tf.reduce_mean(loss)
    learning_rate = tf.Variable(0.0, trainable = False)
    tvars = tf.trainable_variables()
    grads, _ = tf.clip_by_global_norm(tf.gradients(cost, tvars), 5)
    #optimizer = tf.train.GradientDescentOptimizer(learning_rate)
    optimizer = tf.train.AdamOptimizer(learning_rate)
    train_op = optimizer.apply_gradients(zip(grads, tvars))

    Session_config = tf.ConfigProto(allow_soft_placement = True)
    Session_config.gpu_options.allow_growth = True

    trainds = DataSet(len(poetrys_vector))

    with tf.Session(config = Session_config) as sess:
        sess.run(tf.global_variables_initializer())

        saver = tf.train.Saver(tf.global_variables())
        last_epoch = load_model(sess, saver, 'model/')

        for epoch in range(last_epoch + 1.100):
            sess.run(tf.assign(learning_rate, 0.002 * (0.97 ** epoch)))
            #sess.run(tf.assign(learning_rate, 0.01))

            all_loss = 0.0
            for batche in range(n_chunk):
                x,y = trainds.next_batch(batch_size)
                train_loss, _, _ = sess.run([cost, last_state, train_op], feed_dict={input_data: x, output_targets: y})

                all_loss = all_loss + train_loss

                if batche % 50= =1:
                    print(epoch, batche, 0.002 * (0.97 ** epoch),train_loss)

            saver.save(sess, 'model/poetry.module', global_step = epoch)
            print (epoch,' Loss: ', all_loss * 1.0 / n_chunk)


Copy the code

3. Data set preprocessing

poetry_file ='data/poetry.txt'# Poetry poetrys = []with open(poetry_file, "r", encoding = 'utf-8') as f:
    for line in f:
        try:
            #line = line.decode('UTF-8')
            line = line.strip(u'\n')
            title, content = line.strip(u' ').split(u':')
            content = content.replace(u' ',u' ')
            if u'_' in content or u'(' in content or u'(' in content or u' ' ' in content or u'[' in content:
                continue
            if len(content) < 5 or len(content) > 79:
                continue
            content = u'[' + content + u'] '
            poetrys.append(content)
        except Exception as e:
            pass

Copy the code

This tang poetry data set is stored in the file, which is used to train the model

4. Test the effect of the model after training:

Tibetan poem creation: “Happy Chinese Valentine’s Day”

The result of the model operation

Ha ha ha, all kinds of festivals are programmer’s table (zhuang) performance (BI) time, but these are the icing on the cake, only real, sincere, will last forever ah ~

I wish you a happy Valentine’s Day in advance!

I’m Spirited Away, and I’ll see you next time