Sayarara's notebook

blogs/notes/readings


  • Home

  • Archives

  • Search

Hello World

Posted on 2019-01-30

Welcome to Hexo! This is your very first post. Check documentation for more info. If you get any problems when using Hexo, you can find the answer in troubleshooting or you can ask me on GitHub.

Quick Start

Create a new post

1
$ hexo new "My New Post"

More info: Writing

Run server

1
$ hexo server

More info: Server

Generate static files

1
$ hexo generate

More info: Generating

Deploy to remote sites

1
$ hexo deploy

More info: Deployment

AllenNLP基础

Posted on 2018-12-20

安装

pipenv install allennlp

启动

allennlp

出现错误 ModuleNotFoundError: No module named ‘_sqlite3’

解决方案,编译安装python:
yum install sqlite-devel
cd python-3.6.1
./configure
make
make install 

然后import sqlite3无错。

CentOS系统-python安装libsvm

Posted on 2018-12-20 | In notes.tools

基本步骤,(如果安装在系统的python中)

下载libsvm,地址http://www.csie.ntu.edu.tw/~cjlin/libsvm/

解压

解压方法 https://sayarara.github.io/2018/11/26/linux常用命令清单/

tar -xzf  libsvm-3.23.tar.gz

cd 进入libsvm-3.23文件夹,然后make

cd libsvm-3.23
make

cd 进入libsvm的python子文件夹 /libsvm-3.23/python

cd python
make

拷贝编译好的文件

将该python文件夹下的.py 文件拷贝到系统python的site-packages中,将其上一级目录中的libsvm.so.2拷贝到系统python中

$ sudo cp *.py /usr/lib/python2.7/site-packages/
$ cd ..
$ sudo cp libsvm.so.2 /usr/lib/python2.7/

检查是否安装成功

新开一个terminal,进入python

import svm
import svmutil

如果安装在虚拟环境中(比如pipenv)

同基本步骤,但是将编译好的.py文件和libsvm.so.2文件拷贝到虚拟环境路径下

获得虚拟环境路径

(testpipenv3) [root@VM_32_16_centos testpipenv3]# pipenv --venv
/root/.local/share/virtualenvs/testpipenv3-gvhz0M9a

拷贝

$ sudo cp *.py /root/.local/share/virtualenvs/testpipenv3-gvhz0M9a/lib/python3.6/site-packages
$ cd ..
$ sudo cp libsvm.so.2 /root/.local/share/virtualenvs/testpipenv3-gvhz0M9a/lib/python3.6/    

待学习清单

Posted on 2018-12-18 | In notes
  • Rust. 用Rust来优化Python性能。
  • vue.js 或者react替换django前端
  • AllenNLP

paper list
多人编辑 解决一致性问题的CRDT模型 (自主性,零共识自动解决冲突)

  • High Responsiveness for Group Editing CRDTs https://pages.lip6.fr/Marc.Shapiro/papers/rgasplit-group2016-11.pdf
  • CRDT——解决最终一致问题的利器 https://yq.aliyun.com/articles/635632?utm_content=m_1000015503

serverless

  • zappa https://github.com/Miserlou/Zappa#using-a-local-repo

条件随机场CRF

Posted on 2018-12-17 | In notes.algorithm

CRF(条件随机场,Conditional Random Field)

  1. 用简单的语言理解CRF https://www.sohu.com/a/207085690_206784
  2. 以例子的方式来说明CRF https://www.imooc.com/article/27795
  3. 详细的阐述 https://zhuanlan.zhihu.com/P/28465510
  4. An Introduction to Conditional Random Fields http://homepages.inf.ed.ac.uk/csutton/publications/crftut-fnt.pdf

系统评估

Posted on 2018-12-13 | In notes.tools

RAIL performance model

System should feel lightweight and responsive. 用于保证人机交互的友好性。

RAIL 模型 https://developers.google.com/web/fundamentals/performance/rail
一种以用户为中心的性能模型

