
python
我是京城小白
这个作者很懒,什么都没留下…
展开
-
【调参Tricks】WhiteningBERT: An Easy Unsupervised Sentence Embedding Approach
一个猜测是,预训练语言模型生成的各个句向量应该在坐标系中的各个位置是相对均匀的,即表现出各项同性。以余弦相似度作为向量相似度衡量的指标的是建立在“标准正交基”的基础上的,基向量不同,向量中各个数值所代表的的意义也变不一样。然后经过BERT抽取之后的句向量所处的坐标系可能并非基于同一个“标准正交基”的坐标系。根据苏神的博客,只保留SVD提取出来的前N个特征值可以提升进一步的效果。并且,由于只保留了前N个特征,故与PCA的原理类似,相当于对句向量做了一步降维的操作。原创 2022-10-20 15:02:10 · 412 阅读 · 0 评论 -
pytorch问题:found at least two devices, cuda:0 and cuda:1!
RuntimeError: Expected all tensors to be on the same device, but found at least two devices, cuda:0 and cuda:1!原创 2022-10-18 23:34:07 · 4231 阅读 · 0 评论 -
pytorch 不定长序列 mask后 sum
pytorch 不定长序列 mask后 sum原创 2022-10-17 09:58:40 · 363 阅读 · 0 评论 -
python多进程读写文件
python多进程读写文件#encoding:utf-8 import numpy as np import sysimport timeimport threadingfrom queue import Queue np.random.seed(1)# Same with n_compute_threadsREAD_BATCH_SIZE=25WRITE_BATCH_SIZE=25# read_queuer_q = Queue(READ_BATCH_SIZE)原创 2021-09-22 20:01:53 · 1177 阅读 · 0 评论 -
Hadoop 取文件夹下的个数
hadoop fs -lsr [目标路径] | grep "^-"| wc -l取到的是统计文件夹下文件的个数,包括子文件夹里的。https://www.cnblogs.com/qoyi/archive/2012/02/19/2358182.html原创 2021-02-26 15:19:07 · 1087 阅读 · 0 评论 -
threading 并行Python任务
# http://www.uml.org.cn/python/201901221.aspimport threadingimport urllib.requestimport timedef download_image(url, filename): print("download txt from {}".format(url)) urllib.request.urlretrieve(url, filename) print("download done!")def ex.原创 2021-02-25 19:30:19 · 232 阅读 · 0 评论 -
使用Joblib并行运行Python代码
from multiprocessing import cpu_countfrom joblib import Parallel, delayedimport time# (1) paralleldef func(_input): time.sleep(1) return _input * 3start_time = time.time()cpu_count = cpu_count()print("cpu_count = ", cpu_count)out = P.原创 2021-02-25 19:23:20 · 643 阅读 · 0 评论 -
UnicodeEncodeError: ‘ascii‘ codec can‘t encode characters in position 4-8: ordinal not in range(128)
import sysreload(sys)sys.setdefaultencoding('utf-8')原创 2020-11-16 23:42:39 · 188 阅读 · 0 评论 -
数据分析必备,一文了解pandas
一、简介Pandas是Python的一个数据分析包,它是为了解决数据分析任务而创建的。Pandas 纳入了大量库和一些标准的数据模型,提供了高效地操作大型数据集所需的工具。Pandas提供了大量能使我们快速便捷地处理数据的函数和方法。二、数据结构数据结构: 系列(Series) 数据框(DataFrame) 面板(Panel) (多个series→ 多个数据框→ 面板)。这些数据结构构建在Numpy数组之上,这意味着它们很快。导入包 ...原创 2020-11-14 15:07:25 · 535 阅读 · 0 评论 -
python-url中中文编码与解码
接口测试中遇到这种情况:get请求的传参有中文,以致url中有中文编码。下面是常见的一种编码解码方式:from urllib.request import quote, unquoteurl = "https://www.baidu.com/s?wd=住院"res1 = quote(url, safe=";/?:@&=+$,", encoding="utf-8") # 编码print(res1) # https://www.baidu.com/s?wd=%E4%BD%8F%E9原创 2020-11-04 18:05:01 · 618 阅读 · 0 评论 -
使用joblib中的Parallel并行运行程序
joblib 是一个可以使程序并行运行的包,并行运行程序可以大大提高运行效率。下面进行简单测试:import timefrom math import sqrtdef test_func(val): time.sleep(1) return sqrt(val**2)start_time = time.time()for i in range(10): test_func(i)end_time = time.time()print("use time i原创 2020-08-24 15:55:37 · 1217 阅读 · 1 评论 -
朴素贝叶斯算法实现垃圾邮件分类
下面使用朴素贝叶斯模型,对邮件进行分类,识别邮件是不是垃圾邮件。import numpy as npfrom sklearn.metrics import accuracy_scorefrom sklearn.model_selection import train_test_splitfrom sklearn.naive_bayes import MultinomialNB# 预处理数据def text_parse(big_string): token_list = big_s原创 2020-06-14 13:35:45 · 5958 阅读 · 3 评论 -
keras vgg16模型下载
欢迎关注微信公众号:python科技园官网地址:https://github.com/fchollet/deep-learning-models/releases/download/v0.1/vgg16_weights_tf_dim_ordering_tf_kernels_notop.h5改文件放到了百度网盘中,链接和密码如下:链接:https://pan.baidu.com/s/1Exa8g_q9hVmqOU9SBrIxrg提取码:qtsb...原创 2020-06-12 00:45:20 · 1605 阅读 · 0 评论 -
tf.nn.sparse_softmax_cross_entropy_with_logits 函数简介
目录1. 函数功能2. 语法结构3. 实现步骤 第一步:计算 Softmax 第二步:计算 Cross Entropy4.示例sparse_softmax_cross_entropy_with_logits5. 示例softmax_cross_entropy_with_logits6. 补充说明函数讲解1. 函数功能多分类交叉熵计算函数。它适用于每个类别相互独立且排斥的情况,例如一幅图只能属于一类,而不能同时包含一条狗和一头大象...原创 2020-05-28 21:42:20 · 7822 阅读 · 1 评论 -
python 爬虫:https; HTTPSConnectionPool(host='z.jd.com', port=443)
1. 第一种方案import requestsrequests.get('https://www.zhihu.com/',verify=False)2. 由于python2不支持SNI,具体SNI了解转:http://blog.youkuaiyun.com/makenothing/article/details/53292335如果想python2支持SNI,pip安装3个模块: 1.pyOpenSSL ...原创 2018-05-29 09:29:26 · 25844 阅读 · 5 评论 -
python3 tensorflow 安装
兜兜转转来到了版本3.(1)使用Python2.7版本时安装不上 tensorflow;通过查看 tensorflow 版本才发现需要 Python3版本;(2)重新安装Python3.6版本;(3)cmd中直接运行:pip install tensorflow原创 2018-01-05 09:33:22 · 5766 阅读 · 0 评论 -
公司服务器 caffe 绘制网络结构图 及 问题解决
1. 在caffe-master路径下直接运行【在成功编译caffe的源码之后,可以在python环境中使用caffe】:python ./python/draw_net.py ./models/bvlc_alexnet/train_val.prototxt ./AlexNet.jpg--rankdir=LR参考:https://www.cnblogs.com/denny402/p/5原创 2018-01-22 13:32:01 · 357 阅读 · 0 评论