repo stringlengths 7 90 | file_url stringlengths 81 315 | file_path stringlengths 4 228 | content stringlengths 0 32.8k | language stringclasses 1
value | license stringclasses 7
values | commit_sha stringlengths 40 40 | retrieved_at stringdate 2026-01-04 14:38:15 2026-01-05 02:33:18 | truncated bool 2
classes |
|---|---|---|---|---|---|---|---|---|
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/pretrained/amr2text.py | hanlp/pretrained/amr2text.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2022-12-07 15:19
from hanlp_common.constant import HANLP_URL
AMR3_GRAPH_PRETRAIN_GENERATION = HANLP_URL + 'amr2text/amr3_graph_pretrain_generation_20221207_153535.zip'
'''A seq2seq (:cite:`bevilacqua-etal-2021-one`) BART (:cite:`lewis-etal-2020-bart`) large AMR2Text gene... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/pretrained/glove.py | hanlp/pretrained/glove.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-08-27 20:42
_GLOVE_6B_ROOT = 'http://downloads.cs.stanford.edu/nlp/data/glove.6B.zip'
GLOVE_6B_50D = _GLOVE_6B_ROOT + '#' + 'glove.6B.50d.txt'
'Global Vectors for Word Representation (:cite:`pennington-etal-2014-glove`) 50d trained on 6B tokens.'
GLOVE_6B_100D = _G... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/pretrained/classifiers.py | hanlp/pretrained/classifiers.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-01-01 03:51
from hanlp_common.constant import HANLP_URL
CHNSENTICORP_BERT_BASE_ZH = HANLP_URL + 'classification/chnsenticorp_bert_base_20211228_163210.zip'
SST2_ALBERT_BASE_EN = HANLP_URL + 'classification/sst2_albert_base_20211228_164917.zip'
LID_176_FASTTEXT_BASE... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/pretrained/fasttext.py | hanlp/pretrained/fasttext.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-30 18:57
FASTTEXT_DEBUG_EMBEDDING_EN = 'https://elit-models.s3-us-west-2.amazonaws.com/fasttext.debug.bin.zip'
FASTTEXT_CC_300_EN = 'https://dl.fbaipublicfiles.com/fasttext/vectors-crawl/cc.en.300.bin.gz'
'FastText (:cite:`bojanowski2017enriching`) embeddings trai... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/pretrained/sdp.py | hanlp/pretrained/sdp.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-31 23:54
from hanlp_common.constant import HANLP_URL
SEMEVAL16_NEWS_BIAFFINE_ZH = HANLP_URL + 'sdp/semeval16-news-biaffine_20191231_235407.zip'
'Biaffine SDP (:cite:`he-choi-2019`) trained on SemEval16 news data.'
SEMEVAL16_TEXT_BIAFFINE_ZH = HANLP_URL + 'sdp/sem... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/pretrained/rnnlm.py | hanlp/pretrained/rnnlm.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-19 03:47
from hanlp_common.constant import HANLP_URL
FLAIR_LM_FW_WMT11_EN_TF = HANLP_URL + 'lm/flair_lm_wmt11_en_20200211_091932.zip#flair_lm_fw_wmt11_en'
'The forward LSTM of Contextual String Embedding (:cite:`akbik-etal-2018-contextual`).'
FLAIR_LM_BW_WMT11_EN... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/pretrained/tok.py | hanlp/pretrained/tok.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-28 21:12
from hanlp_common.constant import HANLP_URL
SIGHAN2005_PKU_CONVSEG = HANLP_URL + 'tok/sighan2005-pku-convseg_20200110_153722.zip'
'Conv model (:cite:`wang-xu-2017-convolutional`) trained on sighan2005 pku dataset.'
SIGHAN2005_MSR_CONVSEG = HANLP_URL + 't... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/pretrained/__init__.py | hanlp/pretrained/__init__.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-28 19:10
from hanlp.pretrained import tok
from hanlp.pretrained import dep
from hanlp.pretrained import sdp
from hanlp.pretrained import glove
from hanlp.pretrained import pos
from hanlp.pretrained import rnnlm
from hanlp.pretrained import word2vec
from hanlp.pret... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/pretrained/pos.py | hanlp/pretrained/pos.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-29 01:57
from hanlp_common.constant import HANLP_URL
CTB5_POS_RNN = HANLP_URL + 'pos/ctb5_pos_rnn_20200113_235925.zip'
'An old school BiLSTM tagging model trained on CTB5.'
CTB5_POS_RNN_FASTTEXT_ZH = HANLP_URL + 'pos/ctb5_pos_rnn_fasttext_20191230_202639.zip'
'An... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/pretrained/ner.py | hanlp/pretrained/ner.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-30 20:07
from hanlp_common.constant import HANLP_URL
MSRA_NER_BERT_BASE_ZH = HANLP_URL + 'ner/ner_bert_base_msra_20211227_114712.zip'
'BERT model (:cite:`devlin-etal-2019-bert`) trained on MSRA with 3 entity types.'
MSRA_NER_ALBERT_BASE_ZH = HANLP_URL + 'ner/msra... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/pretrained/mtl.py | hanlp/pretrained/mtl.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-12-22 13:16
from hanlp_common.constant import HANLP_URL
OPEN_TOK_POS_NER_SRL_DEP_SDP_CON_ELECTRA_SMALL_ZH = HANLP_URL + 'mtl/open_tok_pos_ner_srl_dep_sdp_con_electra_small_20201223_035557.zip'
"Electra (:cite:`clark2020electra`) small version of joint tok, pos, ner,... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/pretrained/sts.py | hanlp/pretrained/sts.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2021-05-24 12:51
from hanlp_common.constant import HANLP_URL
STS_ELECTRA_BASE_ZH = HANLP_URL + 'sts/sts_electra_base_zh_20210530_200109.zip'
'A naive regression model trained on concatenated STS corpora.'
# Will be filled up during runtime
ALL = {}
| python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/pretrained/constituency.py | hanlp/pretrained/constituency.py | # -*- coding:utf-8 -*-
# Author=hankcs
# Date=2022-01-18 10:34
from hanlp_common.constant import HANLP_URL
CTB9_CON_ELECTRA_SMALL = HANLP_URL + 'constituency/ctb9_con_electra_small_20220215_230116.zip'
'Electra (:cite:`clark2020electra`) small tree CRF model (:cite:`ijcai2020-560`) trained on CTB9 with major categorie... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/tests/test_pipeline.py | tests/test_pipeline.py | import unittest
import hanlp
class TestPipeLine(unittest.TestCase):
def test_copy(self):
pipe = hanlp.pipeline().append(hanlp.utils.rules.split_sentence)
copied_pipe = pipe.copy()
test_text = "今天天气真好。我要去散步。"
assert pipe is not copied_pipe
copied_pipe.append(lambda sent: "".... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/tests/test_rules.py | tests/test_rules.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2022-03-22 17:17
import unittest
from hanlp.utils.rules import split_sentence
class TestRules(unittest.TestCase):
def test_eos(self):
self.assertListEqual(list(split_sentence('叶')), ['叶'])
self.assertListEqual(list(split_sentence('他说:“加油。”谢谢')), ['他... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/tests/test_mtl.py | tests/test_mtl.py | import hanlp
import unittest
from multiprocessing.dummy import Pool
from hanlp_common.document import Document
mtl = hanlp.load(hanlp.pretrained.mtl.CLOSE_TOK_POS_NER_SRL_DEP_SDP_CON_ELECTRA_SMALL_ZH, devices=-1)
def tokenize(mtl, text):
return mtl(text, tasks='tok/fine')['tok/fine']
class TestMultiTaskLearnin... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/tests/__init__.py | tests/__init__.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-06-13 23:43
import os
root = os.path.abspath(os.path.join(os.path.dirname(__file__), os.pardir))
def cdroot():
"""
cd to project root, so models are saved in the root folder
"""
os.chdir(root)
| python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/tests/test_string_util.py | tests/test_string_util.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2022-03-22 17:17
import unittest
from hanlp.utils.string_util import possible_tokenization
class TestStringUtility(unittest.TestCase):
def test_enumerate_tokenization(self):
text = '商品和服务'
toks = possible_tokenization(text)
assert len(set(to... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/tests/test_config_tracker.py | tests/test_config_tracker.py | import unittest
from hanlp.common.structure import ConfigTracker
class MyClass(ConfigTracker):
def __init__(self, i_need_this='yes') -> None:
super().__init__(locals())
class TestConfigTracker(unittest.TestCase):
def test_init(self):
obj = MyClass()
self.assertEqual(obj.config.get('... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_restful/setup.py | plugins/hanlp_restful/setup.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-28 19:26
from os.path import abspath, join, dirname
from setuptools import find_packages, setup
this_dir = abspath(dirname(__file__))
with open(join(this_dir, 'README.md'), encoding='utf-8') as file:
long_description = file.read()
setup(
name='hanlp_rest... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_restful/tests/__init__.py | plugins/hanlp_restful/tests/__init__.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-11-29 18:05
| python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_restful/tests/test_client.py | plugins/hanlp_restful/tests/test_client.py | import unittest
from hanlp_restful import HanLPClient
class TestClient(unittest.TestCase):
def setUp(self) -> None:
self.HanLP = HanLPClient('https://hanlp.hankcs.com/api', auth=None) # Fill in your auth
def test_raw_text(self):
text = '2021年HanLPv2.1为生产环境带来次世代最先进的多语种NLP技术。阿婆主来到北京立方庭参观自然语义... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_restful/hanlp_restful/__init__.py | plugins/hanlp_restful/hanlp_restful/__init__.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-11-29 17:48
import json
from typing import Union, List, Optional, Dict, Any, Tuple
from urllib.error import HTTPError
from urllib.parse import urlencode
from urllib.request import Request, urlopen
from hanlp_common.document import Document
try:
# noinspection Py... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_trie/setup.py | plugins/hanlp_trie/setup.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-28 19:26
from os.path import abspath, join, dirname
from setuptools import find_packages, setup
this_dir = abspath(dirname(__file__))
with open(join(this_dir, 'README.md'), encoding='utf-8') as file:
long_description = file.read()
setup(
name='hanlp_trie... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_trie/tests/test_trie_dict.py | plugins/hanlp_trie/tests/test_trie_dict.py | import unittest
from hanlp_trie import TrieDict
class TestTrieDict(unittest.TestCase):
def setUp(self) -> None:
super().setUp()
self.text = '第一个词语很重要,第二个词语也很重要'
self.trie_dict = TrieDict({'重要': 'important'})
def test_tokenize(self):
self.assertEqual([(6, 8, 'important'), (16... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_trie/tests/__init__.py | plugins/hanlp_trie/tests/__init__.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-11-29 18:05
| python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_trie/tests/test_trie.py | plugins/hanlp_trie/tests/test_trie.py | import unittest
from hanlp_trie import Trie
class TestTrie(unittest.TestCase):
def build_small_trie(self):
return Trie({'商品': 'goods', '和': 'and', '和服': 'kimono', '服务': 'service', '务': 'business'})
def assert_results_valid(self, text, results, trie):
for begin, end, value in results:
... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_trie/hanlp_trie/dictionary.py | plugins/hanlp_trie/hanlp_trie/dictionary.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-11-29 17:53
from abc import ABC, abstractmethod
from typing import List, Tuple, Any, Dict, Union, Sequence, Iterable, Optional
from hanlp_common.configurable import Configurable
from hanlp_common.reflection import classpath_of
from hanlp_trie.trie import Trie
clas... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_trie/hanlp_trie/__init__.py | plugins/hanlp_trie/hanlp_trie/__init__.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-11-29 17:48
from .trie import Trie
from .dictionary import DictInterface, TrieDict
| python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_trie/hanlp_trie/trie.py | plugins/hanlp_trie/hanlp_trie/trie.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-01-04 23:46
from typing import Dict, Any, List, Tuple, Sequence, Union, Iterable, Optional
class Node(object):
def __init__(self, value=None) -> None:
"""A node in a trie tree.
Args:
value: The value associated with this node.
... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_common/setup.py | plugins/hanlp_common/setup.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-28 19:26
from os.path import abspath, join, dirname
from setuptools import find_packages, setup
this_dir = abspath(dirname(__file__))
with open(join(this_dir, 'README.md'), encoding='utf-8') as file:
long_description = file.read()
setup(
name='hanlp_comm... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_common/__init__.py | plugins/hanlp_common/__init__.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-12-16 22:20
| python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_common/hanlp_common/amr.py | plugins/hanlp_common/hanlp_common/amr.py | # MIT License
#
# Copyright (c) 2019 Sheng Zhang
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, ... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | true |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_common/hanlp_common/reflection.py | plugins/hanlp_common/hanlp_common/reflection.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-28 16:41
import importlib
import inspect
def classpath_of(obj) -> str:
"""get the full class path of object
Args:
obj: return:
Returns:
"""
if inspect.isfunction(obj):
return module_path_of(obj)
return "{0}.{1}".format(ob... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_common/hanlp_common/conll.py | plugins/hanlp_common/hanlp_common/conll.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-12-19 20:50
from typing import Union, List
from hanlp_common.structure import SerializableDict
from hanlp_common.visualization import pretty_tree_horizontal, make_table, markdown_table
class CoNLLWord(SerializableDict):
def __init__(self, id, form, lemma=None,... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_common/hanlp_common/util.py | plugins/hanlp_common/hanlp_common/util.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-10-27 19:09
import math
from typing import Union, Any, List, Optional, Tuple, Iterable, Dict
import inspect
from itertools import chain, combinations
def powerset(iterable, descending=False):
"""
powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_common/hanlp_common/structure.py | plugins/hanlp_common/hanlp_common/structure.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-12-19 20:56
import json
from collections import OrderedDict
from hanlp_common.io import filename_is_json, save_pickle, load_pickle, save_json, load_json
class Serializable(object):
"""A super class for save/load operations."""
def save(self, path, fmt=Non... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_common/hanlp_common/document.py | plugins/hanlp_common/hanlp_common/document.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-31 04:16
import json
import re
import warnings
from typing import List, Union
from phrasetree.tree import Tree
from hanlp_common.conll import CoNLLUWord, CoNLLSentence, CoNLLSentenceList
from hanlp_common.constant import PRED, IPYTHON
from hanlp_common.util impo... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_common/hanlp_common/__init__.py | plugins/hanlp_common/hanlp_common/__init__.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-12-16 22:21
| python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_common/hanlp_common/configurable.py | plugins/hanlp_common/hanlp_common/configurable.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-12-16 22:24
from hanlp_common.reflection import str_to_type, classpath_of
class Configurable(object):
@staticmethod
def from_config(config: dict, **kwargs):
"""Build an object from config.
Args:
config: A ``dict`` holding paramete... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_common/hanlp_common/constant.py | plugins/hanlp_common/hanlp_common/constant.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-06-13 22:41
import os
PAD = '<pad>'
'''Padding token.'''
UNK = '<unk>'
'''Unknown token.'''
CLS = '[CLS]'
BOS = '<bos>'
EOS = '<eos>'
ROOT = BOS
IDX = '_idx_'
'''Key for index.'''
HANLP_URL = os.getenv('HANLP_URL', 'https://file.hankcs.com/hanlp/')
'''Resource URL.'... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_common/hanlp_common/io.py | plugins/hanlp_common/hanlp_common/io.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-12-16 22:38
import json
import os
import pickle
import sys
from typing import Union
def save_pickle(item, path):
with open(path, 'wb') as f:
pickle.dump(item, f)
def load_pickle(path):
with open(path, 'rb') as f:
return pickle.load(f)
de... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_common/hanlp_common/visualization.py | plugins/hanlp_common/hanlp_common/visualization.py | # -*- coding:utf-8 -*-
# Modified from https://github.com/tylerneylon/explacy
import io
from collections import defaultdict
from pprint import pprint
from phrasetree.tree import Tree
def make_table(rows, insert_header=False):
col_widths = [max(len(s) for s in col) for col in zip(*rows[1:])]
rows[0] = [x[:l] ... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/setup.py | plugins/hanlp_demo/setup.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-28 19:26
from os.path import abspath, join, dirname
from setuptools import find_packages, setup
this_dir = abspath(dirname(__file__))
with open(join(this_dir, 'README.md'), encoding='utf-8') as file:
long_description = file.read()
setup(
name='hanlp_demo... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/sent_split.py | plugins/hanlp_demo/hanlp_demo/sent_split.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-12-31 14:23
import hanlp
split_sent = hanlp.load(hanlp.pretrained.eos.UD_CTB_EOS_MUL)
output = split_sent('3.14 is pi. “你好!!!”——他说。劇場版「Fate/stay night [HF]」最終章公開カウントダウン!')
print('\n'.join(output))
# See also https://hanlp.hankcs.com/docs/api/hanlp/components/eos.htm... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/block_windows.py | plugins/hanlp_demo/hanlp_demo/block_windows.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2021-07-28 21:38
from hanlp.utils.io_util import windows
assert not windows(), 'Windows is not supported for this script. Please run it on Linux systems.'
| python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/__init__.py | plugins/hanlp_demo/hanlp_demo/__init__.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-11-29 17:48
| python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/demo_del_tasks.py | plugins/hanlp_demo/hanlp_demo/zh/demo_del_tasks.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2021-02-03 13:28
import hanlp
from hanlp.components.mtl.multi_task_learning import MultiTaskLearning
from hanlp_common.document import Document
HanLP: MultiTaskLearning = hanlp.load(hanlp.pretrained.mtl.OPEN_TOK_POS_NER_SRL_DEP_SDP_CON_ELECTRA_SMALL_ZH)
tasks = list(HanL... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/demo_document.py | plugins/hanlp_demo/hanlp_demo/zh/demo_document.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2022-10-26 23:40
from hanlp_common.document import Document
# Create a document or get a document from HanLP.parse
doc = Document(
tok=[["晓美焰", "来到", "北京", "立方庭", "参观", "自然", "语义", "科技", "公司"]],
pos=[["NR", "VV", "NR", "NR", "VV", "NN", "NN", "NN", "NN"]],
ne... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/demo_mlm.py | plugins/hanlp_demo/hanlp_demo/zh/demo_mlm.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2022-01-29 21:11
from hanlp.components.lm.mlm import MaskedLanguageModel
mlm = MaskedLanguageModel()
mlm.load('bert-base-chinese')
print(mlm('生活的真谛是[MASK]。'))
# Batching is always faster
print(mlm(['生活的真谛是[MASK]。', '巴黎是[MASK][MASK]的首都。']))
| python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/demo_word2vec.py | plugins/hanlp_demo/hanlp_demo/zh/demo_word2vec.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2021-12-12 18:33
import hanlp
import torch
word2vec = hanlp.load(hanlp.pretrained.word2vec.CONVSEG_W2V_NEWS_TENSITE_WORD_PKU)
vec = word2vec('先进')
print(vec)
print(torch.nn.functional.cosine_similarity(word2vec('先进'), word2vec('优秀'), dim=0))
print(torch.nn.functional.co... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/train_sota_bert_pku.py | plugins/hanlp_demo/hanlp_demo/zh/train_sota_bert_pku.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-08-11 02:47
from hanlp.common.dataset import SortingSamplerBuilder
from hanlp.components.tokenizers.transformer import TransformerTaggingTokenizer
from hanlp.datasets.tokenization.sighan2005.pku import SIGHAN2005_PKU_TRAIN_ALL, SIGHAN2005_PKU_TEST
from tests import c... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/demo_sts.py | plugins/hanlp_demo/hanlp_demo/zh/demo_sts.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2021-05-24 13:15
import hanlp
sim = hanlp.load(hanlp.pretrained.sts.STS_ELECTRA_BASE_ZH)
print(sim([
['看图猜一电影名', '看图猜电影'],
['无线路由器怎么无线上网', '无线上网卡和无线路由器怎么用'],
['北京到上海的动车票', '上海到北京的动车票'],
]))
| python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/demo_mtl.py | plugins/hanlp_demo/hanlp_demo/zh/demo_mtl.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-12-31 13:51
import hanlp
from hanlp_common.document import Document
# CLOSE是自然语义标注的闭源语料库,BASE是中号模型,ZH中文
HanLP = hanlp.load(hanlp.pretrained.mtl.CLOSE_TOK_POS_NER_SRL_DEP_SDP_CON_ELECTRA_BASE_ZH)
# 默认执行全部任务
doc: Document = HanLP(['2021年HanLPv2.1为生产环境带来次世代最先进的多语种NLP技术... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/demo_parse_constituency.py | plugins/hanlp_demo/hanlp_demo/zh/demo_parse_constituency.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2022-01-18 11:09
from hanlp_common.document import Document
import hanlp
con = hanlp.load(hanlp.pretrained.constituency.CTB9_CON_FULL_TAG_ELECTRA_SMALL)
# To speed up, parse multiple sentences at once, and use a GPU.
print(con(["2021年", "HanLPv2.1", "带来", "最", "先进", "的",... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/demo_amr.py | plugins/hanlp_demo/hanlp_demo/zh/demo_amr.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2022-04-12 22:19
import hanlp
parser = hanlp.load(hanlp.pretrained.amr.MRP2020_AMR_ENG_ZHO_XLM_BASE)
# For Chinese:
print(parser(["男孩", "希望", "女孩", "相信", "他", "。"]))
print(parser(["男孩", "希望", "女孩", "相信", "他", "。"], output_amr=False))
# For English:
print(parser(['The',... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/__init__.py | plugins/hanlp_demo/hanlp_demo/zh/__init__.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-12-31 13:51
| python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/demo_custom_dict.py | plugins/hanlp_demo/hanlp_demo/zh/demo_custom_dict.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-12-15 22:26
import hanlp
from hanlp.components.mtl.multi_task_learning import MultiTaskLearning
from hanlp.components.mtl.tasks.tok.tag_tok import TaggingTokenization
# 加载多任务模型
HanLP: MultiTaskLearning = hanlp.load(hanlp.pretrained.mtl.CLOSE_TOK_POS_NER_SRL_DEP_SDP_... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/demo_custom_dict_stl.py | plugins/hanlp_demo/hanlp_demo/zh/demo_custom_dict_stl.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-12-15 22:26
import hanlp
from hanlp.components.tokenizers.transformer import TransformerTaggingTokenizer
# 加载一个旧版本单任务模型演示分词错误(最新版已经修复):
tok: TransformerTaggingTokenizer = hanlp.load('https://file.hankcs.com/hanlp/tok/coarse_electra_small_20220220_013548.zip')
tok.d... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/demo_pos_dict.py | plugins/hanlp_demo/hanlp_demo/zh/demo_pos_dict.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-12-15 22:26
import hanlp
from hanlp.components.mtl.multi_task_learning import MultiTaskLearning
from hanlp.components.mtl.tasks.pos import TransformerTagging
from hanlp.components.mtl.tasks.tok.tag_tok import TaggingTokenization
from tests import cdroot
cdroot()
Han... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/demo_pipeline.py | plugins/hanlp_demo/hanlp_demo/zh/demo_pipeline.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2021-12-28 20:47
import hanlp
# Pipeline allows blending multiple callable functions no matter they are a rule, a TensorFlow component or a PyTorch
# one. However, it's slower than the MTL framework.
# pos = hanlp.load(hanlp.pretrained.pos.CTB9_POS_ALBERT_BASE) # In cas... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/demo_ner_dict.py | plugins/hanlp_demo/hanlp_demo/zh/demo_ner_dict.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2021-04-29 11:06
import hanlp
from hanlp.components.mtl.tasks.ner.tag_ner import TaggingNamedEntityRecognition
from hanlp.utils.io_util import get_resource
HanLP = hanlp.load(hanlp.pretrained.mtl.CLOSE_TOK_POS_NER_SRL_DEP_SDP_CON_ERNIE_GRAM_ZH)
ner: TaggingNamedEntityRec... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/train/finetune_ner.py | plugins/hanlp_demo/hanlp_demo/zh/train/finetune_ner.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2023-10-18 18:49
import os
import hanlp
from hanlp.components.ner.transformer_ner import TransformerNamedEntityRecognizer
from tests import cdroot
cdroot()
your_training_corpus = 'data/ner/finetune/word_to_iobes.tsv'
your_development_corpus = your_training_corpus # Us... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/train/open_small.py | plugins/hanlp_demo/hanlp_demo/zh/train/open_small.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-12-03 14:24
from hanlp_demo import block_windows
from hanlp.common.dataset import SortingSamplerBuilder
from hanlp.common.transform import NormalizeCharacter
from hanlp.components.mtl.multi_task_learning import MultiTaskLearning
from hanlp.components.mtl.tasks.consti... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/train/__init__.py | plugins/hanlp_demo/hanlp_demo/zh/train/__init__.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-12-31 20:12
| python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/train/open_base.py | plugins/hanlp_demo/hanlp_demo/zh/train/open_base.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-12-03 14:24
from hanlp_demo import block_windows
from hanlp.common.dataset import SortingSamplerBuilder
from hanlp.common.transform import NormalizeCharacter
from hanlp.components.mtl.multi_task_learning import MultiTaskLearning
from hanlp.components.mtl.tasks.consti... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/tf/demo_fasttext.py | plugins/hanlp_demo/hanlp_demo/zh/tf/demo_fasttext.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2021-12-12 18:33
import hanlp
import torch
# fasttext is a `torch.nn.Module`. Unless you know how to code in
# PyTorch, otherwise don't bother to use this.
fasttext = hanlp.load(hanlp.pretrained.fasttext.FASTTEXT_WIKI_300_ZH)
vec = fasttext('单词')
print(vec)
print(torch... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/tf/demo_dep.py | plugins/hanlp_demo/hanlp_demo/zh/tf/demo_dep.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-28 21:25
import hanlp
syntactic_parser = hanlp.load(hanlp.pretrained.dep.CTB7_BIAFFINE_DEP_ZH)
sent = [('蜡烛', 'NN'), ('两', 'CD'), ('头', 'NN'), ('烧', 'VV')]
tree = syntactic_parser(sent)
print(tree)
| python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/tf/demo_classifier.py | plugins/hanlp_demo/hanlp_demo/zh/tf/demo_classifier.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-01-01 03:52
from hanlp.datasets.classification.sentiment import CHNSENTICORP_ERNIE_TEST
import hanlp
classifier = hanlp.load('CHNSENTICORP_BERT_BASE_ZH')
print(classifier.predict('前台客房服务态度非常好!早餐很丰富,房价很干净。再接再厉!'))
# predict a whole file in batch mode
outputs = clas... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/tf/demo_cws.py | plugins/hanlp_demo/hanlp_demo/zh/tf/demo_cws.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-28 21:25
import hanlp
tokenizer = hanlp.load(hanlp.pretrained.tok.LARGE_ALBERT_BASE)
print(tokenizer('商品和服务'))
print(tokenizer(['萨哈夫说,伊拉克将同联合国销毁伊拉克大规模杀伤性武器特别委员会继续保持合作。',
'上海华安工业(集团)公司董事长谭旭光和秘书张晚霞来到美国纽约现代艺术博物馆参观。',
'HanLP支援臺灣正體、香港... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/tf/demo_pos.py | plugins/hanlp_demo/hanlp_demo/zh/tf/demo_pos.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-28 21:25
import hanlp
from hanlp.pretrained.pos import CTB9_POS_ALBERT_BASE
tagger = hanlp.load(CTB9_POS_ALBERT_BASE)
print(tagger.predict(['我', '的', '希望', '是', '希望', '世界', '和平']))
print(tagger.predict([['支持', '批处理', '地', '预测'], ['速度', '更', '快']]))
| python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/tf/demo_ner.py | plugins/hanlp_demo/hanlp_demo/zh/tf/demo_ner.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-30 19:52
import hanlp
recognizer = hanlp.load(hanlp.pretrained.ner.MSRA_NER_BERT_BASE_ZH)
print(recognizer.predict([list('上海华安工业(集团)公司董事长谭旭光和秘书张晚霞来到美国纽约现代艺术博物馆参观。'),
list('萨哈夫说,伊拉克将同联合国销毁伊拉克大规模杀伤性武器特别委员会继续保持合作。')]))
| python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/tf/demo_client.py | plugins/hanlp_demo/hanlp_demo/zh/tf/demo_client.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-01-08 04:43
# pip3 install tensorflow-serving-api-gpu
import grpc
import tensorflow as tf
from tensorflow_core.python.framework import tensor_util
from tensorflow_serving.apis import predict_pb2, prediction_service_pb2_grpc
import hanlp
from hanlp.common.keras_compon... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/tf/demo_cws_trie.py | plugins/hanlp_demo/hanlp_demo/zh/tf/demo_cws_trie.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-28 21:25
from hanlp_trie.trie import Trie
import hanlp
tokenizer = hanlp.load('LARGE_ALBERT_BASE')
text = 'NLP统计模型没有加规则,聪明人知道自己加。英文、数字、自定义词典统统都是规则。'
print(tokenizer(text))
trie = Trie()
trie.update({'自定义词典': 'custom_dict', '聪明人': 'smart'})
def split_sents(tex... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/tf/__init__.py | plugins/hanlp_demo/hanlp_demo/zh/tf/__init__.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-12-31 20:36
| python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/tf/demo_sdp.py | plugins/hanlp_demo/hanlp_demo/zh/tf/demo_sdp.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-31 23:55
import hanlp
semantic_parser = hanlp.load('SEMEVAL16_NEWS_BIAFFINE_ZH')
sent = [('蜡烛', 'NN'), ('两', 'CD'), ('头', 'NN'), ('烧', 'VV')]
print(semantic_parser(sent))
| python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/tf/demo_multiprocess.py | plugins/hanlp_demo/hanlp_demo/zh/tf/demo_multiprocess.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-02-15 11:30
import multiprocessing
import hanlp
tokenizer = hanlp.load(hanlp.pretrained.tok.LARGE_ALBERT_BASE)
def worker(job):
print(job)
print(tokenizer(job))
if __name__ == '__main__':
num_proc = 2
# Important! The python multiprocessing packa... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/tf/demo_pipeline.py | plugins/hanlp_demo/hanlp_demo/zh/tf/demo_pipeline.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-31 03:24
import hanlp
tokenizer = hanlp.load('LARGE_ALBERT_BASE')
tagger = hanlp.load('CTB9_POS_ALBERT_BASE')
syntactic_parser = hanlp.load('CTB7_BIAFFINE_DEP_ZH')
semantic_parser = hanlp.load('SEMEVAL16_TEXT_BIAFFINE_ZH')
pipeline = hanlp.pipeline() \
.app... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/tf/demo_serving.py | plugins/hanlp_demo/hanlp_demo/zh/tf/demo_serving.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-01-06 20:23
import hanlp
from hanlp.common.keras_component import KerasComponent
tagger: KerasComponent = hanlp.load(hanlp.pretrained.pos.CTB5_POS_RNN)
print(tagger('商品 和 服务'.split()))
tagger.serve()
| python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_ptb_dep_sa_pos_bert.py | plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_ptb_dep_sa_pos_bert.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-03-07 23:48
from hanlp.metrics.parsing import conllx_eval
from hanlp.datasets.parsing.ptb import PTB_SD330_DEV, PTB_SD330_TRAIN, PTB_SD330_TEST, PTB_TOKEN_MAPPING
from hanlp.components.parsers.biaffine_parser_tf import BiaffineTransformerDependencyParserTF, \
St... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_ctb7_dep.py | plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_ctb7_dep.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-28 18:33
from hanlp.components.parsers.biaffine_parser_tf import BiaffineDependencyParserTF
from hanlp.datasets.parsing.ctb5 import CIP_W2V_100_CN
from hanlp.datasets.parsing.ctb7 import CTB7_DEP_TRAIN, CTB7_DEP_DEV, CTB7_DEP_TEST
from tests import cdroot
cdroot(... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_ptb_dep_sa_albert_topk.py | plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_ptb_dep_sa_albert_topk.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-03-07 23:48
from hanlp.metrics.parsing import conllx_eval
from hanlp.datasets.parsing.ptb import PTB_SD330_DEV, PTB_SD330_TRAIN, PTB_SD330_TEST, PTB_TOKEN_MAPPING
from hanlp.components.parsers.biaffine_parser_tf import BiaffineTransformerDependencyParserTF, \
St... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_msra_ner_bert.py | plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_msra_ner_bert.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-28 23:15
from hanlp.components.ner.ner_tf import TransformerNamedEntityRecognizerTF
from hanlp.datasets.ner.msra import MSRA_NER_CHAR_LEVEL_TRAIN, MSRA_NER_CHAR_LEVEL_DEV, MSRA_NER_CHAR_LEVEL_TEST
from tests import cdroot
cdroot()
recognizer = TransformerNamedEnt... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_ctb9_pos_electra.py | plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_ctb9_pos_electra.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-28 23:15
from hanlp.components.taggers.transformers.transformer_tagger_tf import TransformerTaggerTF
from tests import cdroot
cdroot()
tagger = TransformerTaggerTF()
save_dir = 'data/model/pos/ctb9_electra_small_zh_epoch_20'
tagger.fit('data/pos/ctb9/train.tsv',
... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_ptb_dep_biaffine_bert.py | plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_ptb_dep_biaffine_bert.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-03-07 23:48
from hanlp.metrics.parsing import conllx_eval
from hanlp.datasets.parsing.ptb import PTB_SD330_DEV, PTB_SD330_TRAIN, PTB_SD330_TEST, PTB_TOKEN_MAPPING
from hanlp.components.parsers.biaffine_parser_tf import BiaffineTransformerDependencyParserTF
from test... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_ctb5_dep.py | plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_ctb5_dep.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-28 18:33
from hanlp.components.parsers.biaffine_parser_tf import BiaffineDependencyParserTF
from hanlp.datasets.parsing.ctb5 import CTB5_DEP_TRAIN, CTB5_DEP_DEV, CTB5_DEP_TEST
from hanlp.pretrained.word2vec import CTB5_FASTTEXT_300_CN
from tests import cdroot
cdr... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_semeval15_dm.py | plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_semeval15_dm.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-01-01 18:26
from hanlp.components.parsers.biaffine_parser_tf import BiaffineSemanticDependencyParserTF
from hanlp.pretrained.glove import GLOVE_6B_100D
from tests import cdroot
cdroot()
save_dir = 'data/model/sdp/semeval15_biaffine_dm'
parser = BiaffineSemanticDepen... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_ptb_dep_biaffine_bert_positional.py | plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_ptb_dep_biaffine_bert_positional.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-03-07 23:48
from hanlp.metrics.parsing import conllx_eval
from hanlp.datasets.parsing.ptb import PTB_SD330_DEV, PTB_SD330_TRAIN, PTB_SD330_TEST, PTB_TOKEN_MAPPING
from hanlp.components.parsers.biaffine_parser_tf import BiaffineTransformerDependencyParserTF
from test... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_msra_ner_albert.py | plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_msra_ner_albert.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-28 23:15
from hanlp.components.ner.ner_tf import TransformerNamedEntityRecognizerTF
from hanlp.datasets.ner.msra import MSRA_NER_CHAR_LEVEL_TRAIN, MSRA_NER_CHAR_LEVEL_DEV, MSRA_NER_CHAR_LEVEL_TEST
from tests import cdroot
cdroot()
recognizer = TransformerNamedEnt... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_ptb_dep_sa_albert.py | plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_ptb_dep_sa_albert.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-03-07 23:48
from hanlp.metrics.parsing import conllx_eval
from hanlp.datasets.parsing.ptb import PTB_SD330_DEV, PTB_SD330_TRAIN, PTB_SD330_TEST, PTB_TOKEN_MAPPING
from hanlp.components.parsers.biaffine_parser_tf import BiaffineTransformerDependencyParserTF, \
St... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_chnsenticorp_bert.py | plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_chnsenticorp_bert.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-30 21:01
from hanlp.components.classifiers.transformer_classifier_tf import TransformerClassifierTF, TransformerTextTransform
from hanlp.datasets.classification.sentiment import CHNSENTICORP_ERNIE_TRAIN, CHNSENTICORP_ERNIE_TEST, \
CHNSENTICORP_ERNIE_DEV
from t... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_ptb_dep_biaffine_bert_96.6.py | plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_ptb_dep_biaffine_bert_96.6.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2020-03-07 23:48
from hanlp.datasets.parsing.ptb import PTB_SD330_DEV, PTB_SD330_TRAIN, PTB_SD330_TEST, PTB_TOKEN_MAPPING
from hanlp.components.parsers.biaffine_parser_tf import BiaffineTransformerDependencyParserTF
from tests import cdroot
from hanlp.metrics.parsing imp... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_semeval16_text.py | plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_semeval16_text.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-26 23:20
from hanlp.datasets.parsing.semeval16 import SEMEVAL2016_TEXT_TRAIN, SEMEVAL2016_TEXT_DEV, SEMEVAL2016_TEXT_TEST
from hanlp.pretrained.word2vec import SEMEVAL16_EMBEDDINGS_300_TEXT_CN
from hanlp.utils.tf_util import nice
nice()
from hanlp.components.pars... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_semeval16_news.py | plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_semeval16_news.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-26 23:20
from hanlp.datasets.parsing.semeval16 import SEMEVAL2016_NEWS_TRAIN, SEMEVAL2016_NEWS_DEV, SEMEVAL2016_NEWS_TEST
from hanlp.pretrained.word2vec import SEMEVAL16_EMBEDDINGS_300_NEWS_CN
from hanlp.utils.tf_util import nice
nice()
from hanlp.components.pars... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_msra_ner_ngram_conv.py | plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_msra_ner_ngram_conv.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-28 23:15
from hanlp.components.ner.ner_tf import NgramConvNamedEntityRecognizerTF
from hanlp.datasets.ner.msra import MSRA_NER_CHAR_LEVEL_TRAIN, MSRA_NER_CHAR_LEVEL_DEV, MSRA_NER_CHAR_LEVEL_TEST
from hanlp.pretrained.word2vec import CONVSEG_W2V_NEWS_TENSITE_CHAR, ... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_conll03_ner_bert.py | plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_conll03_ner_bert.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-10-25 21:34
from hanlp.components.ner.ner_tf import TransformerNamedEntityRecognizerTF
from hanlp.datasets.ner.conll03 import CONLL03_EN_TRAIN, CONLL03_EN_DEV, CONLL03_EN_TEST
from tests import cdroot
cdroot()
tagger = TransformerNamedEntityRecognizerTF()
save_dir =... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_ctb5_pos_rnn.py | plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_ctb5_pos_rnn.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-28 22:46
from hanlp.components.taggers.pos_tf import RNNPartOfSpeechTaggerTF
from hanlp.datasets.pos.ctb5 import CTB5_POS_TRAIN, CTB5_POS_DEV, CTB5_POS_TEST
from hanlp.pretrained.fasttext import FASTTEXT_WIKI_300_ZH
from tests import cdroot
cdroot()
tagger = RNNP... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/tf/train/finetune_msra_ner_albert.py | plugins/hanlp_demo/hanlp_demo/zh/tf/train/finetune_msra_ner_albert.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-28 23:15
import hanlp
from hanlp.components.ner.ner_tf import TransformerNamedEntityRecognizerTF
from hanlp.datasets.ner.msra import MSRA_NER_CHAR_LEVEL_TRAIN, MSRA_NER_CHAR_LEVEL_DEV, MSRA_NER_CHAR_LEVEL_TEST
from tests import cdroot
cdroot()
recognizer = Transf... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_msra_ner_rnn.py | plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_msra_ner_rnn.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-28 23:15
from hanlp.components.ner.ner_tf import RNNNamedEntityRecognizerTF
from hanlp.datasets.ner.msra import MSRA_NER_CHAR_LEVEL_TRAIN, MSRA_NER_CHAR_LEVEL_DEV, MSRA_NER_CHAR_LEVEL_TEST
from hanlp.pretrained.word2vec import RADICAL_CHAR_EMBEDDING_100
from tests... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
hankcs/HanLP | https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_msra_ner_electra.py | plugins/hanlp_demo/hanlp_demo/zh/tf/train/train_msra_ner_electra.py | # -*- coding:utf-8 -*-
# Author: hankcs
# Date: 2019-12-28 23:15
from hanlp.components.ner.ner_tf import TransformerNamedEntityRecognizerTF
from hanlp.datasets.ner.msra import MSRA_NER_CHAR_LEVEL_TRAIN, MSRA_NER_CHAR_LEVEL_DEV, MSRA_NER_CHAR_LEVEL_TEST
from tests import cdroot
cdroot()
recognizer = TransformerNamedEnt... | python | Apache-2.0 | ddb1299bddff079e447af52ec12549c50636bfa8 | 2026-01-04T14:42:01.948856Z | false |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.