CRF中文分词开源版发布啦

 

langiner@gmail.com

中文分词是互联网应用不可缺少的基础技术之一,也是语音和语言产品必不可少的技术组件。 自2003年第一届国际中文分词评测以来,由字构词的分词方法获得了压倒性优势,国内主要通过CRF++开源软件包来学习该分词方法,但是CRF++过于复杂的代码结构,导致了该算法的普及率。

本次首先发布了CRF中文分词开源版(http://xiazai.zol.com.cn/detail/41/407136.shtml)仅仅包含CRF++软件包中分词解码器部分,简化了CRF++复杂代码结构,清除了分词解码器不需要的代码,大大提高了分词解码器的可读性和可懂度。同时为了方便学习者可视化跟踪和调试代码,在Windows平台下分别建立了VC6.0和VS2008两个工程文件,使得VC6.0用户和VS2008用户都能轻玩转中文分词。

开源包中的分词知识库较小,分词精度较低,仅供学习Crf分词算法使用。后续将继续发布更高精度和更高速度分词引擎。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
BERT-BiLSTM-CRF是一种基于深度学习的中文分词方法,它结合了BERT预训练模型、双向长短时记忆网络(BiLSTM)和条件随机场(CRF)模型。具体流程如下: 1. 预处理:将中文文本转换为字符序列,并将每个字符转换为对应的向量表示。 2. BERT编码:使用BERT模型对字符序列进行编码,得到每个字符的上下文表示。 3. BiLSTM编码:将BERT编码后的字符向量输入到双向LSTM中,得到每个字符的上下文表示。 4. CRF解码:使用CRF模型对BiLSTM编码后的结果进行解码,得到最终的分词结果。 以下是BERT-BiLSTM-CRF中文分词的Python代码示例: ```python import torch import torch.nn as nn from transformers import BertModel class BertBiLSTMCRF(nn.Module): def __init__(self, bert_path, num_tags): super(BertBiLSTMCRF, self).__init__() self.bert = BertModel.from_pretrained(bert_path) self.lstm = nn.LSTM(input_size=self.bert.config.hidden_size, hidden_size=self.bert.config.hidden_size // 2, num_layers=1, bidirectional=True, batch_first=True) self.dropout = nn.Dropout(p=0.5) self.fc = nn.Linear(self.bert.config.hidden_size, num_tags) self.crf = CRF(num_tags) def forward(self, input_ids, attention_mask): bert_output = self.bert(input_ids=input_ids, attention_mask=attention_mask)[0] lstm_output, _ = self.lstm(bert_output) lstm_output = self.dropout(lstm_output) emissions = self.fc(lstm_output) return emissions def loss(self, input_ids, attention_mask, tags): emissions = self.forward(input_ids, attention_mask) loss = self.crf(emissions, tags, mask=attention_mask.byte(), reduction='mean') return -loss def decode(self, input_ids, attention_mask): emissions = self.forward(input_ids, attention_mask) return self.crf.decode(emissions, attention_mask.byte()) ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值