Skip to content

Instantly share code, notes, and snippets.

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: tabstop=4 shiftwidth=4 expandtab number
"""
演示Python Descriptor(描述符)的 基础语法和用例
Authors: qianweishuo<qzy922@gmail.com>
Date: 2020/2/1 10:45 PM
"""
@koyo922
koyo922 / glove.py
Created January 5, 2020 09:32
demo for GloVe
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: tabstop=4 shiftwidth=4 expandtab number
"""
glove的简易实现,包括
- 准备训练数据
- 训练词向量
- 实验词向量观察语义空间的降维效果
"""
BiLSTM-CRF的PyTorch教学实现,矩阵化版本,含详尽注释和举例
参考
- PyTorch官方教学代码: https://pytorch.org/tutorials/beginner/nlp/advanced_tutorial.html
- 矩阵化推导: https://zhuanlan.zhihu.com/p/44042528
- BiLSTM-CRF原文: https://arxiv.org/pdf/1508.01991v1.pdf
by 虎哥@知乎 koyo922@.qq.com 2019/12/16
"""
import torch
# !/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: tabstop=4 shiftwidth=4 expandtab number
"""
每15钟检测一次 如果发现开机太久且GPU空闲,就告警
有个免费的运维告警平台,参见 https://caweb.aiops.com/#/integrate 下面的REST API集成
弄完后添加开机自启动
chmod 755 alert_gpu_idle.py
sudo vim /etc/rc.local # 将此脚本的绝对路径写进去
"""
@koyo922
koyo922 / tfserving_demo.py
Created September 1, 2019 14:46
TensorFlow Serving Usage Demo
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: tabstop=4 shiftwidth=4 expandtab number
"""
关于 TFServing 用法的详细demo, 包括:
1. 训练一个MNIST模型
2. 将其导出为 SavedModel 格式
3. 使用TFServing Docker Image封装上述 SavedModel格式的模型,提供服务
4. 演示client的 gRPC/REST 用法
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# vim: tabstop=4 shiftwidth=4 expandtab number
################################################################################
#
# Copyright (c) 2018 Baidu.com, Inc. All Rights Reserved
#
################################################################################
@koyo922
koyo922 / MathJax.html
Last active July 10, 2018 04:37
Anki_config
<!-- Anki自带的LaTeX功能也可以了;无需这个脚本 -->
<!-- Add this to Front/Back or both, to support MathJax -->
<!-- https://www.reddit.com/r/Anki/comments/54c967/how_to_use_mathjax_in_anki_ankidroid_online_and/ -->
<!-- http://www.bootcdn.cn/mathjax/ -->
<script type="text/x-mathjax-config">
MathJax.Hub.processSectionDelay = 0;
MathJax.Hub.Config({
messageStyle:"none",
showProcessingMessages:false,
#!/usr/bin/env bash
# referencing: https://www.moerats.com/archives/507/
set -e
# Usage: pipe to `sh` on the fly, or download and use
# curl -L https://tinyurl.com/mk-inst-py | PYTHON_VERSION=<2.7.15 or 3.6.5> [SILENT_SUDO=1] sh
# wget https://tinyurl.com/mk-inst-py && PYTHON_VERSION=3.6.5 sh ./install_python_from_source.sh
if ! [[ "$PYTHON_VERSION" =~ ^(2.7.15|3.6.5)$ ]]; then # required environ var
echo "Usage: PYTHON_VERSION=<2.7.15 or 3.6.5> [SILENT_SUDO=1] sh $BASH_SOURCE"
@koyo922
koyo922 / leetcode402_alike_keep_largest.py
Last active May 15, 2018 03:20
2 interview coding problems
# 这题与LeetCode 402 极为相似;就是把『最小』改成了『最大』
#
# 链接:https://www.nowcoder.com/questionTerminal/7f26bfeccfa44a17b6b269621304dd4a
# 来源:牛客网
#
# [编程题]保留最大的数
# 时间限制:1秒
# 空间限制:32768K
#
# 给定一个十进制的正整数number,选择从里面去掉一部分数字,希望保留下来的数字组成的正整数最大。
@koyo922
koyo922 / demo.py
Last active February 5, 2018 09:18
multi thread or process for simple jobs
from parallel_util import parallel_process
arr = [1,2,3,4]
def f(v):
print(v**2)
parallel_process(arr, f)