RAIL 步骤 关键指标 用户操作
响应 response 输入延迟时间(从点按到绘制)小于 100 毫秒。 用户点按按钮(例如打开导航)
动画 animation 每个帧的工作(从 JS 到绘制)完成时间小于 16 毫秒。 用户滚动页面,拖动手指(例如,打开菜单)或看到动画。 拖动时,应用的响应与手指位置有关(例如,拉动刷新、滑动轮播)。 此指标仅适用于拖动的持续阶段,不适用于开始阶段。
空闲 idle 主线程 JS 工作分成不大于 50 毫秒的块 用户没有与页面交互,但主线程应足够用于处理下一个用户输入。2
加载 load 页面可以在 1000 毫秒内就绪。 用户加载页面并看到关键路径内容。

Chrome DevTools

Performance (原Timeline)和 Memory (原Profile)工具用于记录用户操作和分析性能。

Chrome DevTools 使用详解: https://segmentfault.com/a/1190000007877846

Chrome DevTools(Chrome 开发者工具) 是内嵌在 Chrome 浏览器里的一组用于网页制作和调试的工具。
Chrome 金丝雀版本(Chrome Canary)可以获得最新版本的 DevTools

访问 DevTools

  • 选择右上角Chrome 菜单,然后选择更多工具 -> 开发者工具
  • 右键,选择检查/审查元素

快捷键打开:

  • Ctrl + Shift + I, F12 / Cmd + Opt + I,打开 DevTools
  • Ctrl + Shift + J / Cmd + Opt + J,打开 DevTools,并且定位到控制台面板
  • Ctrl + Shift + C / Cmd + Opt + C,打开 DevTools,并且开启审查元素模式(相当于点击了 DevTools 左上角的图标)

其他常用快捷键:

  • F5, Ctrl + R / Cmd + R,刷新页面
  • Ctrl + F5, Ctrl + Shift + R / Cmd + Shift + R,刷新页面并忽略缓存
  • Ctrl + ‘+’ / Cmd + Shift + ‘+’,放大 DevTools
  • Ctrl + ‘-‘ / Cmd + Shift + ‘-‘,缩小 DevTools
  • Ctrl + 0 / Cmd + 0,DevTools 恢复大小

涉及太多前端,放弃使用。

Python常见错误

Posted on 2018-12-12 | In bug

18个新手常见Python运行时错误 https://blog.csdn.net/newtonnl/article/details/70792289

SyntaxError: invalid syntax

  • 括号没有成对出现,会导致下一行代码中提示出现该错误
  • 忘记在 if , elif , else , for , while , class ,def 声明末尾添加 :

SourceTree使用基础

Posted on 2018-12-12 | In notes.tools

安装及配置

参考windows系统配置指南

push本地代码至远程仓库

  • 拖动文件到本地目标文件夹
  • 拖动本地修改文件至已暂存
  • 添加本地修改记录,提交至本地仓库
  • push(点击推送)到远程仓库

python字典value查key

Posted on 2018-12-11 | In notes.code

key查value

dict ['key']

value查key

确保value值distinct

1
2
3
4
5
6
7
8
9
10
11
12
13
#法1
def get_key1 (dict, value):
return [k for k, v in dict.items() if v == value]

#法2
def get_key2 (dict, value):
return list (dict.keys()) [list (dict.values()).index (value)]

#法3: 反转原字典,由原来的K-V存储形式,变为V-K存储形式

def get_key3 (dict, value):
new_dict = {v : k for k, v in dict.items()}
return new_dict[value]

PyTorch基础

Posted on 2018-12-03 | In notes.deeplearning

与Tensorflow的静态计算图不同,pytorch的计算图是动态的,可以根据计算需要实时改变计算图
基于python,具备GPU加速的张量和动态神经网络深度学习框架。

安装

按照官网指示,https://pytorch.org

python 3.6 cpu 稳定版
pip3 install http://download.pytorch.org/whl/cpu/torch-0.4.1-cp36-cp36m-linux_x86_64.whl
pip3 install torchvision

—可以换个有gpu的服务器么。。。

教程

官方教程

  • 初级教程,通俗易懂 https://pytorch.org/tutorials/beginner/nlp/pytorch_tutorial.html#sphx-glr-beginner-nlp-pytorch-tutorial-py

Pytorch张量运算

