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/components/parsers/biaffine/structual_attention.py
hanlp/components/parsers/biaffine/structual_attention.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-06-26 10:40 from typing import Union, List import torch import torch.nn.functional as F from hanlp.utils.torch_util import lengths_to_mask from torch import nn from hanlp.common.torch_component import TorchComponent from hanlp.components.parsers.biaffine.biaffine_d...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/parsers/biaffine/mlp.py
hanlp/components/parsers/biaffine/mlp.py
# MIT License # # Copyright (c) 2020 Yu 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, pub...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/parsers/biaffine/biaffine_2nd_dep.py
hanlp/components/parsers/biaffine/biaffine_2nd_dep.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-08-06 13:57 import functools from typing import Union, List, Any import torch from hanlp_common.constant import UNK from hanlp.common.transform import TransformList from hanlp.common.vocab import Vocab from hanlp.components.parsers.biaffine.biaffine import Biaffine ...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/parsers/biaffine/biaffine_sdp.py
hanlp/components/parsers/biaffine/biaffine_sdp.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-07-28 15:12 import functools from collections import Counter from typing import Union, List import torch from torch import nn from hanlp_common.constant import UNK from hanlp.common.transform import TransformList from hanlp.components.parsers.biaffine.biaffine_dep ...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/parsers/biaffine/__init__.py
hanlp/components/parsers/biaffine/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-05-08 20:43
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/parsers/biaffine/biaffine_dep.py
hanlp/components/parsers/biaffine/biaffine_dep.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-05-08 20:51 import os from collections import Counter from typing import Union, Any, List from hanlp.layers.transformers.pt_imports import PreTrainedTokenizer, AutoModel_, AutoTokenizer_ import torch from hanlp.utils.torch_util import lengths_to_mask from torch impo...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/parsers/biaffine/biaffine.py
hanlp/components/parsers/biaffine/biaffine.py
# MIT License # # Copyright (c) 2020 Yu 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, pub...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/parsers/biaffine/variationalbilstm.py
hanlp/components/parsers/biaffine/variationalbilstm.py
# MIT License # # Copyright (c) 2020 Yu 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, pub...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/parsers/ud/tag_decoder.py
hanlp/components/parsers/ud/tag_decoder.py
# This file is modified from udify, which is licensed under the MIT license: # MIT License # # Copyright (c) 2019 Dan Kondratyuk # # 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 rest...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/parsers/ud/util.py
hanlp/components/parsers/ud/util.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-12-14 20:44 from hanlp_common.constant import ROOT from hanlp.components.parsers.ud.lemma_edit import gen_lemma_rule def generate_lemma_rule(sample: dict): if 'LEMMA' in sample: sample['lemma'] = [gen_lemma_rule(word, lemma) if lemma != "_" else "_" for...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/parsers/ud/ud_parser.py
hanlp/components/parsers/ud/ud_parser.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-12-14 20:34 import logging from copy import deepcopy from typing import Union, List, Callable import torch from torch.utils.data import DataLoader from hanlp_common.constant import IDX from hanlp.common.dataset import PadSequenceDataLoader, SortingSamplerBuilder fr...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/parsers/ud/ud_model.py
hanlp/components/parsers/ud/ud_model.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-12-15 14:21 from typing import Dict, Any import torch from hanlp.components.parsers.biaffine.biaffine_dep import BiaffineDependencyParser from hanlp.components.parsers.biaffine.biaffine_model import BiaffineDecoder from hanlp.components.parsers.ud.tag_decoder impo...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/parsers/ud/udify_util.py
hanlp/components/parsers/ud/udify_util.py
# This file is modified from udify and allennlp, which are licensed under the MIT license: # MIT License # # Copyright (c) 2019 Dan Kondratyuk and allennlp # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # i...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/parsers/ud/__init__.py
hanlp/components/parsers/ud/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-12-14 20:34
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/parsers/ud/lemma_edit.py
hanlp/components/parsers/ud/lemma_edit.py
""" Utilities for processing lemmas Adopted from UDPipe Future https://github.com/CoNLL-UD-2018/UDPipe-Future """ def min_edit_script(source, target, allow_copy=False): """Finds the minimum edit script to transform the source to the target Args: source: target: allow_copy: (Default valu...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/utils/span_util.py
hanlp/utils/span_util.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-06-12 20:34 import warnings from typing import Dict, List, Tuple, Callable, Set, Optional def generate_words_per_line(file_path): with open(file_path, encoding='utf-8') as src: for line in src: cells = line.strip().split() if not...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/utils/rules.py
hanlp/utils/rules.py
import re _SEPARATOR = r'@' _RE_SENTENCE = re.compile(r'(\S.+?[.!?])(?=\s+|$)|(\S.+?)(?=[\n]|$)', re.UNICODE) _AB_SENIOR = re.compile(r'([A-Z][a-z]{1,2}\.)\s(\w)', re.UNICODE) _AB_ACRONYM = re.compile(r'(\.[a-zA-Z]\.)\s(\w)', re.UNICODE) _UNDO_AB_SENIOR = re.compile(r'([A-Z][a-z]{1,2}\.)' + _SEPARATOR + r'(\w)', re.UN...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/utils/torch_util.py
hanlp/utils/torch_util.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-05-09 15:52 import os import random import time from typing import List, Union, Dict, Tuple import numpy as np import torch from pynvml import nvmlDeviceGetHandleByIndex, nvmlDeviceGetMemoryInfo, nvmlInit, nvmlShutdown, nvmlDeviceGetCount from torch import nn from t...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/utils/log_util.py
hanlp/utils/log_util.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-08-24 22:12 import datetime import io import logging import os import sys from logging import LogRecord import termcolor from hanlp_common.constant import IPYTHON class ColoredFormatter(logging.Formatter): def __init__(self, fmt=None, datefmt=None, style='%',...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/utils/string_util.py
hanlp/utils/string_util.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-08-25 00:19 import unicodedata from typing import List, Dict, Tuple def format_scores(results: Dict[str, float]) -> str: return ' - '.join(f'{k}: {v:.4f}' for (k, v) in results.items()) def ispunct(token): return all(unicodedata.category(char).startswith(...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/utils/time_util.py
hanlp/utils/time_util.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-08-27 00:01 import datetime import logging import sys import time from typing import Union from hanlp.utils.log_util import ErasablePrinter, color_format, color_format_len def human_time_delta(days, hours, minutes, seconds, delimiter=' ') -> str: units = local...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/utils/io_util.py
hanlp/utils/io_util.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-08-26 15:02 import contextlib import glob import gzip import json import logging import os import platform import random import shlex import shutil import sys import tarfile import tempfile import urllib import zipfile from contextlib import contextmanager from pathl...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/utils/__init__.py
hanlp/utils/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-08-24 22:12 from . import rules def ls_resource_in_module(root) -> dict: res = dict() for k, v in root.__dict__.items(): if k.startswith('_') or v == root: continue if isinstance(v, str): if v.startswith('http') and n...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/utils/tf_util.py
hanlp/utils/tf_util.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-08-27 01:27 import json import logging import os import random from typing import List import numpy as np from hanlp_common.constant import PAD def set_gpu(idx=0): """Restrict TensorFlow to only use the GPU of idx Args: idx: (Default value = 0) ...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/utils/component_util.py
hanlp/utils/component_util.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-12-31 19:24 import os from hanlp_common.constant import HANLP_VERBOSE from hanlp_common.io import load_json, eprint, save_json from hanlp_common.reflection import object_from_classpath, str_to_type from hanlp import pretrained from hanlp import version from hanlp.com...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/utils/init_util.py
hanlp/utils/init_util.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-05-27 13:25 import math import torch from torch import nn import functools def embedding_uniform(tensor:torch.Tensor, seed=233): gen = torch.Generator().manual_seed(seed) with torch.no_grad(): fan_out = tensor.size(-1) bound = math.sqrt(3.0...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/utils/lang/__init__.py
hanlp/utils/lang/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-01-09 18:46 __doc__ = ''' This package holds misc utils for specific languages. '''
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/utils/lang/zh/localization.py
hanlp/utils/lang/zh/localization.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-12-05 02:09 task = { 'dep': '依存句法树', 'token': '单词', 'pos': '词性', 'ner': '命名实体', 'srl': '语义角色' } pos = { 'VA': '表语形容词', 'VC': '系动词', 'VE': '动词有无', 'VV': '其他动词', 'NR': '专有名词', 'NT': '时间名词', 'NN': '其他名词', 'LC': '方位词', 'PN': '代词', 'DT': '限定词...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/utils/lang/zh/char_table.py
hanlp/utils/lang/zh/char_table.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-01-09 19:07 from typing import List from hanlp.utils.io_util import get_resource from hanlp_common.io import load_json HANLP_CHAR_TABLE_TXT = 'https://file.hankcs.com/corpus/char_table.zip#CharTable.txt' HANLP_CHAR_TABLE_JSON = 'https://file.hankcs.com/corpus/char_...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/utils/lang/zh/__init__.py
hanlp/utils/lang/zh/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-01-09 18:47
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/utils/lang/en/__init__.py
hanlp/utils/lang/en/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2021-12-28 19:28
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/utils/lang/en/english_tokenizer.py
hanlp/utils/lang/en/english_tokenizer.py
#!/usr/bin/env python """ Regex-based word tokenizers. Note that small/full/half-width character variants are *not* covered. If a text were to contains such characters, normalize it first. A modified version of https://github.com/fnl/segtok - dropped dependency on regex - dropped web_tokenize - supported concat word ...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/utils/lang/ja/bert_tok.py
hanlp/utils/lang/ja/bert_tok.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2021-05-13 13:24 from typing import Union, Optional from transformers import BertTokenizerFast, TensorType, BatchEncoding, BertJapaneseTokenizer as _BertJapaneseTokenizer from transformers.file_utils import PaddingStrategy from transformers.tokenization_utils_base import...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/utils/lang/ja/__init__.py
hanlp/utils/lang/ja/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2021-05-13 13:24
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/utils/file_read_backwards/buffer_work_space.py
hanlp/utils/file_read_backwards/buffer_work_space.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """BufferWorkSpace module.""" import os new_lines = ["\r\n", "\n", "\r"] new_lines_bytes = [n.encode("ascii") for n in new_lines] # we only support encodings that's backward compat with ascii class BufferWorkSpace: """It is a helper module for FileReadBackwards."...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/utils/file_read_backwards/file_read_backwards.py
hanlp/utils/file_read_backwards/file_read_backwards.py
#!/usr/bin/env python # -*- coding: utf-8 -*- """FileReadBackwards module.""" import io import os from .buffer_work_space import BufferWorkSpace supported_encodings = ["utf-8", "ascii", "latin-1"] # any encodings that are backward compatible with ascii should work class FileReadBackwards: """Class definitio...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/utils/file_read_backwards/__init__.py
hanlp/utils/file_read_backwards/__init__.py
# -*- coding: utf-8 -*- from .file_read_backwards import FileReadBackwards # noqa: F401 __author__ = """Robin Robin""" __email__ = 'robinsquare42@gmail.com' __version__ = '2.0.0'
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/callbacks/fine_csv_logger.py
hanlp/callbacks/fine_csv_logger.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-12-05 02:12 import copy from io import TextIOWrapper from typing import List import numpy as np import tensorflow as tf class StreamTableFormatter(object): def __init__(self) -> None: super().__init__() self.col_widths = None def format_r...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/callbacks/__init__.py
hanlp/callbacks/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-12-05 02:10
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/common/vocab_tf.py
hanlp/common/vocab_tf.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-06-13 22:42 from typing import List, Dict, Union, Iterable from hanlp_common.structure import Serializable from hanlp_common.constant import PAD, UNK import tensorflow as tf from tensorflow.python.ops.lookup_ops import index_table_from_tensor class VocabTF(Seriali...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/common/transform.py
hanlp/common/transform.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-05-03 14:44 import logging import os from abc import ABC, abstractmethod from typing import Tuple, Union, List from hanlp_common.constant import EOS, PAD from hanlp_common.structure import SerializableDict from hanlp_common.configurable import Configurable from hanl...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/common/structure.py
hanlp/common/structure.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-08-26 14:58 from typing import Dict from hanlp_common.configurable import Configurable from hanlp_common.reflection import classpath_of from hanlp_common.structure import SerializableDict class ConfigTracker(Configurable): def __init__(self, locals_: Dict, ex...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/common/vocab.py
hanlp/common/vocab.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-06-13 22:42 from collections import Counter from typing import List, Dict, Union, Iterable from hanlp_common.constant import UNK, PAD from hanlp_common.structure import Serializable from hanlp_common.reflection import classpath_of class Vocab(Serializable): de...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/common/component.py
hanlp/common/component.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-08-26 14:45 import inspect from abc import ABC, abstractmethod from typing import Any from hanlp_common.configurable import Configurable class Component(Configurable, ABC): @abstractmethod def predict(self, *args, **kwargs): """Predict on data. Thi...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/common/dataset.py
hanlp/common/dataset.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-05-09 20:27 import math import os import random import tempfile import warnings from abc import ABC, abstractmethod from copy import copy from logging import Logger from typing import Union, List, Callable, Iterable, Dict, Any import torch import torch.multiprocessi...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
true
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/common/transform_tf.py
hanlp/common/transform_tf.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-10-27 14:22 import inspect from abc import ABC, abstractmethod from typing import Generator, Tuple, Union, Iterable, Any import tensorflow as tf from hanlp_common.structure import SerializableDict from hanlp.common.vocab_tf import VocabTF from hanlp.utils.io_util i...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/common/torch_component.py
hanlp/common/torch_component.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-05-08 21:20 import logging import os import re import time from abc import ABC, abstractmethod from typing import Optional, Dict, List, Union, Callable import torch from torch import nn from torch.utils.data import DataLoader import hanlp from hanlp.common.componen...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/common/keras_component.py
hanlp/common/keras_component.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-08-26 14:45 import logging import math import os import sys from abc import ABC, abstractmethod from typing import Optional, List, Any, Dict import numpy as np import tensorflow as tf import hanlp.utils from hanlp_common.io import save_json, load_json from hanlp.ca...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/common/__init__.py
hanlp/common/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-08-26 14:45
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/transform/table_tf.py
hanlp/transform/table_tf.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-11-10 21:00 from abc import ABC from typing import Tuple, Union import numpy as np import tensorflow as tf from hanlp_common.structure import SerializableDict from hanlp.common.transform_tf import Transform from hanlp_common.constant import PAD from hanlp.common.voc...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/transform/tacred_tf.py
hanlp/transform/tacred_tf.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-03-14 17:06 from typing import Union, Tuple import tensorflow as tf from hanlp_common.structure import SerializableDict from hanlp.common.transform_tf import Transform from hanlp.common.vocab_tf import VocabTF from hanlp_common.io import load_json from hanlp_common...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/transform/transformer_tokenizer.py
hanlp/transform/transformer_tokenizer.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-05-03 16:23 import warnings from typing import Union, Optional from hanlp_common.constant import BOS, EOS from hanlp_common.structure import SerializableDict from hanlp.layers.transformers.pt_imports import PreTrainedTokenizer, PretrainedConfig, AutoTokenizer_ from ...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
true
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/transform/text_tf.py
hanlp/transform/text_tf.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-12-04 11:46 from typing import Union, Tuple, Iterable, Any import tensorflow as tf from hanlp_common.structure import SerializableDict from hanlp.common.transform_tf import Transform from hanlp.common.vocab_tf import VocabTF from hanlp.metrics.chunking.sequence_lab...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/transform/tsv_tf.py
hanlp/transform/tsv_tf.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-06-13 21:15 import functools from abc import ABC from typing import Tuple, Union, Optional, Iterable, List import tensorflow as tf from hanlp_common.structure import SerializableDict from hanlp.common.transform_tf import Transform from hanlp.common.vocab_tf import...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/transform/txt_tf.py
hanlp/transform/txt_tf.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-10-24 15:07 import functools from abc import ABC from typing import Tuple, Union, List, Iterable import tensorflow as tf from hanlp.common.transform_tf import Transform from hanlp.common.vocab_tf import VocabTF from hanlp.utils.io_util import get_resource from hanl...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/transform/__init__.py
hanlp/transform/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-12-29 22:24
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/transform/conll_tf.py
hanlp/transform/conll_tf.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-05-08 15:30 from abc import abstractmethod from collections import Counter from typing import Union, Tuple, Iterable, Any, Generator import numpy as np import tensorflow as tf from transformers import PreTrainedTokenizer, PretrainedConfig from hanlp_common.constant...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
true
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/transform/glue_tf.py
hanlp/transform/glue_tf.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-05-08 16:34 from hanlp_common.structure import SerializableDict from hanlp.datasets.glu.glue import STANFORD_SENTIMENT_TREEBANK_2_TRAIN, MICROSOFT_RESEARCH_PARAPHRASE_CORPUS_DEV from hanlp.transform.table_tf import TableTransform class StanfordSentimentTreebank2Tra...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/time_distributed.py
hanlp/layers/time_distributed.py
""" A wrapper that unrolls the second (time) dimension of a tensor into the first (batch) dimension, applies some other `Module`, and then rolls the time dimension back up. """ from typing import List import torch class TimeDistributed(torch.nn.Module): """ Given an input shaped like `(batch_size, time_ste...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/weight_normalization.py
hanlp/layers/weight_normalization.py
# Copyright 2019 The TensorFlow Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applica...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/dropout.py
hanlp/layers/dropout.py
# -*- coding:utf-8 -*- # Date: 2020-06-05 17:47 from typing import List import torch import torch.nn as nn class WordDropout(nn.Module): def __init__(self, p: float, oov_token: int, exclude_tokens: List[int] = None) -> None: super().__init__() self.oov_token = oov_token self.p = p ...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/scalar_mix.py
hanlp/layers/scalar_mix.py
# This file is modified from udify, which is licensed under the MIT license: # MIT License # # Copyright (c) 2019 Dan Kondratyuk # # 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 rest...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/cnn_encoder.py
hanlp/layers/cnn_encoder.py
from typing import Optional, Tuple import torch from torch.nn import Conv1d, Linear class CnnEncoder(torch.nn.Module): """ A `CnnEncoder` is a combination of multiple convolution layers and max pooling layers. As a [`Seq2VecEncoder`](./seq2vec_encoder.md), the input to this module is of shape `(batch_si...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/feedforward.py
hanlp/layers/feedforward.py
""" A feed-forward neural network. """ from typing import List, Union import torch from hanlp.utils.torch_util import activation_from_name class FeedForward(torch.nn.Module): """ This `Module` is a feed-forward neural network, just a sequence of `Linear` layers with activation functions in between. ...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/__init__.py
hanlp/layers/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-10-26 00:50
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/feed_forward.py
hanlp/layers/feed_forward.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-07-06 14:37 from typing import Union, List from hanlp.layers import feedforward from hanlp.common.structure import ConfigTracker class FeedForward(feedforward.FeedForward, ConfigTracker): def __init__(self, input_dim: int, num_layers: int, hidden_dims: Union[...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/transformers/encoder.py
hanlp/layers/transformers/encoder.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-06-22 21:06 import warnings from typing import Union, Dict, Any, Sequence, Tuple, Optional import torch from torch import nn from hanlp.layers.dropout import WordDropout from hanlp.layers.scalar_mix import ScalarMixWithDropout, ScalarMixWithDropoutBuilder from hanlp...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/transformers/utils_tf.py
hanlp/layers/transformers/utils_tf.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-12-29 15:32 import tensorflow as tf from hanlp.optimizers.adamw import create_optimizer from hanlp.utils.log_util import logger def config_is(config, model='bert'): return model in type(config).__name__.lower() def convert_examples_to_features( words,...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/transformers/resource.py
hanlp/layers/transformers/resource.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2021-05-20 12:43 from hanlp.utils.io_util import get_resource from hanlp_common.constant import HANLP_URL tokenizer_mirrors = { 'hfl/chinese-electra-180g-base-discriminator': HANLP_URL + 'transformers/electra_zh_base_20210706_125233.zip', 'hfl/chinese-electra-180...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/transformers/utils.py
hanlp/layers/transformers/utils.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-06-15 21:22 from collections import defaultdict from typing import Tuple, Union import torch from torch.nn import functional as F from hanlp.components.parsers.ud import udify_util as util from hanlp.layers.transformers.pt_imports import PreTrainedModel def trans...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/transformers/tf_imports.py
hanlp/layers/transformers/tf_imports.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-05-08 21:57 from transformers import BertTokenizer, BertConfig, PretrainedConfig, TFAutoModel, \ AutoConfig, AutoTokenizer, PreTrainedTokenizer, TFPreTrainedModel, TFAlbertModel, TFAutoModelWithLMHead, \ BertTokenizerFast, TFAlbertForMaskedLM, AlbertConfig, T...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/transformers/__init__.py
hanlp/layers/transformers/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-12-29 15:17 # mute transformers import logging logging.getLogger('transformers.file_utils').setLevel(logging.ERROR) logging.getLogger('transformers.filelock').setLevel(logging.ERROR) logging.getLogger('transformers.tokenization_utils').setLevel(logging.ERROR) loggin...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/transformers/pt_imports.py
hanlp/layers/transformers/pt_imports.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-05-09 11:25 import os import warnings from hanlp.layers.transformers.resource import get_tokenizer_mirror, get_model_mirror if os.environ.get('TOKENIZERS_PARALLELISM', None) is None: os.environ["TOKENIZERS_PARALLELISM"] = "false" from transformers import BertTo...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/transformers/loader_tf.py
hanlp/layers/transformers/loader_tf.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-01-04 06:05 import tensorflow as tf from transformers import TFAutoModel from hanlp.layers.transformers.pt_imports import AutoTokenizer_, AutoModel_ def build_transformer(transformer, max_seq_length, num_labels, tagging=True, tokenizer_only=False): tokenizer =...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/transformers/relative_transformer.py
hanlp/layers/transformers/relative_transformer.py
# A modified version of the implementation from the following paper: # TENER: Adapting Transformer Encoder for Named Entity Recognition # Hang Yan, Bocao Deng, Xiaonan Li, Xipeng Qiu import math import torch import torch.nn.functional as F from torch import Tensor, nn from hanlp.common.structure import ConfigTracker ...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/embeddings/char_cnn_tf.py
hanlp/layers/embeddings/char_cnn_tf.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-12-20 21:15 from functools import reduce import tensorflow as tf from hanlp.common.vocab_tf import VocabTF from hanlp.utils.tf_util import hanlp_register @hanlp_register class CharCNNEmbeddingTF(tf.keras.layers.Layer): def __init__(self, word_vocab: VocabTF, ...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/embeddings/char_rnn_tf.py
hanlp/layers/embeddings/char_rnn_tf.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-12-20 17:02 import tensorflow as tf from hanlp.common.vocab_tf import VocabTF from hanlp.utils.tf_util import hanlp_register @hanlp_register class CharRNNEmbeddingTF(tf.keras.layers.Layer): def __init__(self, word_vocab: VocabTF, char_vocab: VocabTF, ...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/embeddings/char_rnn.py
hanlp/layers/embeddings/char_rnn.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-06-02 23:49 from typing import Optional, Callable, Union import torch import torch.nn as nn from torch.nn.utils.rnn import pack_padded_sequence from hanlp_common.configurable import AutoConfigurable from hanlp.common.transform import VocabDict, ToChar from hanlp.co...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/embeddings/contextual_string_embedding.py
hanlp/layers/embeddings/contextual_string_embedding.py
# Most codes of this file is adopted from flair, which is licenced under: # # The MIT License (MIT) # # Flair is licensed under the following MIT License (MIT) Copyright © 2018 Zalando SE, https://tech.zalando.com # Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associ...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/embeddings/util.py
hanlp/layers/embeddings/util.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-05-09 15:45 from typing import Union import torch from torch import nn from hanlp.common.vocab import Vocab from hanlp.utils.init_util import embedding_uniform from hanlp.utils.torch_util import load_word2vec, load_word2vec_as_vocab_tensor def index_word2vec_with...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/embeddings/word2vec.py
hanlp/layers/embeddings/word2vec.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-05-09 13:38 import logging import math import os.path from typing import Optional, Callable, Union, List, Dict import torch from hanlp_common.configurable import AutoConfigurable from hanlp_common.constant import HANLP_VERBOSE from hanlp_trie.trie import Trie from t...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/embeddings/fast_text.py
hanlp/layers/embeddings/fast_text.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-05-27 15:06 import logging import os import sys from typing import Optional, Callable import fasttext import torch from torch import nn from torch.nn.utils.rnn import pad_sequence from hanlp_common.configurable import AutoConfigurable from torch.utils.data import D...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/embeddings/contextual_string_embedding_tf.py
hanlp/layers/embeddings/contextual_string_embedding_tf.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-12-19 03:24 from typing import List import tensorflow as tf import numpy as np from hanlp.components.rnn_language_model_tf import RNNLanguageModel from hanlp_common.constant import PAD from hanlp.utils.io_util import get_resource from hanlp.utils.tf_util import copy...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/embeddings/util_tf.py
hanlp/layers/embeddings/util_tf.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-05-09 15:46 from typing import Union import tensorflow as tf from hanlp.common.transform_tf import Transform from hanlp.common.vocab_tf import VocabTF from hanlp.layers.embeddings.char_cnn_tf import CharCNNEmbeddingTF from hanlp.layers.embeddings.char_rnn_tf import...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/embeddings/concat_embedding.py
hanlp/layers/embeddings/concat_embedding.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-12-20 17:08 import tensorflow as tf from hanlp.utils.tf_util import hanlp_register, copy_mask @hanlp_register class ConcatEmbedding(tf.keras.layers.Layer): def __init__(self, *embeddings, trainable=True, name=None, dtype=None, dynamic=False, **kwargs): ...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/embeddings/contextual_word_embedding.py
hanlp/layers/embeddings/contextual_word_embedding.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-07-05 13:50 from typing import Optional, Union, List, Any, Dict, Tuple import torch from torch import nn from hanlp_common.configurable import AutoConfigurable from hanlp.layers.embeddings.embedding import Embedding from hanlp.layers.scalar_mix import ScalarMixWith...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/embeddings/__init__.py
hanlp/layers/embeddings/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-08-24 21:48
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/embeddings/word2vec_tf.py
hanlp/layers/embeddings/word2vec_tf.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-08-24 21:49 import os from typing import Tuple, Union, List import numpy as np import tensorflow as tf from tensorflow.python.ops import math_ops from hanlp.common.vocab_tf import VocabTF from hanlp.utils.io_util import get_resource from hanlp.utils.torch_util impo...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/embeddings/embedding.py
hanlp/layers/embeddings/embedding.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-06-02 13:04 from abc import ABC, abstractmethod from typing import Callable, List, Optional, Iterable import torch from torch import nn from torch.nn import Module from hanlp_common.configurable import AutoConfigurable from hanlp.common.transform import TransformLi...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/embeddings/char_cnn.py
hanlp/layers/embeddings/char_cnn.py
# Adopted from https://github.com/allenai/allennlp under Apache Licence 2.0. # Changed the packaging and created a subclass CharCNNEmbedding from typing import Union, Tuple, Optional, Callable import torch from torch import nn from hanlp.layers.cnn_encoder import CnnEncoder from hanlp.layers.time_distributed import Ti...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/embeddings/fast_text_tf.py
hanlp/layers/embeddings/fast_text_tf.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-10-29 13:14 import os import sys import numpy as np import tensorflow as tf from tensorflow.python.keras.utils import tf_utils from hanlp_common.constant import PAD from hanlp.utils.io_util import get_resource, stdout_redirected from hanlp.utils.log_util import log...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/crf/crf_tf.py
hanlp/layers/crf/crf_tf.py
# Copyright 2019 The TensorFlow Authors. All Rights Reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applica...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/crf/crf.py
hanlp/layers/crf/crf.py
# Copied from https://github.com/kmkurn/pytorch-crf # Copyright 2017 Kemal Kurniawan <kemal@kkurniawan.com> # # 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 wi...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/crf/__init__.py
hanlp/layers/crf/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-12-18 22:55
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/layers/crf/crf_layer_tf.py
hanlp/layers/crf/crf_layer_tf.py
# ****************************************************************************** # Copyright 2017-2018 Intel Corporation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apa...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/pretrained/amr.py
hanlp/pretrained/amr.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2022-01-25 11:47 from hanlp_common.constant import HANLP_URL AMR3_SEQ2SEQ_BART_LARGE = HANLP_URL + 'amr/amr3_seq2seq_bart_large_83.30_20220125_114450.zip' '''A seq2seq (:cite:`bevilacqua-etal-2021-one`) BART (:cite:`lewis-etal-2020-bart`) large parser trained on Abstract...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/pretrained/dep.py
hanlp/pretrained/dep.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-12-29 02:55 from hanlp_common.constant import HANLP_URL CTB5_BIAFFINE_DEP_ZH = HANLP_URL + 'dep/biaffine_ctb5_20191229_025833.zip' 'Biaffine LSTM model (:cite:`dozat:17a`) trained on CTB5.' CTB7_BIAFFINE_DEP_ZH = HANLP_URL + 'dep/biaffine_ctb7_20200109_022431.zip' '...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/pretrained/word2vec.py
hanlp/pretrained/word2vec.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-12-21 18:25 from hanlp_common.constant import HANLP_URL CONVSEG_W2V_NEWS_TENSITE = HANLP_URL + 'embeddings/convseg_embeddings.zip' CONVSEG_W2V_NEWS_TENSITE_WORD_PKU = CONVSEG_W2V_NEWS_TENSITE + '#news_tensite.pku.words.w2v50' CONVSEG_W2V_NEWS_TENSITE_WORD_MSR = CONV...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/pretrained/eos.py
hanlp/pretrained/eos.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-12-22 13:22 from hanlp_common.constant import HANLP_URL UD_CTB_EOS_MUL = HANLP_URL + 'eos/eos_ud_ctb_mul_20201222_133543.zip' 'EOS model (:cite:`Schweter:Ahmed:2019`) trained on concatenated UD2.3 and CTB9.' # 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/srl.py
hanlp/pretrained/srl.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2021-08-07 19:07 from hanlp_common.constant import HANLP_URL CPB3_SRL_ELECTRA_SMALL = HANLP_URL + 'srl/cpb3_electra_small_crf_has_transform_20220218_135910.zip' 'Electra small model (:cite:`clark2020electra`) trained on CPB3. P=75.87% R=76.24% F1=76.05%.' ALL = {}
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false