<jupyter_start><jupyter_text>点击下列图标在线运行HanLP		  安装 无论是Windows、Linux还是macOS，HanLP的安装只需一句话搞定：<jupyter_code>!pip install hanlp -U<jupyter_output><empty_output><jupyter_text>加载模型HanLP的工作流程是先加载模型，模型的标示符存储在`hanlp.pretrained`这个包中，按照NLP任务归类。<jupyter_code>import hanlp
hanlp.pretrained.mtl.ALL # MTL多任务，具体任务见模型名称，语种见名称最后一个字段或相应语料库<jupyter_output><empty_output><jupyter_text>调用`hanlp.load`进行加载，模型会自动下载到本地缓存。自然语言处理分为许多任务，分词只是最初级的一个。与其每个任务单独创建一个模型，不如利用HanLP的联合模型一次性完成多个任务：<jupyter_code>HanLP = hanlp.load(hanlp.pretrained.mtl.CLOSE_TOK_POS_NER_SRL_DEP_SDP_CON_ELECTRA_BASE_ZH)<jupyter_output><empty_output><jupyter_text>词性标注任务越少，速度越快。如指定仅执行词性标注，默认CTB标准：<jupyter_code>HanLP([['HanLP为生产环境带来次世代最先进的多语种NLP技术。'], ['我的希望是希望张晚霞的背影被晚霞映红。']], tasks='pos').pretty_print()<jupyter_output><empty_output><jupyter_text>注意上面两个“希望”的词性各不相同，一个是名词另一个是动词。执行PKU词性标注：<jupyter_code>HanLP([['HanLP为生产环境带来次世代最先进的多语种NLP技术。'], ['我的希望是希望张晚霞的背影被晚霞映红。']], tasks='pos/pku').pretty_print()<jupyter_output><empty_output><jupyter_text>同时执行所有标准的词性标注：<jupyter_code>print(HanLP([['HanLP为生产环境带来次世代最先进的多语种NLP技术。'], ['我的希望是希望张晚霞的背影被晚霞映红。']], tasks='pos*'))<jupyter_output>{
  "tok/fine": [
    ["HanLP", "为", "生产", "环境", "带来", "次", "世代", "最", "先进", "的", "多语种", "NLP", "技术", "。"],
    ["我", "的", "希望", "是", "希望", "张晚霞", "的", "背影", "被", "晚霞", "映红", "。"]
  ],
  "pos/ctb": [
    ["NR", "P", "NN", "NN", "VV", "JJ", "NN", "AD", "JJ", "DEG", "NN", "NR", "NN", "PU"],
    ["PN", "补语成分", "名词", "VC", "动词", "NR", "DEG", "NN", "LB", "NN", "VV", "PU"]
  ],
  "pos/pku": [
    ["nx", "p", "vn", "n", "v", "b", "n", "d", "a", "u", "n", "nx", "n", "w"],
    ["r", "u", "n", "v", "v", "nr", "u", "n", "p", "n", "v", "w"]
  ],
  "pos/863": [
    ["w", "p", "v", "n", "v", "a", "nt", "d", "a", "u", "n", "ws", "n", "w"],
    ["r", "u", "n", "vl", "v", "nh", "u", "n", "p", "n", "v", "w"]
  ]
}<jupyter_text>以`pos`开头的字段为词性，以`tok`开头的第一个数组为单词，两者按下标一一对应。  注意Native API的输入单位限定为句子，需使用[多语种分句模型](https://github.com/hankcs/HanLP/blob/master/plugins/hanlp_demo/hanlp_demo/sent_split.py)或[基于规则的分句函数](https://github.com/hankcs/HanLP/blob/master/hanlp/utils/rules.pyL19)先行分句。RESTful同时支持全文、句子、已分词的句子。除此之外，RESTful和native两种API的语义设计完全一致，用户可以无缝互换。  自定义词典自定义词典为词性标注任务的成员变量，要操作自定义词典，先获取一个词性标注任务，以CTB标准为例：<jupyter_code>pos = HanLP['pos/ctb']
pos<jupyter_output><empty_output><jupyter_text>自定义单个词性：<jupyter_code>pos.dict_tags = {'HanLP': 'state-of-the-art-tool'}
HanLP("HanLP为生产环境带来次世代最先进的多语种NLP技术。", tasks='pos/ctb').pretty_print()<jupyter_output><empty_output><jupyter_text>根据上下文自定义词性：<jupyter_code>pos.dict_tags = {('的', '希望'): ('补语成分', '名词'), '希望': '动词'}
HanLP("我的希望是希望张晚霞的背影被晚霞映红。", tasks='pos/ctb').pretty_print()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.24858969537420084, 'fraction_numerical': 0.00188040616773223, 'mean_word_length': 9.27027027027027, 'pattern_counts': {'":': 4, '<': 36, '<?xml version=': 0, '>': 36, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '440553', 'license': 'Apache-2.0', 'n_tokens_mistral': 1652, 'n_tokens_neox': 1812, 'n_words': 142, 'path': 'plugins/hanlp_demo/hanlp_demo/zh/pos_mtl.ipynb', 'repo_name': 'chen88358323/HanLP', 'size': '2659'}