Bert+中文文本分类实现及参数解析

实现bert模型已经被封装好了,直接使用就可以了。但是需要自定义一个实体类,用来处理自己的数据。直接在run_classify.py中加入下面类就可以自定义MyDataProcessor类,传入class MyDataProcessor(DataProcessor): """Base class for data converters for sequence classificat...
摘要由CSDN通过智能技术生成

实现

bert模型已经被封装好了,直接使用就可以了。
但是需要自定义一个实体类,用来处理自己的数据。

直接在run_classify.py中加入下面类就可以

自定义MyDataProcessor类,传入

class MyDataProcessor(DataProcessor):
  """Base class for data converters for sequence classification data sets."""
	#data_dir对应参数中,的data_dir
  #这个方法用来处理训练数据,
  def get_train_examples(self, data_dir):
    """Gets a collection of `InputExample`s for the train set."""
    file_path=os.path.join(data_dir,"train.txt")
    file=open(file_path,'r',encoding='utf-8')
    train_data=[]
    index=0
    for line in file.readlines():
      	#标记每一行的数据
        guid = "train-%d" % (index)
        #切分数据集
        line=line.rsplit('|',1)
        #对于原始数据集做一个编码
        text_a = tokenization.convert_to_unicode(str(line[0]).replace(' ',''))
        #去掉label中多余的部分
        label = str(line[1
  • 1
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值