【python,hanlp】pyhanlp分词如何加入自定义词典

[nlp] pyhanlp安装以及自定义词典&词性 pip install pyhanlp hanlp segment 阅读详情

step1:首先找到pyhanlp的安装位置

这里分两种情况:
1、安装位置在虚拟环境

E:\apps\Anaconda3\envs\dome\Lib\sitepackages\pyhanlp\static\data\dictionary\custom

envs文件夹下面存放的就是python编译器所有的虚拟环境列表,这里我使用的是dome虚拟环境,按照这种格式”虚拟环境->Lib->site-packages->pyhanlp->static->data->dictionary->custom“一步一步找到词典存放位置,可以将自定义词典放在此文件夹下面。比如下图的:金融词库.txt就是我的金融行业的自定义词典。加入词典之后,便可以进行下一步操作,这里我的自定义词典仅仅有词没有词性和词频。一词一行行与行之间没有空格,词顶行排列,行尾没有多余的空格符。
在这里插入图片描述
在这里插入图片描述
2、未使用虚拟环境
在这里插入图片描述
没有安装虚拟环境下,而在真实环境安装pyhanlp的小伙伴直接按照上图找到site-packages目录按照Lib->site-packages->pyhanlp->static->data->dictionary->custom的路径进行和虚拟环境下进行一样的操作即可。

step2:配置自定义字典路径

1、使用虚拟环境
在这里插入图片描述
2、未使用虚拟环境
仅仅是路径不同,Anaconda3->Lib->site-packages->pyhanlp->static下找到该文件,打开进行如下图修改:
在这里插入图片描述
其中字典的先后顺序代表的是优先级。

step3:删除”CustomDictionary.txt.bin”文件,运行分词程序重新生成该文件,即可实现使用自定义字典进行分词的功能。

在这里插入图片描述
参考:https://blog.youkuaiyun.com/lzbmc/article/details/90083561

准确分词:加载自定义字典分词(pyhanlp分词示例) 目录 一、pyhanlp 1.1基本介绍 1.2 pyhanlp加入字典 二、分词对比 tokenizer.py :hanlp函数 cut_data.py 主文件 全部代码、数据集:https://github.com/455125158/NLP_basis 一、pyhanlp 1.1基本介绍 pyhanlp介绍:https://github.com/ha... 阅读详情

相关推荐

B0505S选型

    使用B0505S-1W已经有一段时间了,一直以来使用的是下面的电路,该电路摘自《CAN总线嵌入式开发——从入门到实战》一书。 参考金升阳的用户手册,手册上写道: 为了确保该模块能够高效可靠的工作,使用时,其输出最小负载不能小于额定负载的10%。若您所需功率确实较小,请在输出端并联一个电阻(电阻消耗功率与实际使用功率之和大于等于10%的额定功率)        由于使用该电源模...

动感小麦兜的博客 1万+

hannlp添加自定义 词典

为hanlp加载自定义词表。

wcc8848的博客 2741

博途WinCC上位机避坑指南:从工控机选型到趋势图优化的完整流程

本文详细解析了博途WinCC上位机开发全流程,从工控机选型到趋势图优化的关键技巧。针对工业自动化场景,提供硬件配置指南、网络优化方案和性能提升策略,帮助工程师避开常见陷阱,实现稳定高效的HMI系统部署。特别强调PC Station与传统触摸屏的选型对比及SIMATIC NET配置优化。

pp12345的博客 279

Jieba分词模式详解、词库的添加与删除、自定义词库失败的处理

当需要添加的词过多时,建议使用添加词典的方式。自定义词典可以包含用户自己添加的词语及其词频和词性等信息。创建一个文本文件,例如,用于存储自定义词典。每行格式为:词语 词频 词性。将需要添加的词语及其词频和词性等信息写入到中,每个词语一行。调用Jieba的方法加载自定义词典文件。词典示例如下:开源模型 10 n深度学习 8 n其中,10和8为词语的词频,n为词语的词性。之后调用词典即可。词典加入之后,再次进行分词,词典中的内容就可以被分出来了。

Hello Word 7262

叶绿体基因组提交NCBI全流程避坑指南

叶绿体基因组作为环状细胞器DNA,其数据提交并非简单上传,而是需严格遵循INSDC标准的学术出版行为。其核心原理在于元数据完整性、拓扑结构语义一致性与分类学路径精确匹配;技术价值体现在保障序列可追溯、可复现、可互操作;典型应用场景涵盖植物系统发育、条形码开发及合成生物学底盘构建。实践中,FASTA头行格式、feature table嵌套规则、taxid绑定及BankIt静默校验等环节极易引发失败。本文聚焦NCBI|叶绿体基因组数据上传中的高频报错与隐性约束,提供面向生物信息工程师的实操级规范解析。

weixin_31960565的博客 330

航空大数据——项目资源汇总及开源(四)

ADS-B项目开源大礼包

cyc头发还挺多的博客 4991

