Skip to main content

bert_text_pretty 是一个bert 文本特征化和文本后处理解码的包,用于bert工程推理

# -*- coding:utf-8 -*-
import numpy as np
from bert_text_pretty import cls,ner,relation,tokenization

'''
    简化文本特征化,解码
    https://github.com/ssbuild/bert_text_pretty.git
'''


text_list = ["你是谁123456","你是谁123456222222222222"]


tokenizer = tokenization.FullTokenizer(vocab_file=r'F:\pretrain\chinese_L-12_H-768_A-12\vocab.txt',do_lower_case=True)

feat = cls.cls_text_feature(tokenizer,text_list,max_seq_len=128,with_padding=False)
print(feat)

feat = ner.ner_text_feature(tokenizer,text_list,max_seq_len=128,with_padding=False)
print(feat)

feat = relation.re_text_feature(tokenizer,text_list,max_seq_len=128,with_padding=False)
print(feat)


labels = ['标签1','标签2']
print(cls.load_labels(labels))

print(ner.load_label_bio(labels))


# def ner_decoding(example_all, id2label, logits_all,trans=None) # crf 解码
'''
    example_all 文本list , 
    id2label 标签 list or dict
    logits_all 为bert 预测结果 (batch,seq_len,num_tags) or (batch,seq_len)
    trans 是否启用trans预测 , 2D 
    解析crf序列  or 解析 已经解析过的crf序列

'''


#ner_pointer_decoding(example_all, id2label, logits_all,threshold=0.) # 指针 解码
'''
   example_all 文本list , 
   id2label 标签 list or dict
   logits_all (batch,num_labels,seq_len,seq_len)
   threshold 阈值

'''



#  cls.cls_decoding(example_all,labels,logits) #分类
'''
   example_all 文本list , 
   id2label 标签 list or dict
   logits_all (batch,hidden)
   threshold 阈值

'''



# relation.re_decoding(example_all, id2spo, logits_all)  #关旭

Metadata

Release files for bert-text-pretty 0.0.18

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for bert-text-pretty 0.0.18
File Interpreter ABI Platform
bert_text_pretty-0.0.18-py3-none-any.whl Python 3 none any Details

Release files / bert_text_pretty-0.0.18-py3-none-any.whl

Download URL bert_text_pretty-0.0.18-py3-none-any.whl
Size 13.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
95926b51a7556cb893d0ca8f046b67c03eba3d94e6f158959ccf11cea0e8178f
BLAKE2b-256 checksum
How to use checksums
de531cf62122fbb95dee2585cae86aef1759c689a40518f2c573316748a52401
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.5.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.9

Release history Release notifications | RSS feed

This release

0.0.18 This release

1 release file

0.0.9

1 release file

0.0.5

1 release file

0.0.4

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page