1 爬虫
1.1 cookie
cookie是服务器安在客户端的“监视器”,记录了包括登录状态在内的所有信息,这些信息由服务器生成和解释,服务器通过客户端携带的cookie来识别用户。cookie存在生命周期,短的关掉浏览器就失效,长的能若干天免登陆,一旦失效就要重新获取。所以只要得到登录后的cookie并必要时进行更新,服务器就会认定其为登录状态。通常可根据浏览器记录中获取cookie。
1.2 get和post
最直观的区别就是GET把参数包含在URL中,POST通过request body传递参数。GET和POST还有一个重大区别,简单的说:GET产生一个TCP数据包;POST产生两个TCP数据包。对于GET方式的请求,浏览器会把http header和data一并发送出去,服务器响应200;而对于POST,浏览器先发送header,服务器响应100 continue,浏览器再发送data,服务器响应200 ok(返回数据)。
2 python
2.1 yield
生成器,是迭代器的一种,可通过next()和send()方法调用。这篇文章讲的很详细:http://kissg.me/2016/04/09/python-generator-yield/
3 其他
3.1 unicode编码
unicode编码,例如'\u0001',16位表示,范围从0x0000到0xffff,16进制表示;assic编码字符集一共有256个,用8位表示;unicode编码可包含assic编码,它的低8位用来表示assic编码;java中的char类型是两个字节,用unicode编码表示的。
4 长期更新
https://www.zhihu.com/question/35866596
5. 整理:
sequence_loss:
先求交叉熵,然后取平均
# coding:utf-8 from __future__ import unicode_literals from __future__ import print_function from __future__ import division from tensorflow.contrib.seq2seq import sequence_loss import tensorflow as tf import numpy as np output_np = np.array( [ [[0.6, 0.5, 0.3, 0.2], [0.9, 0.5, 0.3, 0.2], [1.0, 0.5, 0.3, 0.2]], [[0.2, 0.5, 0.3, 0.2], [0.3, 0.5, 0.3, 0.2], [0.4, 0.5, 0.3, 0.2]] ] ) print(output_np.shape) target_np = np.array([[0, 1, 2], [3, 0, 1]], dtype=np.int32) print(target_np.shape) output = tf.convert_to_tensor(output_np, np.float32) target = tf.convert_to_tensor(target_np, np.int32) cost = sequence_loss(output, target, tf.ones_like(target, dtype=np.float32)) init = tf.global_variables_initializer() with tf.Session() as sess: sess.run(init) cost_r = sess.run(cost) print(cost_r)