NLP(五十二)在BERT模型中添加自己的词汇

  不论是Tensorflow版本或者PyTorch版本的NLP预训练模型,我们都会在模型文件中看到vocab.txt文件,这个文件就是该预训练模型的词汇表。通常,模型本身都会自带词汇表文件,这是在模型预训练的时候训练得到的词汇表,具有代表性,一般不可随意更改。同时vocab.txt文件中也保留了一定数量的unused词汇,用来添加新词。   本文将介绍如何在BERT模型中添加自己的词汇,其他预训练模型原理相同。 我们将通过三个常见的模块来介绍,分别是keras-bert,transformers,toke

山阴少年 9402

ZEMAX学习 6.一个照相物镜的设计

曲线越平滑表示场曲越小,曲线越接近水平,系统边缘与中心对比度越接近,虚实越接近表示色差和色散越好;第1个面设计不合理,出现前后表面相交的情况,点击第1面厚度,选择边缘厚度,设置为0.1,第1面厚度被控制在0.1mm厚,系统根据这一设置始终保持第1面边缘厚度为0.1mm。要求:设计一个照相物镜,焦距f=9mm,F#为4,视场角40°;添加有效焦距操作数EFFL 9mm 权重为1,设置优化变量,如下图,ctrl+shift+o打开优化界面。报告中系统数据有效焦距为67.381mm,设计要求为9mm;

qq_24542783的博客 4715

HanLP:pyhanlp python中文分词,以及加入自定义词典

fw = open(HanLP_save_path, 'w', encoding='utf-8') # 分词结果保存 with open(origin_path, 'r', encoding='utf-8') as fr: # 需要分词的文档 for line in fr: line = line.strip() word_list = HanLP...

lzbmc的博客 8905

C#实现串口通讯程序