100多种,包括转置,数学运算,线性代数,索引切分 https://pytorch.org/docs/stable/torch.html

Tensor创建:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# torch.tensor(data) creates a torch.Tensor object with the given data.
# 1D tensor: vector
V_data = [1., 2., 3.]
V = torch.tensor(V_data)

# Creates a matrix
# 2D tensor 矩阵
M_data = [[1., 2., 3.], [4., 5., 6]]
M = torch.tensor(M_data)

# Create a 3D tensor of size 2x2x2.
# 3D tensor
T_data = [[[1., 2.], [3., 4.]],
[[5., 6.], [7., 8.]]]
T = torch.tensor(T_data)

# Index into V and get a scalar (0 dimensional tensor)
print(V[0])
# Get a Python number from it
print(V[0].item())

# Index into M and get a vector
print(M[0])

# Index into T and get a matrix
print(T[0])

concatenation运算

1
2
3
4
5
6
7
8
9
10
11
12
13
14
# By default, it concatenates along the first axis (concatenates rows)
# 行连接
x_1 = torch.randn(2, 5) #2行5列
y_1 = torch.randn(3, 5) #3行5列
z_1 = torch.cat([x_1, y_1])
print(z_1) #5行5列

# Concatenate columns:
# 列连接
x_2 = torch.randn(2, 3) #2行3列
y_2 = torch.randn(2, 5) #2行5列
# second arg specifies which axis to concat along
z_2 = torch.cat([x_2, y_2], 1)
print(z_2) #2行8列

Reshaping Tensors

1
2
3
4
5
x = torch.randn(2, 3, 4) # 2*3*4的随机tensor
print(x)
print(x.view(2, 12)) # Reshape to 2 rows, 12 columns
# Same as above. If one of the dimensions is -1, its size can be inferred
print(x.view(2, -1)) #如果某一维是-1,它的具体大小会被自动推断而出。

Torch Tensor与 NumPy array的互相转换

Converting a Torch Tensor to a NumPy array

1
2
3
4
5
6
7
8
9
from __future__ import print_function
import torch
a = torch.ones(5)
b = a.numpy()

# a变化之后b也会跟着变
a.add_(1)
print(a)
print(b)

Converting NumPy Array to Torch Tensor

1
2
3
4
5
6
import numpy as np
a = np.ones(5)
b = torch.from_numpy(a)
np.add(a, 1, out=a) #a变化之后b也会跟着变
print(a)
print(b)

autograd 自动求导

原理

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
# Tensor factory methods have a ``requires_grad`` flag
x = torch.tensor([1., 2., 3], requires_grad=True)

# With requires_grad=True, you can still do all the operations you previously
# could
y = torch.tensor([4., 5., 6], requires_grad=True)
z = x + y
print(z)
# BUT z knows something extra.
print(z.grad_fn) #grad_fn=<AddBackward0>

s = z.sum()
print(s)
print(s.grad_fn) #grad_fn=<SumBackward0>

# what is the derivative of this sum with respect to the first component of x?
# s knows that it was created as a sum of the tensor z. z knows that it was the sum x + y
# calling .backward() on any variable will run backprop, starting from it.
s.backward()
print(x.grad) #tensor([1., 1., 1.])

脱离自动求导的方法

z.detach()

该命令将z从计算历史中分离出来。

returns a tensor that shares the same storage as z, but with the computation history forgotten. It doesn’t know anything
about how it was computed.

with torch.no_grad()

将需要停止自动求导的代码库放置于with torch.no_grad() 范围内

1
2
3
4
5
print(x.requires_grad)  #True
print((x ** 2).requires_grad) #True

with torch.no_grad():
print((x ** 2).requires_grad) #False

Neural networks

Training a Classifier

先使用python包将数据导入成numpy array

  • images: Pillow, OpenCV
  • audio: scipy and librosa
  • text: NLTK and SpaCy

torchvision包提供了计算机视觉领域 Imagenet, CIFAR10, MNIST等数据集的数据入口。
torchvision.datasets
torch.utils.data.DataLoader

12…5

Sayarara

42 posts
9 categories
36 tags
© 2019 Sayarara
Powered by Hexo
|
Theme — NexT.Muse v5.1.4