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/mtl/tasks/tok/__init__.py
hanlp/components/mtl/tasks/tok/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-08-11 16:34
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/mtl/tasks/tok/reg_tok.py
hanlp/components/mtl/tasks/tok/reg_tok.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-08-02 16:51 import logging from typing import Union, List, Dict, Any, Iterable, Tuple import torch from hanlp_common.util import merge_locals_kwargs from torch import Tensor from torch.utils.data import DataLoader import hanlp.utils.torch_util from hanlp.common.dat...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/amr/__init__.py
hanlp/components/amr/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-08-20 17:35
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/amr/amrbart/bart_amr_parser.py
hanlp/components/amr/amrbart/bart_amr_parser.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2022-12-05 17:56 import logging import os.path from typing import Callable, Union, List import datetime import torch from torch.utils.data import DataLoader from hanlp.components.amr.amrbart.data_interface.dataset import AMRParsingDataSet from hanlp.common.dataset impor...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/amr/amrbart/__init__.py
hanlp/components/amr/amrbart/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2022-12-05 17:53
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/amr/amrbart/bart_amr_generation.py
hanlp/components/amr/amrbart/bart_amr_generation.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2022-12-05 17:56 import logging import os.path from typing import Callable, Union, List import penman import torch from torch.utils.data import DataLoader from hanlp.components.amr.amrbart.data_interface.dataset import AMR2TextDataSet from hanlp.common.dataset import So...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/amr/amrbart/data_interface/dataset.py
hanlp/components/amr/amrbart/data_interface/dataset.py
# coding:utf-8 # MIT License # # Copyright (c) 2022 xfbai # # 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...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/amr/amrbart/data_interface/__init__.py
hanlp/components/amr/amrbart/data_interface/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2022-12-07 14:36
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/amr/amrbart/preprocess/read_and_process.py
hanlp/components/amr/amrbart/preprocess/read_and_process.py
# coding:utf-8 # MIT License # # Copyright (c) 2022 xfbai # # 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...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/amr/amrbart/preprocess/amr_io.py
hanlp/components/amr/amrbart/preprocess/amr_io.py
# coding:utf-8 # the code is migrated from https://github.com/SapienzaNLP/spring # MIT License # # Copyright (c) 2022 xfbai # # 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 restrict...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/amr/amrbart/preprocess/__init__.py
hanlp/components/amr/amrbart/preprocess/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2022-12-03 20:33
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/amr/amrbart/preprocess/penman_interface.py
hanlp/components/amr/amrbart/preprocess/penman_interface.py
# coding:utf-8 # MIT License # # Copyright (c) 2022 xfbai # # 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...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/amr/amrbart/common/__init__.py
hanlp/components/amr/amrbart/common/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2022-12-05 17:53
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/amr/amrbart/common/penman_interface.py
hanlp/components/amr/amrbart/common/penman_interface.py
# coding:utf-8 # MIT License # # Copyright (c) 2022 xfbai # # 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...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/amr/amrbart/common/constant.py
hanlp/components/amr/amrbart/common/constant.py
# coding:utf-8 # MIT License # # Copyright (c) 2022 xfbai # # 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...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
true
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/amr/amrbart/common/postprocessing.py
hanlp/components/amr/amrbart/common/postprocessing.py
# coding:utf-8 # MIT License # # Copyright (c) 2022 xfbai # # 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...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/amr/amrbart/model_interface/modeling_bart.py
hanlp/components/amr/amrbart/model_interface/modeling_bart.py
# coding=utf-8 # Copyright 2021 The Fairseq Authors and The HuggingFace Inc. team. 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/...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
true
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/amr/amrbart/model_interface/__init__.py
hanlp/components/amr/amrbart/model_interface/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2022-12-03 20:33
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/amr/amrbart/model_interface/tokenization_bart.py
hanlp/components/amr/amrbart/model_interface/tokenization_bart.py
# coding:utf-8 # this is a simplified version of "https://github.com/SapienzaNLP/spring/blob/main/spring_amr/tokenization_bart.py" # MIT License # # Copyright (c) 2022 xfbai # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Softw...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/amr/seq2seq/optim.py
hanlp/components/amr/seq2seq/optim.py
# taken from import math import torch from torch.optim.optimizer import Optimizer class RAdam(Optimizer): def __init__(self, params, lr=1e-3, betas=(0.9, 0.999), eps=1e-8, weight_decay=0, degenerated_to_sgd=True): if not 0.0 <= lr: raise ValueError("Invalid learning rate: {}".format(lr)) ...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/amr/seq2seq/seq2seq_amr_parser.py
hanlp/components/amr/seq2seq/seq2seq_amr_parser.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2021-04-28 17:33 import datetime import functools import logging import os from typing import Union, List, Callable import torch from torch.utils.data import DataLoader from transformers import get_constant_schedule_with_warmup, T5ForConditionalGeneration from transforme...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/amr/seq2seq/evaluation.py
hanlp/components/amr/seq2seq/evaluation.py
from pathlib import Path import penman def write_predictions(predictions_path, tokenizer, graphs): pieces = [penman.encode(g) for g in graphs] text = '\n\n'.join(pieces) if tokenizer: text = text.replace(tokenizer.INIT, '') Path(predictions_path).write_text(text) return predictions_path ...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/amr/seq2seq/__init__.py
hanlp/components/amr/seq2seq/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2021-04-27 19:24
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/amr/seq2seq/dataset/IO.py
hanlp/components/amr/seq2seq/dataset/IO.py
import glob from typing import List, Union, Iterable from pathlib import Path from .penman import pm_load as pm_load def read_raw_amr_data( paths: List[Union[str, Path]], use_recategorization=False, dereify=True, remove_wiki=False, ): assert paths if not isinstance(paths, Iter...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/amr/seq2seq/dataset/dataset.py
hanlp/components/amr/seq2seq/dataset/dataset.py
from collections import Counter from typing import Union, List, Callable, Tuple import torch import penman from penman import Graph from hanlp.common.dataset import TransformableDataset from hanlp.components.amr.seq2seq.dataset.IO import read_raw_amr_data from hanlp.components.amr.seq2seq.dataset.penman import role_is_...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/amr/seq2seq/dataset/linearization.py
hanlp/components/amr/seq2seq/dataset/linearization.py
import abc import itertools from collections import deque, defaultdict import re from typing import List, Optional, Dict, Any, Set, TypeVar from dataclasses import dataclass import networkx as nx import penman @dataclass class SemanticGraph: nodes_var: List[str] """ List of linearized nodes, with special ...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/amr/seq2seq/dataset/__init__.py
hanlp/components/amr/seq2seq/dataset/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2021-04-27 19:29
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/amr/seq2seq/dataset/tokenization_bart.py
hanlp/components/amr/seq2seq/dataset/tokenization_bart.py
import copy import sys from typing import Set, Iterable import penman import regex as re import torch from transformers import BartTokenizer from . import postprocessing from .linearization import AMRTokens, AMRLinearizer from .penman import pm_encode class AMRBartTokenizer(BartTokenizer): ADDITIONAL = [ ...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/amr/seq2seq/dataset/tokenization_t5.py
hanlp/components/amr/seq2seq/dataset/tokenization_t5.py
import copy import sys from typing import Set, Iterable, Dict import penman import regex as re import torch import traceback from transformers import T5Tokenizer, T5TokenizerFast from . import postprocessing from .linearization import AMRTokens, AMRLinearizer from .penman import pm_encode class AMRT5Tokenizer(T5Tok...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/amr/seq2seq/dataset/postprocessing.py
hanlp/components/amr/seq2seq/dataset/postprocessing.py
from collections import defaultdict, Counter import enum import re import networkx as nx import penman from hanlp.components.amr.seq2seq.dataset.penman import pm_encode BACKOFF = penman.Graph([ penman.Triple('d2', ':instance', 'dog'), penman.Triple('b1', ':instance', 'bark-01'), penman.Triple('b1', ':ARG0...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/amr/seq2seq/dataset/penman.py
hanlp/components/amr/seq2seq/dataset/penman.py
from typing import List from penman import load as load_, Graph, Triple from penman import loads as loads_ from penman import encode as encode_ from penman.model import Model from penman.models.noop import NoOpModel from penman.models import amr import penman import logging op_model = Model() noop_model = NoOpModel()...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/taggers/tagger_tf.py
hanlp/components/taggers/tagger_tf.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-10-25 21:49 import logging from abc import ABC import tensorflow as tf from hanlp.common.keras_component import KerasComponent from hanlp.layers.crf.crf_layer_tf import CRF, CRFLoss, CRFWrapper from hanlp.metrics.chunking.iobes_tf import IOBES_F1_TF class TaggerC...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/taggers/rnn_tagger.py
hanlp/components/taggers/rnn_tagger.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-05-20 13:12 import logging import torch from torch import nn from torch.optim.lr_scheduler import ReduceLROnPlateau from torch.utils.data import DataLoader from hanlp.common.dataset import PadSequenceDataLoader, SortingSampler, TransformableDataset from hanlp_commo...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/taggers/util.py
hanlp/components/taggers/util.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-06-01 00:31 from typing import List, Tuple from hanlp.utils.span_util import allowed_transitions def guess_tagging_scheme(labels: List[str]) -> str: tagset = set(y.split('-')[0] for y in labels) for scheme in "BIO", "BIOUL", "BMES", 'IOBES': if tags...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/taggers/pos_tf.py
hanlp/components/taggers/pos_tf.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-12-05 23:05 from hanlp.components.taggers.cnn_tagger_tf import CNNTaggerTF from hanlp.components.taggers.rnn_tagger_tf import RNNTaggerTF class CNNPartOfSpeechTaggerTF(CNNTaggerTF): pass class RNNPartOfSpeechTaggerTF(RNNTaggerTF): pass
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/taggers/tagger.py
hanlp/components/taggers/tagger.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-08-11 12:19 import logging import warnings from abc import ABC, abstractmethod from typing import List, TextIO, Any, Union, Dict, Tuple, Sequence import torch from torch import optim, nn from torch.utils.data import DataLoader from hanlp_common.constant import IDX ...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/taggers/rnn_tagger_tf.py
hanlp/components/taggers/rnn_tagger_tf.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-09-14 20:30 from typing import Union, List import tensorflow as tf from hanlp.common.transform_tf import Transform from hanlp.components.taggers.tagger_tf import TaggerComponent from hanlp.transform.tsv_tf import TSVTaggingTransform from hanlp.common.vocab_tf impor...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/taggers/cnn_tagger_tf.py
hanlp/components/taggers/cnn_tagger_tf.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-10-31 13:52 from abc import ABC from typing import Union, Tuple, Any, List, Iterable import tensorflow as tf from hanlp.components.taggers.tagger_tf import TaggerComponent from hanlp.transform.tsv_tf import TSVTaggingTransform from hanlp.common.vocab_tf import Voca...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/taggers/__init__.py
hanlp/components/taggers/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-08-28 15:39
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/taggers/ngram_conv/ngram_conv_tagger.py
hanlp/components/taggers/ngram_conv/ngram_conv_tagger.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-10-25 00:04 from typing import Union, Optional, Tuple, Any, Iterable, List import tensorflow as tf from hanlp_common.structure import SerializableDict from hanlp.components.taggers.tagger_tf import TaggerComponent from hanlp.transform.tsv_tf import TSVTaggingTrans...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/taggers/ngram_conv/__init__.py
hanlp/components/taggers/ngram_conv/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-12-29 22:18
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/taggers/transformers/transformer_tagger_tf.py
hanlp/components/taggers/transformers/transformer_tagger_tf.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-12-29 13:55 import math import tensorflow as tf from hanlp.common.transform_tf import Transform from hanlp.components.taggers.tagger_tf import TaggerComponent from hanlp.components.taggers.transformers.transformer_transform_tf import TransformerTransform from hanlp...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/taggers/transformers/metrics_tf.py
hanlp/components/taggers/transformers/metrics_tf.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-12-30 16:33 import tensorflow as tf class Accuracy(tf.keras.metrics.SparseCategoricalAccuracy): def __init__(self, name='sparse_categorical_accuracy', dtype=None, mask_value=0): super().__init__(name, dtype) self.mask_value = mask_value de...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/taggers/transformers/transformer_tagger.py
hanlp/components/taggers/transformers/transformer_tagger.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-06-15 20:55 import logging from typing import Union, List import torch from torch import nn from torch.utils.data import DataLoader from hanlp.common.dataset import PadSequenceDataLoader, SamplerBuilder, TransformableDataset from hanlp.common.structure import Histo...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/taggers/transformers/__init__.py
hanlp/components/taggers/transformers/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-12-29 13:57
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/taggers/transformers/transformer_transform_tf.py
hanlp/components/taggers/transformers/transformer_transform_tf.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-12-29 15:14 from typing import Union, Tuple, List, Iterable 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.layers.transformers.utils_tf...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/taggers/rnn/rnntaggingmodel.py
hanlp/components/taggers/rnn/rnntaggingmodel.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/taggers/rnn/__init__.py
hanlp/components/taggers/rnn/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-05-19 15:41
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/eos/__init__.py
hanlp/components/eos/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-07-26 20:19
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/eos/ngram.py
hanlp/components/eos/ngram.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-07-26 20:19 import logging from collections import Counter from typing import Union, List, Callable import torch from torch import nn, optim from torch.nn import BCEWithLogitsLoss from torch.utils.data import DataLoader from hanlp.common.dataset import PadSequenceD...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/sts/transformer_sts.py
hanlp/components/sts/transformer_sts.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2021-05-20 17:03 import logging from typing import Union, List import torch from torch.utils.data import DataLoader from hanlp.common.structure import History from hanlp.layers.transformers.pt_imports import AutoConfig_, AutoTokenizer_ from transformers import AutoModelFo...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/sts/__init__.py
hanlp/components/sts/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2021-05-20 17:02
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/ner/transformer_ner.py
hanlp/components/ner/transformer_ner.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-10-07 11:08 import functools from typing import Union, List, Dict, Any, Set from hanlp_trie import DictInterface, TrieDict from hanlp.common.dataset import SamplerBuilder from hanlp.components.taggers.transformers.transformer_tagger import TransformerTagger from ha...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/ner/rnn_ner.py
hanlp/components/ner/rnn_ner.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-06-12 18:00 from typing import Any import torch from hanlp_common.util import merge_locals_kwargs import hanlp.utils.span_util from hanlp.components.taggers.rnn_tagger import RNNTagger from hanlp.metrics.chunking.conlleval import SpanF1 class RNNNamedEntityRecogn...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/ner/ner_tf.py
hanlp/components/ner/ner_tf.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-09-14 20:33 from abc import ABC from typing import Union, Any, Tuple, Iterable import tensorflow as tf from hanlp.components.taggers.transformers.transformer_transform_tf import TransformerTransform from hanlp.common.transform_tf import Transform 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/components/ner/__init__.py
hanlp/components/ner/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-07-21 17:22
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/ner/biaffine_ner/biaffine_ner.py
hanlp/components/ner/biaffine_ner/biaffine_ner.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-07-09 18:13 import logging from typing import Union, List, Callable, Dict, Any from hanlp_common.constant import IDX from hanlp.common.structure import History from hanlp.components.ner.biaffine_ner.biaffine_ner_model import BiaffineNamedEntityRecognitionModel from ...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/ner/biaffine_ner/__init__.py
hanlp/components/ner/biaffine_ner/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-07-21 18:41
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/ner/biaffine_ner/biaffine_ner_model.py
hanlp/components/ner/biaffine_ner/biaffine_ner_model.py
from typing import Dict import torch import torch.nn.functional as F from torch import nn import hanlp.utils.torch_util from hanlp.layers.time_distributed import TimeDistributed from ...parsers.biaffine.biaffine import Biaffine def initializer_1d(input_tensor, initializer): assert len(input_tensor.size()) == 1 ...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/lm/mlm.py
hanlp/components/lm/mlm.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2022-01-29 21:07 import logging import math from typing import Callable, Union, List import torch from hanlp_common.constant import IDX from hanlp_common.util import reorder from torch.utils.data import DataLoader from transformers import AutoModelForMaskedLM from transf...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/lm/__init__.py
hanlp/components/lm/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2022-01-29 21:07
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/srl/__init__.py
hanlp/components/srl/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-06-22 20:50
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/srl/span_bio/baffine_tagging.py
hanlp/components/srl/span_bio/baffine_tagging.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-12-04 13:59 import math import torch from torch import nn from hanlp.components.parsers.biaffine.biaffine import Biaffine from hanlp.components.parsers.biaffine.mlp import MLP from hanlp.layers.crf.crf import CRF class BiaffineTaggingDecoder(nn.Module): def ...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/srl/span_bio/__init__.py
hanlp/components/srl/span_bio/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-12-04 13:59
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/srl/span_bio/span_bio.py
hanlp/components/srl/span_bio/span_bio.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-06-22 20:54 import logging from copy import copy from typing import Union, List, Callable, Dict, Any from bisect import bisect import torch import torch.nn.functional as F from torch import nn from torch.utils.data import DataLoader from hanlp_common.constant import...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/srl/span_rank/layer.py
hanlp/components/srl/span_rank/layer.py
# Adopted from https://github.com/KiroSummer/A_Syntax-aware_MTL_Framework_for_Chinese_SRL import torch import torch.nn as nn from torch.autograd import Variable import numpy as np import torch.nn.functional as F from hanlp.components.srl.span_rank.util import block_orth_normal_initializer def get_tensor_np(t): ...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/srl/span_rank/util.py
hanlp/components/srl/span_rank/util.py
# Adopted from https://github.com/KiroSummer/A_Syntax-aware_MTL_Framework_for_Chinese_SRL import torch def block_orth_normal_initializer(input_size, output_size): weight = [] for o in output_size: for i in input_size: param = torch.FloatTensor(o, i) torch.nn.init.orthogonal_(pa...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/srl/span_rank/span_ranking_srl_model.py
hanlp/components/srl/span_rank/span_ranking_srl_model.py
from typing import Dict import hanlp.utils.torch_util from hanlp.layers.feedforward import FeedForward from hanlp.layers.time_distributed import TimeDistributed from .highway_variational_lstm import * import torch from ...parsers.biaffine.biaffine import Biaffine def initializer_1d(input_tensor, initializer): ...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/srl/span_rank/srl_eval_utils.py
hanlp/components/srl/span_rank/srl_eval_utils.py
# Evaluation util functions for PropBank SRL. import codecs import collections import operator import tempfile from collections import Counter from hanlp.metrics.srl.srlconll import official_conll_05_evaluate _SRL_CONLL_EVAL_SCRIPT = "../run_eval.sh" def split_example_for_eval(example): """Split document-based...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/srl/span_rank/inference_utils.py
hanlp/components/srl/span_rank/inference_utils.py
# Adopted from https://github.com/KiroSummer/A_Syntax-aware_MTL_Framework_for_Chinese_SRL # Inference functions for the SRL model. import numpy as np def decode_spans(span_starts, span_ends, span_scores, labels_inv): """ Args: span_starts: [num_candidates,] span_scores: [num_candidates, num_labe...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/srl/span_rank/highway_variational_lstm.py
hanlp/components/srl/span_rank/highway_variational_lstm.py
# Adopted from https://github.com/KiroSummer/A_Syntax-aware_MTL_Framework_for_Chinese_SRL import torch import torch.nn as nn import torch.nn.functional as F import torch.nn.init as init from torch.autograd import Variable from .layer import DropoutLayer, HighwayLSTMCell, VariationalLSTMCell def initializer_1d(input_...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/srl/span_rank/__init__.py
hanlp/components/srl/span_rank/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-07-19 22:22
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/srl/span_rank/span_rank.py
hanlp/components/srl/span_rank/span_rank.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-07-09 18:13 import logging from bisect import bisect from typing import Union, List, Callable, Tuple, Dict, Any from hanlp_common.constant import IDX from hanlp.layers.transformers.utils import build_optimizer_scheduler_with_transformer import torch from torch.utils...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/classifiers/transformer_classifier.py
hanlp/components/classifiers/transformer_classifier.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-06-08 16:31 import logging from abc import ABC from typing import Callable, Union from typing import List import torch from torch import nn from torch.utils.data import DataLoader from hanlp_common.constant import IDX from hanlp.common.dataset import TableDataset, ...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/classifiers/transformer_classifier_hf.py
hanlp/components/classifiers/transformer_classifier_hf.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2023-02-17 17:54 import logging from typing import List, Union, Callable import torch from torch.utils.data import DataLoader from transformers import AutoModelForSequenceClassification, PreTrainedTokenizer, AutoTokenizer from hanlp.common.dataset import TableDataset, P...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/classifiers/transformer_regression_hf.py
hanlp/components/classifiers/transformer_regression_hf.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2023-02-17 17:54 import logging from typing import List, Union, Callable import torch from torch.utils.data import DataLoader from transformers import AutoModelForSequenceClassification, PreTrainedTokenizer, AutoTokenizer from hanlp.common.dataset import TableDataset, P...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/classifiers/fasttext_classifier.py
hanlp/components/classifiers/fasttext_classifier.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2022-09-28 13:31 import os import sys from typing import List, Union import fasttext from fasttext.FastText import _FastText import hanlp from hanlp.common.component import Component from hanlp.utils.io_util import get_resource, stdout_redirected from hanlp_common.io im...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/classifiers/__init__.py
hanlp/components/classifiers/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-11-10 13:18
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/classifiers/transformer_classifier_tf.py
hanlp/components/classifiers/transformer_classifier_tf.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-11-10 13:19 import math from typing import Union, Tuple, Any, Iterable import tensorflow as tf from hanlp.common.keras_component import KerasComponent from hanlp_common.structure import SerializableDict from hanlp.layers.transformers.loader_tf import build_transform...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/tokenizers/tok.py
hanlp/components/tokenizers/tok.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-06-12 13:08 from typing import Any, Callable from hanlp.components.taggers.rnn_tagger import RNNTagger from hanlp.datasets.tokenization.loaders.chunking_dataset import ChunkingDataset from hanlp.metrics.chunking.chunking_f1 import ChunkingF1 from hanlp.utils.span_ut...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/tokenizers/__init__.py
hanlp/components/tokenizers/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-08-11 02:48
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/tokenizers/multi_criteria_cws_transformer.py
hanlp/components/tokenizers/multi_criteria_cws_transformer.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-10-21 19:55 from typing import List, Union from hanlp.common.dataset import SamplerBuilder from hanlp.components.taggers.transformers.transformer_tagger import TransformerTagger from hanlp.components.tokenizers.transformer import TransformerTaggingTokenizer from han...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/tokenizers/tok_tf.py
hanlp/components/tokenizers/tok_tf.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-10-27 14:30 import logging from typing import Union, Any, List, Tuple, Iterable import tensorflow as tf from hanlp.common.keras_component import KerasComponent from hanlp.components.taggers.ngram_conv.ngram_conv_tagger import NgramTransform, NgramConvTaggerTF from ...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/tokenizers/transformer.py
hanlp/components/tokenizers/transformer.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-08-11 02:48 import functools from typing import TextIO, Union, List, Dict, Any, Set import torch from hanlp.common.dataset import SamplerBuilder from hanlp.common.transform import TransformList from hanlp.components.taggers.transformers.transformer_tagger import Tra...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/parsers/conll.py
hanlp/components/parsers/conll.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-12-26 15:37 from typing import Union from hanlp.utils.io_util import get_resource, TimingFileIterator from hanlp.utils.log_util import logger def collapse_enhanced_empty_nodes(sent: list): collapsed = [] for cells in sent: if isinstance(cells[0], f...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/parsers/parse_alg.py
hanlp/components/parsers/parse_alg.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-04-02 23:20 from collections import defaultdict import hanlp.utils.span_util from hanlp.components.parsers.chu_liu_edmonds import decode_mst import numpy as np class Tarjan: """Computes Tarjan's algorithm for finding strongly connected components (cycles) of a...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/parsers/alg_tf.py
hanlp/components/parsers/alg_tf.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-12-26 19:49 # Ported from the PyTorch implementation https://github.com/zysite/biaffine-parser from typing import List import numpy as np import tensorflow as tf from collections import defaultdict def nonzero(t: tf.Tensor) -> tf.Tensor: return tf.where(t > 0) ...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/parsers/chu_liu_edmonds.py
hanlp/components/parsers/chu_liu_edmonds.py
# Adopted from https://github.com/allenai/allennlp under Apache Licence 2.0. # Changed the packaging. from typing import List, Set, Tuple, Dict import numpy def decode_mst( energy: numpy.ndarray, length: int, has_labels: bool = True ) -> Tuple[numpy.ndarray, numpy.ndarray]: """Note: Counter to typical in...
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_parser_tf.py
hanlp/components/parsers/biaffine_parser_tf.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-12-22 12:47 import logging import math import os from typing import List import numpy as np import tensorflow as tf from hanlp.components.parsers.parse_alg import unique_root, adjust_root_score, chu_liu_edmonds from hanlp.layers.transformers.loader_tf import build_t...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/parsers/__init__.py
hanlp/components/parsers/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-12-22 12:46
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/parsers/alg.py
hanlp/components/parsers/alg.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/constituency/treecrf.py
hanlp/components/parsers/constituency/treecrf.py
# -*- coding:utf-8 -*- # Adopted from https://github.com/yzhangcs/parser # 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, 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/constituency/crf_constituency_model.py
hanlp/components/parsers/constituency/crf_constituency_model.py
# -*- coding:utf-8 -*- # Adopted from https://github.com/yzhangcs/parser # 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, 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/constituency/crf_constituency_parser.py
hanlp/components/parsers/constituency/crf_constituency_parser.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-11-28 21:24 import logging from typing import Union, List import torch from phrasetree.tree import Tree from torch.utils.data import DataLoader from hanlp_common.constant import BOS, EOS, IDX from hanlp.common.dataset import TransformableDataset, SamplerBuilder, Pa...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false
hankcs/HanLP
https://github.com/hankcs/HanLP/blob/ddb1299bddff079e447af52ec12549c50636bfa8/hanlp/components/parsers/constituency/__init__.py
hanlp/components/parsers/constituency/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2020-11-28 19:26
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_tf/model.py
hanlp/components/parsers/biaffine_tf/model.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-12-26 23:04 import tensorflow as tf from hanlp.layers.transformers.tf_imports import TFPreTrainedModel from hanlp.components.parsers.biaffine_tf.layers import IndependentDropout, SharedDropout, Biaffine, MLP class BiaffineModelTF(tf.keras.Model): def __init__(...
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_tf/__init__.py
hanlp/components/parsers/biaffine_tf/__init__.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-12-26 23:03
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_tf/layers.py
hanlp/components/parsers/biaffine_tf/layers.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-12-26 23:05 # Ported from the PyTorch implementation https://github.com/zysite/biaffine-parser import tensorflow as tf from hanlp.utils.tf_util import tf_bernoulli class Biaffine(tf.keras.layers.Layer): def __init__(self, n_in, n_out=1, bias_x=True, bias_y=True...
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_tf/alg.py
hanlp/components/parsers/biaffine_tf/alg.py
# -*- coding:utf-8 -*- # Author: hankcs # Date: 2019-12-26 19:49 # Ported from the PyTorch implementation https://github.com/zysite/biaffine-parser from typing import List import numpy as np import tensorflow as tf from collections import defaultdict def nonzero(t: tf.Tensor) -> tf.Tensor: return tf.where(t > 0) ...
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_model.py
hanlp/components/parsers/biaffine/biaffine_model.py
# -*- coding: utf-8 -*- from typing import Any, Tuple import torch import torch.nn as nn from torch.nn.utils.rnn import (pack_padded_sequence, pad_packed_sequence, pad_sequence) from hanlp.components.parsers.biaffine.biaffine import Biaffine from hanlp.components.parsers.biaffine.mlp i...
python
Apache-2.0
ddb1299bddff079e447af52ec12549c50636bfa8
2026-01-04T14:42:01.948856Z
false