1. add license declaration
Link: https://code.alibaba-inc.com/Ali-MaaS/MaaS-lib/codereview/10216802
master
| @@ -1,3 +1,5 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| from typing import Dict | from typing import Dict | ||||
| import numpy as np | import numpy as np | ||||
| @@ -1,3 +1,5 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| from typing import Dict | from typing import Dict | ||||
| from modelscope.metainfo import Metrics | from modelscope.metainfo import Metrics | ||||
| @@ -1,3 +1,5 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| import importlib | import importlib | ||||
| from typing import Dict, List, Optional, Union | from typing import Dict, List, Optional, Union | ||||
| @@ -1 +1,3 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| from .clip import load_from_config | from .clip import load_from_config | ||||
| @@ -1,3 +1,19 @@ | |||||
| # Copyright 2021-2022 The Alibaba DAMO NLP Team Authors. | |||||
| # Copyright 2018 The Google AI Language Team Authors and The HugginFace Inc. team. | |||||
| # Copyright (c) 2019, NVIDIA CORPORATION. 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 applicable law or agreed to in writing, software | |||||
| # distributed under the License is distributed on an "AS IS" BASIS, | |||||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
| # See the License for the specific language governing permissions and | |||||
| # limitations under the License. | |||||
| from __future__ import print_function | from __future__ import print_function | ||||
| import torch | import torch | ||||
| @@ -1,3 +1,5 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| import os.path as osp | import os.path as osp | ||||
| from typing import Dict, List | from typing import Dict, List | ||||
| @@ -1,3 +1,4 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| from modelscope.metainfo import Models | from modelscope.metainfo import Models | ||||
| from modelscope.models.base import TorchModel | from modelscope.models.base import TorchModel | ||||
| from modelscope.models.builder import BACKBONES | from modelscope.models.builder import BACKBONES | ||||
| @@ -1,3 +1,4 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| import os.path as osp | import os.path as osp | ||||
| from typing import Any, Dict | from typing import Any, Dict | ||||
| @@ -1,3 +1,4 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| import os | import os | ||||
| from typing import Any, Dict | from typing import Any, Dict | ||||
| @@ -1,3 +1,6 @@ | |||||
| # Part of the implementation is borrowed and modified from THUMT, | |||||
| # publicly available at https://github.com/THUNLP-MT/THUMT | |||||
| # Copyright 2017-2022 The Alibaba MT Team Authors. All rights reserved. | |||||
| import math | import math | ||||
| from collections import namedtuple | from collections import namedtuple | ||||
| from typing import Dict | from typing import Dict | ||||
| @@ -1,3 +1,4 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| from typing import Dict | from typing import Dict | ||||
| from modelscope.metainfo import Models | from modelscope.metainfo import Models | ||||
| @@ -1,3 +1,4 @@ | |||||
| # Copyright 2021-2022 The Alibaba DAMO NLP Team Authors. | |||||
| # Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. | # Copyright (c) 2019, NVIDIA CORPORATION. All rights reserved. | ||||
| # | # | ||||
| # Licensed under the Apache License, Version 2.0 (the "License"); | # Licensed under the Apache License, Version 2.0 (the "License"); | ||||
| @@ -1,13 +1,10 @@ | |||||
| from typing import Dict | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| import torch | import torch | ||||
| import torch.nn.functional as F | |||||
| from torch import nn | from torch import nn | ||||
| from modelscope.metainfo import Heads | from modelscope.metainfo import Heads | ||||
| from modelscope.models.base import TorchHead | from modelscope.models.base import TorchHead | ||||
| from modelscope.models.builder import HEADS | from modelscope.models.builder import HEADS | ||||
| from modelscope.outputs import OutputKeys | |||||
| from modelscope.utils.constant import Tasks | from modelscope.utils.constant import Tasks | ||||
| @@ -1,3 +1,4 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| from typing import Dict | from typing import Dict | ||||
| import torch | import torch | ||||
| @@ -1,3 +1,4 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| from typing import Dict | from typing import Dict | ||||
| import torch | import torch | ||||
| @@ -1,3 +1,4 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| from typing import Dict | from typing import Dict | ||||
| import torch | import torch | ||||
| @@ -1,6 +1,5 @@ | |||||
| from typing import Any, Dict, Optional, Union | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| import numpy as np | |||||
| from transformers import BertForMaskedLM as BertForMaskedLMTransformer | from transformers import BertForMaskedLM as BertForMaskedLMTransformer | ||||
| from modelscope.metainfo import Models | from modelscope.metainfo import Models | ||||
| @@ -1,3 +1,7 @@ | |||||
| # Copyright 2021-2022 The Alibaba DAMO NLP Team Authors. All rights reserved. | |||||
| # The CRF implementation borrows mostly from AllenNLP CRF module (https://github.com/allenai/allennlp) | |||||
| # and pytorch-crf (https://github.com/kmkurn/pytorch-crf) with some modifications. | |||||
| import os | import os | ||||
| from typing import Any, Dict, List, Optional | from typing import Any, Dict, List, Optional | ||||
| @@ -208,8 +212,6 @@ class CRF(nn.Module): | |||||
| Learning*. Morgan Kaufmann. pp. 282–289. | Learning*. Morgan Kaufmann. pp. 282–289. | ||||
| .. _Viterbi algorithm: https://en.wikipedia.org/wiki/Viterbi_algorithm | .. _Viterbi algorithm: https://en.wikipedia.org/wiki/Viterbi_algorithm | ||||
| The implementation borrows mostly from AllenNLP CRF module (https://github.com/allenai/allennlp) | |||||
| and pytorch-crf (https://github.com/kmkurn/pytorch-crf) with some modifications. | |||||
| """ | """ | ||||
| def __init__(self, num_tags: int, batch_first: bool = False) -> None: | def __init__(self, num_tags: int, batch_first: bool = False) -> None: | ||||
| @@ -1,3 +1,19 @@ | |||||
| # Copyright 2021-2022 The Alibaba DAMO NLP Team Authors. | |||||
| # Copyright 2018 The Google AI Language Team Authors and The HugginFace Inc. team. | |||||
| # Copyright (c) 2019, NVIDIA CORPORATION. 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 applicable law or agreed to in writing, software | |||||
| # distributed under the License is distributed on an "AS IS" BASIS, | |||||
| # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |||||
| # See the License for the specific language governing permissions and | |||||
| # limitations under the License. | |||||
| import codecs | import codecs | ||||
| import copy | import copy | ||||
| import math | import math | ||||
| @@ -1,3 +1,4 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| from typing import Dict, List | from typing import Dict, List | ||||
| from modelscope.metainfo import Models | from modelscope.metainfo import Models | ||||
| @@ -1,3 +1,5 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| from typing import Any, Dict | from typing import Any, Dict | ||||
| import numpy as np | import numpy as np | ||||
| @@ -1,7 +1,7 @@ | |||||
| import os | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| from typing import Any, Dict | from typing import Any, Dict | ||||
| import json | |||||
| import numpy as np | import numpy as np | ||||
| from modelscope.metainfo import Models | from modelscope.metainfo import Models | ||||
| @@ -1,3 +1,5 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| from abc import abstractmethod | from abc import abstractmethod | ||||
| from torch import nn | from torch import nn | ||||
| @@ -1,7 +1,7 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| from typing import Any, Dict | from typing import Any, Dict | ||||
| import numpy as np | import numpy as np | ||||
| import torch | |||||
| from modelscope.metainfo import TaskModels | from modelscope.metainfo import TaskModels | ||||
| from modelscope.models.builder import MODELS | from modelscope.models.builder import MODELS | ||||
| @@ -9,9 +9,6 @@ from modelscope.models.nlp.task_models.task_model import \ | |||||
| SingleBackboneTaskModelBase | SingleBackboneTaskModelBase | ||||
| from modelscope.outputs import OutputKeys | from modelscope.outputs import OutputKeys | ||||
| from modelscope.utils.constant import Tasks | from modelscope.utils.constant import Tasks | ||||
| from modelscope.utils.hub import parse_label_mapping | |||||
| from modelscope.utils.tensor_utils import (torch_nested_detach, | |||||
| torch_nested_numpify) | |||||
| __all__ = ['InformationExtractionModel'] | __all__ = ['InformationExtractionModel'] | ||||
| @@ -1,3 +1,4 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| import os | import os | ||||
| from typing import Any, Dict | from typing import Any, Dict | ||||
| @@ -1,3 +1,4 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| import os.path | import os.path | ||||
| import re | import re | ||||
| from abc import ABC | from abc import ABC | ||||
| @@ -1,3 +1,4 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| from typing import Any, Dict | from typing import Any, Dict | ||||
| import numpy as np | import numpy as np | ||||
| @@ -1,3 +1,5 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| from abc import abstractmethod | from abc import abstractmethod | ||||
| from typing import Dict | from typing import Dict | ||||
| @@ -1,3 +1,5 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| from typing import Any, Dict, Union | from typing import Any, Dict, Union | ||||
| from modelscope.metainfo import Pipelines | from modelscope.metainfo import Pipelines | ||||
| @@ -1,3 +1,5 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| from typing import Any, Dict | from typing import Any, Dict | ||||
| import torch | import torch | ||||
| @@ -1,3 +1,5 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| from typing import Any, Dict, Union | from typing import Any, Dict, Union | ||||
| import torch | import torch | ||||
| @@ -1,3 +1,5 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| import os | import os | ||||
| from typing import Any, Dict, Optional, Union | from typing import Any, Dict, Optional, Union | ||||
| @@ -1,11 +1,12 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| from typing import Any, Dict, Optional, Union | from typing import Any, Dict, Optional, Union | ||||
| import torch | import torch | ||||
| from modelscope.metainfo import Pipelines | from modelscope.metainfo import Pipelines | ||||
| from modelscope.models import Model | from modelscope.models import Model | ||||
| from modelscope.outputs import OutputKeys | |||||
| from modelscope.pipelines.base import Pipeline, Tensor | |||||
| from modelscope.pipelines.base import Pipeline | |||||
| from modelscope.pipelines.builder import PIPELINES | from modelscope.pipelines.builder import PIPELINES | ||||
| from modelscope.preprocessors import (Preprocessor, | from modelscope.preprocessors import (Preprocessor, | ||||
| RelationExtractionPreprocessor) | RelationExtractionPreprocessor) | ||||
| @@ -1,3 +1,5 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| from typing import Any, Dict, Optional, Union | from typing import Any, Dict, Optional, Union | ||||
| import torch | import torch | ||||
| @@ -1,3 +1,5 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| from typing import Union | from typing import Union | ||||
| from modelscope.models.base import Model | from modelscope.models.base import Model | ||||
| @@ -1,3 +1,5 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| from typing import Any, Dict, Optional, Union | from typing import Any, Dict, Optional, Union | ||||
| import torch | import torch | ||||
| @@ -1,3 +1,5 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| from typing import Any, Dict, Optional, Union | from typing import Any, Dict, Optional, Union | ||||
| import torch | import torch | ||||
| @@ -1,3 +1,5 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| from typing import Any, Dict, Union | from typing import Any, Dict, Union | ||||
| import numpy as np | import numpy as np | ||||
| @@ -1,3 +1,5 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| from typing import Union | from typing import Union | ||||
| from ...metainfo import Pipelines | from ...metainfo import Pipelines | ||||
| @@ -1,3 +1,5 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| from typing import Any, Dict, Optional, Union | from typing import Any, Dict, Optional, Union | ||||
| import torch | import torch | ||||
| @@ -1,3 +1,5 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| from typing import Any, Dict, Optional, Union | from typing import Any, Dict, Optional, Union | ||||
| import torch | import torch | ||||
| @@ -1,3 +1,5 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| from typing import Any, Dict, Optional, Union | from typing import Any, Dict, Optional, Union | ||||
| import torch | import torch | ||||
| @@ -1,3 +1,5 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| import os.path as osp | import os.path as osp | ||||
| from typing import Any, Dict | from typing import Any, Dict | ||||
| @@ -1,3 +1,5 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| from typing import Any, Dict, Optional, Union | from typing import Any, Dict, Optional, Union | ||||
| import torch | import torch | ||||
| @@ -1,3 +1,5 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| from typing import Any, Dict, Union | from typing import Any, Dict, Union | ||||
| import torch | import torch | ||||
| @@ -24,7 +24,8 @@ if TYPE_CHECKING: | |||||
| TextErrorCorrectionPreprocessor, FaqQuestionAnsweringPreprocessor, | TextErrorCorrectionPreprocessor, FaqQuestionAnsweringPreprocessor, | ||||
| SequenceLabelingPreprocessor, RelationExtractionPreprocessor, | SequenceLabelingPreprocessor, RelationExtractionPreprocessor, | ||||
| DocumentSegmentationPreprocessor, FillMaskPoNetPreprocessor, | DocumentSegmentationPreprocessor, FillMaskPoNetPreprocessor, | ||||
| PassageRankingPreprocessor, Text2TextGenerationPreprocessor, | |||||
| PassageRankingPreprocessor, SentenceEmbeddingPreprocessor, | |||||
| Text2TextGenerationPreprocessor, | |||||
| WordSegmentationBlankSetToLabelPreprocessor) | WordSegmentationBlankSetToLabelPreprocessor) | ||||
| from .space import (DialogIntentPredictionPreprocessor, | from .space import (DialogIntentPredictionPreprocessor, | ||||
| DialogModelingPreprocessor, | DialogModelingPreprocessor, | ||||
| @@ -15,6 +15,7 @@ if TYPE_CHECKING: | |||||
| FaqQuestionAnsweringPreprocessor, SequenceLabelingPreprocessor, | FaqQuestionAnsweringPreprocessor, SequenceLabelingPreprocessor, | ||||
| RelationExtractionPreprocessor, DocumentSegmentationPreprocessor, | RelationExtractionPreprocessor, DocumentSegmentationPreprocessor, | ||||
| FillMaskPoNetPreprocessor, PassageRankingPreprocessor, | FillMaskPoNetPreprocessor, PassageRankingPreprocessor, | ||||
| SentenceEmbeddingPreprocessor, | |||||
| WordSegmentationBlankSetToLabelPreprocessor) | WordSegmentationBlankSetToLabelPreprocessor) | ||||
| else: | else: | ||||
| @@ -23,16 +23,24 @@ from modelscope.utils.type_assert import type_assert | |||||
| logger = get_logger() | logger = get_logger() | ||||
| __all__ = [ | __all__ = [ | ||||
| 'Tokenize', 'SequenceClassificationPreprocessor', | |||||
| 'TextGenerationPreprocessor', 'TokenClassificationPreprocessor', | |||||
| 'Tokenize', | |||||
| 'SequenceClassificationPreprocessor', | |||||
| 'TextGenerationPreprocessor', | |||||
| 'TokenClassificationPreprocessor', | |||||
| 'PairSentenceClassificationPreprocessor', | 'PairSentenceClassificationPreprocessor', | ||||
| 'Text2TextGenerationPreprocessor', | 'Text2TextGenerationPreprocessor', | ||||
| 'SingleSentenceClassificationPreprocessor', 'FillMaskPreprocessor', | |||||
| 'ZeroShotClassificationPreprocessor', 'NERPreprocessor', | |||||
| 'SentenceEmbeddingPreprocessor', 'PassageRankingPreprocessor', | |||||
| 'FaqQuestionAnsweringPreprocessor', 'SequenceLabelingPreprocessor', | |||||
| 'RelationExtractionPreprocessor', 'DocumentSegmentationPreprocessor', | |||||
| 'FillMaskPoNetPreprocessor' | |||||
| 'SingleSentenceClassificationPreprocessor', | |||||
| 'FillMaskPreprocessor', | |||||
| 'ZeroShotClassificationPreprocessor', | |||||
| 'NERPreprocessor', | |||||
| 'SentenceEmbeddingPreprocessor', | |||||
| 'PassageRankingPreprocessor', | |||||
| 'FaqQuestionAnsweringPreprocessor', | |||||
| 'SequenceLabelingPreprocessor', | |||||
| 'RelationExtractionPreprocessor', | |||||
| 'DocumentSegmentationPreprocessor', | |||||
| 'FillMaskPoNetPreprocessor', | |||||
| 'WordSegmentationBlankSetToLabelPreprocessor', | |||||
| ] | ] | ||||
| @@ -1,3 +1,5 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| import os.path as osp | import os.path as osp | ||||
| from typing import Dict, Optional | from typing import Dict, Optional | ||||
| @@ -1,3 +1,5 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| import time | import time | ||||
| from dataclasses import dataclass | from dataclasses import dataclass | ||||
| from typing import Any, Callable, Dict, List, Optional, Tuple, Union | from typing import Any, Callable, Dict, List, Optional, Tuple, Union | ||||
| @@ -1,3 +1,5 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| import time | import time | ||||
| from typing import Dict, Optional, Tuple, Union | from typing import Dict, Optional, Tuple, Union | ||||
| @@ -1,3 +1,5 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| import os | import os | ||||
| import time | import time | ||||
| from typing import Callable, Dict, Optional, Tuple, Union | from typing import Callable, Dict, Optional, Tuple, Union | ||||
| @@ -1,3 +1,5 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| import os | import os | ||||
| import time | import time | ||||
| from typing import Callable, Dict, Optional, Tuple, Union | from typing import Callable, Dict, Optional, Tuple, Union | ||||
| @@ -1,6 +1,4 @@ | |||||
| """ | |||||
| MetricsTracker class | |||||
| """ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| import math | import math | ||||
| from collections import defaultdict | from collections import defaultdict | ||||
| @@ -1,3 +1,5 @@ | |||||
| # Copyright (c) Alibaba, Inc. and its affiliates. | |||||
| import os | import os | ||||
| from typing import Callable, Optional, Tuple, Union | from typing import Callable, Optional, Tuple, Union | ||||