- 博客(18)
- 收藏
- 关注
原创 pytorch Glove 下载到使用
ref:Basics of Using Pre-trained GloVe Vectors in Python.1. 下载从 glove官网 获取下载地址# 下载glove文件import urllib import requestsurllib.request.urlretrieve('https://nlp.stanford.edu/data/wordvecs/glove.840B.300d.zip', "glove.840B.300d.zip")2. 解压 glove文件压缩解压zi
2021-02-12 18:00:56
2935
4
原创 lunix unzip
# 查看 zip 文件unzip erc-training.zip'''Archive: erc-training.zip creating: erc-training/ inflating: __MACOSX/._erc-training inflating: erc-training/.DS_Store inflating: __MACOSX/erc-training/._.DS_Store creating: erc-training/dailydialo
2020-12-01 15:01:24
261
转载 visdom可视化pytorch训练过程
referance: https://www.lagou.com/lgeduarticle/36232.htmlvisdom的安装比较简单,可以直接使用pip命令。# visdom 安装指令pip install visdom #执行安装命令后,可以执行以下命令启动visdom。# 启动 visdom web服务器python -m visdom.server若安装成功,则会返回一个网页地址;若报错,则安装失败,可以自行去github上下载源码安装。将网址复制后在浏览器中打开,就可以
2020-11-30 13:28:40
377
原创 plot confusion_matrix
import seaborn as snssns.set(font_scale=1.4) # y label 横向import matplotlib.pyplot as plt'''https://zhuanlan.zhihu.com/p/35494575fmt ='.0%'#显示百分比fmt ='f' 显示完整数字 = fmt ='g'fmt ='.3'显示小数的位数 = fmt ='.3f' = fmt ='.3g''''confusion_matrix = pd.DataFram
2020-11-29 21:58:19
3513
1
原创 python 统计区间列表
from itertools import groupbynum_range = 1for k,g in groupby(sorted(all_num_of_label.astype(np.int16)),key = lambda x:x//num_range): print ('{}-{}:{}'.format(k*num_range,(k+1)*num_range-1,len(list(g))))‘’‘0-0:26901-1:88372-2:44483-3:16984-4:44
2020-11-29 20:28:15
548
原创 focal loss in pytorch
def multi_label_loss(y_pred, y_true): ''' Zhang, M. L., & Zhou, Z. H. (2006). Multilabel neural networks with applications to functional genomics and text categorization. IEEE transactions on Knowledge and Data Engineering, 18(10), 1338-1351. '''
2020-11-26 22:15:56
226
原创 focal loss in keras
from keras import backend as Kimport tensorflow as tf# import dilldef binary_focal_loss(gamma=2., alpha=.25): """ Binary form of focal loss. FL(p_t) = -alpha * (1 - p_t)**gamma * log(p_t) where p = sigmoid(x), p_t = p or 1 - p depe
2020-11-26 22:13:28
268
1
原创 pytorch 中对某一层参数设置限制
想要设置某一层的weight值在0-1之间:参考回答:https://discuss.pytorch.org/t/set-constraints-on-parameters-or-layers/23620/11It is impossible to declare a constrained parameter in pytorch. So, in init an unconstained parameter is declared, e.g.:self.my_param = nn.Parameter
2020-11-26 20:01:22
3763
2
原创 pytorch: 根据mask标记,从pad的层级数据中取出非pad的 true 和 pred 数据
def collect_NotMask_sents(y_true,y_out,mask): ''' y_pred,y_true: shape = (batch, max_len, n_class) mask.shape = (batch, max_len,) mask 中pad 部分为 0,真实存在句子则为 1 return: all_true,all_out, 非mask 的句子,shape = [n,n_class] '''
2020-11-26 16:20:41
619
原创 Bert-BiLSTM-CRF pytorch 代码解析-3:def _viterbi_decode
理解 github上代码:Bert-BiLSTM-CRF-pytorchGithub 相关链接: link.这部分用于解码阶段def _viterbi_decode(self, feats, mask=None): """ Args: feats: size=(batch_size, seq_len, self.target_size+2) mask: size=(batch_size, seq_len) Returns: de
2020-11-18 16:28:51
1209
原创 Bert-BiLSTM-CRF pytorch 代码解析-2:def _score_sentence(self, scores, mask, tags)
理解 github上代码:Bert-BiLSTM-CRF-pytorchGithub 相关链接: link.neg_log_likelihood_loss = forward_score - gold_score这部分应该是为了计算真实径的分数(gold_score) def _score_sentence(self, scores, mask, tags): """ Args: scores: size=(seq_len, batch
2020-11-18 13:58:03
657
原创 Bert-BiLSTM-CRF pytorch 代码解析-1:def _forward_alg(self, feats, mask=None)
理解 github上代码:Bert-BiLSTM-CRF-pytorchGithub 相关链接: link. def _forward_alg(self, feats, mask=None): """ Do the forward algorithm to compute the partition function (batched). Args: feats: size=(batch_size, seq_len, sel
2020-11-17 20:24:24
2946
1
原创 pytorch 中遇到的 code
masked_copy_(mask, source)将mask中值为1元素对应的source中位置的元素复制到本tensor中。mask应该有和本tensor相同数目的元素。a = torch.zeros(3, 4).byte()index = torch.LongTensor([0])mask = a.index_fill_(0, index, 1)print(mask)source = torch.randn(3, 4)print(source)target = torch.on.
2020-11-17 18:03:11
167
原创 class AttrDict(dict)
class AttrDict(dict)在 jupyter notebook 中加入属性词典class AttrDict(dict): def __init__(self, *args, **kwargs): super(AttrDict, self).__init__(*args, **kwargs) self.__dict__ = selfconfig = AttrDict()config.update({ 'label_file': './da
2020-11-13 17:58:24
1480
翻译 seq2seq model
原文链接: link.把Seq2Seq模型打包的库。安装:sudo pip install git+https://github.com/farizrahman4u/seq2seq.gitRequirements:KerasRecurrent Shop主要包括的模型:1. A simple Seq2Seq model:import seq2seqfrom seq2seq.models import SimpleSeq2Seqmodel = SimpleSeq2Seq(input_
2020-06-12 21:44:14
488
原创 查看GPU
查看当前可使用的GPU:# import tensorflow as tfsess = tf.Session(config=tf.ConfigProto(log_device_placement=True))'''Device mapping:/job:localhost/replica:0/task:0/device:XLA_CPU:0 -> device: XLA_CPU device/job:localhost/replica:0/task:0/device:XLA_GPU:0 -&
2020-06-12 21:43:44
922
1
原创 文本生成中的 mask CrossEntropy -Tensorflow
文本生成中的真实标签为 index,shape = [n_batch,]输出的为概率分布,shape = [n_batch, num_decoder_tokens]计算 loss 时应 mask 序列 padding部分Example:sess = tf.Session()y_label_onehot = tf.convert_to_tensor([[1, 0, 0, 0], [0, 0, 1, 0]], dtype=tf.int64)y_label = tf.argmax(y_label_o
2020-06-10 15:21:26
1221
翻译 tf.pad
tf.padPads a tensorPads a tensor链接: tf.pad.tf.pad(tensor, paddings, mode='CONSTANT', constant_values=0, name=None)’‘’paddings.shape = [n, 2],其中 n 是 tensor的维度The padded size of each dimension D of the output is:paddings[D, 0]
2020-06-10 14:37:28
138
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人