1、自动获取本地串口。2、根据传入串口基本属性参数打开串口。3、串口数据的发送接收功能(ASCII和HEX格式)。4、ASCII和HEX相互转换。csharp体验AI代码助手代码解读复制代码[Category("UserProperty")] [Description("轮廓半径")] public int Radius { get => radius;

2401_89221445的博客 1767

mapbox进阶,dem数据转为等高面,加载转换后的等高面到地图

本文详细介绍如何基于mapbox-gl v3.*.* 版本,使用dem数据转为等高面,加载转换后的等高面到地图,亲测可用。希望能帮助到您。一起学习,加油!加油!

我哎GIS博客 407

Python 实战 | 进阶中文分词之 HanLP 词典分词(上)

HanLP 分词器,一个实用且高效的自然语言处理助手,不妨试一试。

weixin_55633225的博客 2143

【智能流体力学】使用ANSYS Fluent + SpaceClaim + SCDM制作流体力学前处理的几何模型

生成来源.scdoc文件来自前处理工具生成的模型数据,或在 FLUENT 中创建和保存的模型。生成方式: 通过前处理工具导出网格数据,或在 FLUENT 中设置并保存模型。作用: 用于储存模型的结构信息和设置,确保在 FLUENT 中的正确导入和使用。.x_t文件是 Parasolid 文件格式的扩展名,用于存储三维模型数据。在 ANSYS Fluent 中,这种格式通常用于在前处理工具之间交换几何数据。要创建.x_t。

源代码杀手的博客 3265

pyhanlp添加自定义词典 强制优先自定义词典分词

自定义词典 自定义词典有多种添加模式,首先是展示的一个小例子,展示了词汇的动态增加与强行插入,删除等。 一、代码方式插入 from pyhanlp import * text = "攻城狮逆袭单身狗,迎娶白富美,走上人生巅峰" # 怎么可能噗哈哈! print(HanLP.segment(text)) CustomDictionary = JClass("com.hankcs.hanlp...

Eadon999 4469

Camera2Demo

在Camera2 的基础上进行封装,使得Camera2一堆初始化逻辑与Activity分离,降低耦合度,完成预览拍照并保存的操作

VC中sqlite的使用

在VC中对sqlite的使用,实现数据库大批数据的快速插入,读取数据库中的数据在ListCtrl中显示

[655]HanLP 分词

pyhanlp 安装 其为 HanLP 的 Python 接口,支持自动下载与升级 HanLP,兼容 Python2、Python3。 安装命令为 pip install pyhanlp,使用命令 hanlp 来验证安装。 pyhanlp 目前使用 jpype1 这个 Python 包来调用 HanLP,如果遇到: building ‘_jpype’ extensionerror: M...

周小董 3599

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

python分词自定义词典_pyhanlp用户自定义词典添加实例说明

pyhanlp用户自定义词典添加实例说明pyhanlp是python版封装的的HanLP,项目地址:https://github.com/hankcs/pyhanlp经过测试,HanLP比nltk在中文分词和实体识别方面都更好用. 如何向pyhanlp添加自定义的词典?以python 2.7.9为例:1.安装pyhanlp:pip install pyhanlp2.在字典路径下添加自定义的词典:C...

weixin_29363945的博客 889

SAP B1中文培訓教材_SDK

公司内部培训资料,对开发工具 ,DIAPI, UIAPI,Add-ON有详细解说

python自定义词典怎么用_pyhanlp用户自定义词典添加实例说明

pyhanlp用户自定义词典添加实例说明pyhanlp是python版封装的的HanLP,项目地址:https://github.com/hankcs/pyhanlp经过测试,HanLP比nltk在中文分词和实体识别方面都更好用.如何向pyhanlp添加自定义的词典?以python 2.7.9为例:1.安装pyhanlp:pip install pyhanlp2.在字典路径下添加自定义的词典:Cu...

weixin_29860267的博客 661

python怎么使用自定义停用词_pyhanlp 停用词与用户自定义词典功能详解

hanlp的词典模式之前我们看了hanlp的词性标注,现在我们就要使用自定义词典与停用词功能了,首先关于HanLP的词性标注方式具体请看HanLP词性标注集。其核心词典形式如下:自定义词典自定义词典有多种添加模式,首先是展示的一个小例子,展示了词汇的动态增加与强行插入,删除等。更复杂的内容请参考后边的第二段代码。简单的例子from pyhanlp import *text = "攻城狮逆袭单身狗,...

weixin_39624097的博客 1502

python 自定义词典_pyhanlp用户自定义词典添加

pyhanlp是python版封装的的HanLP,项目地址:https://github.com/hankcs/pyhanlp经过测试,HanLP比nltk在中文分词和实体识别方面都更好用。如何向pyhanlp添加自定义的词典?以python 2.7.9为例:1.安装pyhanlp:pip install pyhanlp2.在字典路径下添加自定义的词典:CustomDictionary主词典文本路...

weixin_39598135的博客 415

python 分词 词性_pyhanlp——分词与词性标注

这篇文章的内容是作为所有文本分类技术的基础而写的,也可以把它作为其他自然语言处理技术的基础。pyhanlp的内容很多,这篇文章先介绍分词和词性标注这一部分。顺便写一个简介。简介pyhanlp是HanLP的Python接口。因此后续所有关于pyhanlp的文章中也会写成HanLP。HanLP是完全用Java自实现的自然语言处理工具包。特点是完全用Java实现不引入第三方工具包。完全开源。中文的开源工...

weixin_39786141的博客 917

NLP第2课:中文分词利器 jieba 和 HanLP

前言 从本文开始,我们进入实战部分。首先,我们按照中文自然语言处理流程的第一步获取语料,然后重点进行中文分词的学习。中文分词有很多种,常见的比如有中科院计算所 NLPIR、哈工大 LTP、清华大学 THULAC 、斯坦福分词器、Hanlp 分词器、jieba 分词、IKAnalyzer 等。这里针对 jieba 和 HanLP 分别介绍不同场景下的中文分词应用。 j...

米饭超人的专栏 2218

pyhanlp:hanlp的python接口

HanLP的Python接口,支持自动下载与升级HanLP,兼容py2、py3。 安装 pip install pyhanlp 使用命令hanlp来验证安装,如因网络等原因自动安装失败,可参考手动配置或Windows指南。 命令行 中文分词 使用命令hanlp segment进入交互分词模式,输入一个句子并回车,HanLP会输出分词结果: $ hanlp segmen...

adnb34g的博客 3874

python定义词典_pyhanlp用户自定义词典添加

原标题:pyhanlp用户自定义词典添加pyhanlp是python版封装的的HanLP,项目地址:https://github.com/hankcs/pyhanlp经过测试,HanLP比nltk在中文分词和实体识别方面都更好用。如何向pyhanlp添加自定义的词典?以python 2.7.9为例:1.安装pyhanlp:pip install pyhanlp2.在字典路径下添加自定义的词典:Cu...

weixin_39549312的博客 380

NLP分词使用总结--python HANLP

一、我用了几个NLP框架(HANLP / NLTK / JIEBA / STANFORD-NLP)后总结出来一个 还是HANLP比较好,灵活,准确;当然大家可以留言讨论;HANLP坐着是何晗 二、我用的是python版本的--pyhanlp, 需要安装的环境 python3 / java /jype /pyhanlp .....的不详细说了 三、HANLP词性表: a形容词 ad副形词 ag形容词性语素 al形容词性惯用语 an名形词 b区...

2292

pyhanlp用户自定义词典添加

pyhanlp是python版封装的的HanLP,项目地址:https://github.com/hankcs/pyhanlp 经过测试,HanLP比nltk在中文分词和实体识别方面都更好用。 如何向pyhanlp添加自定义的词典?以python 2.7.9为例: 1.安装pyhanlp...

chuanmi6070的博客 400
上一篇: 【python】pymysql的使用-CURD
下一篇: 【NLP】自然语言处理中常见的英文单词
菜菜2022
博客等级 码龄9年 67粉丝 1033原创
评论 1
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值