repo stringlengths 1 99 | file stringlengths 13 215 | code stringlengths 12 59.2M | file_length int64 12 59.2M | avg_line_length float64 3.82 1.48M | max_line_length int64 12 2.51M | extension_type stringclasses 1
value |
|---|---|---|---|---|---|---|
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/transformers/modeling_beam_search.py | # coding=utf-8
# Copyright (c) 2019 Yang Liu
# 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, publi... | 10,385 | 37.183824 | 100 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/transformers/file_utils.py | """
Utilities for working with the local dataset cache.
This file is adapted from the AllenNLP library at https://github.com/allenai/allennlp
Copyright by the AllenNLP authors.
"""
import fnmatch
import json
import logging
import os
import re
import shutil
import sys
import tarfile
import tempfile
from collections imp... | 36,425 | 35.244776 | 150 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/transformers/modeling_tf_ctrl.py | # coding=utf-8
# Copyright 2018 Salesforce and HuggingFace Inc. team.
# Copyright (c) 2018, 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
#
# h... | 25,751 | 44.822064 | 169 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/transformers/activations.py | import math
import torch
import torch.nn.functional as F
def swish(x):
return x * torch.sigmoid(x)
def _gelu_python(x):
""" Original Implementation of the gelu activation function in Google Bert repo when initially created.
For information: OpenAI GPT's gelu is slightly different (and gives slightl... | 1,381 | 27.791667 | 115 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/transformers/__init__.py | # flake8: noqa
# There's no way to ignore "F401 '...' imported but unused" warnings in this
# module, but to preserve other warnings. So, don't check this module at all.
__version__ = "2.8.0"
# Work around to update TensorFlow's absl.logging threshold which alters the
# default Python logging output behavior when pre... | 15,999 | 31.258065 | 113 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/transformers/modeling_tf_bert.py | # coding=utf-8
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, 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 cop... | 56,324 | 47.223459 | 181 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/transformers/convert_bert_original_tf_checkpoint_to_pytorch.py | # coding=utf-8
# Copyright 2018 The HuggingFace Inc. team.
#
# 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... | 2,139 | 33.516129 | 117 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/transformers/modeling_tf_distilbert.py | # coding=utf-8
# Copyright 2019-present, the HuggingFace Inc. team, The Google AI Language Team and Facebook, Inc.
#
# 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.or... | 39,379 | 45.93683 | 169 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/transformers/convert_bert_pytorch_checkpoint_to_original_tf.py | # coding=utf-8
# Copyright 2018 The HuggingFace Inc. team.
#
# 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... | 4,115 | 35.424779 | 118 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/transformers/modeling_transfo_xl.py | # coding=utf-8
# Copyright 2018 Google AI, Google Brain and Carnegie Mellon University Authors and the HuggingFace Inc. team.
# Copyright (c) 2018, 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 Lice... | 39,986 | 41.858521 | 151 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/transformers/convert_xlnet_original_tf_checkpoint_to_pytorch.py | # coding=utf-8
# Copyright 2018 The HuggingFace Inc. team.
#
# 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... | 3,685 | 31.052174 | 117 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/transformers/modeling_albert.py | # coding=utf-8
# Copyright 2018 Google AI, Google Brain and the HuggingFace Inc. team.
#
# 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
#
# U... | 45,507 | 44.690763 | 148 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/transformers/modeling_xlnet.py | # coding=utf-8
# Copyright 2018 Google AI, Google Brain and Carnegie Mellon University Authors and the HuggingFace Inc. team.
# Copyright (c) 2018, 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 Lice... | 79,269 | 45.988737 | 304 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/transformers/modeling_tf_camembert.py | # coding=utf-8
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, 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 cop... | 4,799 | 39.336134 | 127 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/transformers/modeling_xlm.py | # coding=utf-8
# Copyright 2019-present, Facebook, Inc and the HuggingFace Inc. team.
#
# 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
#
# Un... | 52,669 | 45.282953 | 197 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/transformers/modeling_tf_utils.py | # coding=utf-8
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, 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 cop... | 84,031 | 48.752516 | 472 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/transformers/modeling_ctrl.py | # coding=utf-8
# Copyright 2018 Salesforce and HuggingFace Inc. team.
# Copyright (c) 2018, 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
#
# h... | 24,739 | 44.145985 | 177 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/transformers/tokenization_transfo_xl.py | # coding=utf-8
# Copyright 2018 Google AI, Google Brain and Carnegie Mellon University Authors and the HuggingFace Inc. team.
# Copyright (c) 2018, 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 Lice... | 28,550 | 36.175781 | 204 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/transformers/modeling_transfo_xl_utilities.py | # coding=utf-8
# Copyright 2018 Google AI, Google Brain and Carnegie Mellon University Authors and the HuggingFace Inc. team.
# Copyright (c) 2018, 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 Lice... | 10,418 | 41.70082 | 132 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/transformers/convert_pytorch_checkpoint_to_tf2.py | # coding=utf-8
# Copyright 2018 The HuggingFace Inc. team.
#
# 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... | 18,333 | 33.397749 | 126 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/transformers/modeling_roberta.py | # coding=utf-8
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, 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 cop... | 32,164 | 45.081662 | 149 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/transformers/tokenization_utils.py | # coding=utf-8
# Copyright 2018 The Open AI Team Authors and The HuggingFace Inc. team.
#
# 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
#
# ... | 99,451 | 49.766718 | 372 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/transformers/commands/convert.py | from argparse import ArgumentParser, Namespace
from logging import getLogger
from transformers.commands import BaseTransformersCLICommand
def convert_command_factory(args: Namespace):
"""
Factory function used to convert a model TF 1.0 checkpoint in a PyTorch checkpoint.
:return: ServeCommand
"""
... | 6,406 | 43.186207 | 117 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/transformers/commands/train.py | import os
from argparse import ArgumentParser, Namespace
from logging import getLogger
from transformers import SingleSentenceClassificationProcessor as Processor
from transformers import TextClassificationPipeline, is_tf_available, is_torch_available
from transformers.commands import BaseTransformersCLICommand
if n... | 5,830 | 39.213793 | 117 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/transformers/commands/env.py | import platform
from argparse import ArgumentParser
from transformers import __version__ as version
from transformers import is_tf_available, is_torch_available
from transformers.commands import BaseTransformersCLICommand
def info_command_factory(_):
return EnvironmentCommand()
class EnvironmentCommand(BaseTra... | 2,027 | 33.372881 | 105 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/transformers/data/processors/squad.py | import json
import logging
import os
from functools import partial
from multiprocessing import Pool, cpu_count
import numpy as np
from tqdm import tqdm
from ...file_utils import is_tf_available, is_torch_available
from ...tokenization_bert import whitespace_tokenize
from .utils import DataProcessor
if is_torch_avai... | 28,192 | 38.211405 | 125 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/transformers/data/processors/utils.py | # coding=utf-8
# Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team.
# Copyright (c) 2018, 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 cop... | 13,817 | 38.593123 | 119 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/SentenceTransformer.py | import json
import logging
import os
import shutil
from collections import OrderedDict
from typing import List, Dict, Tuple, Iterable, Type, Union, Callable
from zipfile import ZipFile
import requests
import numpy as np
import transformers
import torch
from numpy import ndarray
from torch import nn, Tensor, device
from... | 31,733 | 43.632911 | 280 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/util.py | import requests
from torch import Tensor, device
from typing import Tuple, List
from tqdm import tqdm
import sys
import importlib
import os
import torch
import numpy as np
import queue
import logging
def pytorch_cos_sim(a: Tensor, b: Tensor):
"""
Computes the cosine similarity cos_sim(a[i], b[j]) for all i and... | 10,912 | 41.964567 | 165 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/evaluation/BinaryClassificationEvaluator.py | from . import SentenceEvaluator, SimilarityFunction
import torch
from torch.utils.data import DataLoader
import logging
from tqdm import tqdm
from sentence_transformers.util import batch_to_device
import os
import csv
from sklearn.metrics.pairwise import paired_cosine_distances, paired_euclidean_distances, paired_manha... | 8,128 | 42.010582 | 187 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/evaluation/EmbeddingSimilarityEvaluator.py | from . import SentenceEvaluator, SimilarityFunction
import torch
import logging
import os
import csv
from sklearn.metrics.pairwise import paired_cosine_distances, paired_euclidean_distances, paired_manhattan_distances
from scipy.stats import pearsonr, spearmanr
import numpy as np
from typing import List
from ..readers ... | 6,243 | 46.30303 | 205 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/evaluation/InformationRetrievalEvaluator.py | from . import SentenceEvaluator, SimilarityFunction
import torch
from torch.utils.data import DataLoader
import logging
from tqdm import tqdm
from sentence_transformers.util import batch_to_device, pytorch_cos_sim
import os
import csv
import numpy as np
from typing import List, Tuple, Dict, Set
from collections import ... | 10,636 | 36.586572 | 157 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/evaluation/TranslationEvaluator.py | from . import SentenceEvaluator
import logging
from ..util import pytorch_cos_sim
import os
import csv
import numpy as np
import scipy.spatial
from typing import List
import torch
class TranslationEvaluator(SentenceEvaluator):
"""
Given two sets of sentences in different languages, e.g. (en_1, en_2, en_3...) a... | 4,278 | 39.367925 | 188 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/evaluation/MSEEvaluatorFromDataFrame.py | from sentence_transformers.evaluation import SentenceEvaluator
from sentence_transformers.util import batch_to_device
from sentence_transformers import SentenceTransformer
from typing import List, Tuple, Dict
import torch
import numpy as np
import logging
import os
import csv
class MSEEvaluatorFromDataFrame(SentenceE... | 3,814 | 42.850575 | 162 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/evaluation/LabelAccuracyEvaluator.py | from . import SentenceEvaluator
import torch
from torch.utils.data import DataLoader
import logging
from tqdm import tqdm
from ..util import batch_to_device
import os
import csv
class LabelAccuracyEvaluator(SentenceEvaluator):
"""
Evaluate a model based on its accuracy on a labeled dataset
This requires a... | 2,641 | 34.226667 | 98 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/evaluation/TripletEvaluator.py | from . import SentenceEvaluator, SimilarityFunction
import torch
from torch.utils.data import DataLoader
import logging
from tqdm import tqdm
from ..util import batch_to_device
import os
import csv
from sklearn.metrics.pairwise import paired_cosine_distances, paired_euclidean_distances, paired_manhattan_distances
from ... | 6,057 | 44.893939 | 209 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/models/Transformer.py | from torch import nn
from transformers import AutoModel, AutoTokenizer, AutoConfig, BertModel, BertConfig
import json
from typing import List, Dict, Optional
import os
import gluonnlp as nlp
from kobert.utils import get_tokenizer
from kobert.pytorch_kobert import get_pytorch_kobert_model
import torch
class Transformer... | 6,187 | 42.272727 | 168 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/models/WeightedLayerPooling.py | import torch
from torch import Tensor
from torch import nn
from typing import Union, Tuple, List, Iterable, Dict
import os
import json
import numpy as np
import torch.nn.functional as F
from sklearn.metrics.pairwise import cosine_similarity
from sklearn.preprocessing import normalize
class WeightedLayerPooling(nn.Mod... | 2,396 | 40.327586 | 165 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/models/CNN.py | import torch
from torch import nn, Tensor
from typing import Union, Tuple, List, Iterable, Dict
import logging
import gzip
from tqdm import tqdm
import numpy as np
import os
import json
from ..util import import_from_string, fullname, http_get
from .tokenizer import WordTokenizer, WhitespaceTokenizer
class CNN(nn.Mod... | 2,462 | 34.695652 | 119 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/models/WordEmbeddings.py | import torch
from torch import nn, Tensor
from typing import Union, Tuple, List, Iterable, Dict
import logging
import gzip
from tqdm import tqdm
import numpy as np
import os
import json
from ..util import import_from_string, fullname, http_get
from .tokenizer import WordTokenizer, WhitespaceTokenizer
class WordEmbedd... | 5,784 | 43.844961 | 171 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/models/XLMRoBERTa.py | from torch import Tensor
from torch import nn
from transformers import XLMRobertaModel, XLMRobertaTokenizer
import json
from typing import Union, Tuple, List, Dict, Optional
import os
import numpy as np
import logging
class XLMRoBERTa(nn.Module):
"""DEPRECATED: Please use models.Transformer instead.
RoBERTa m... | 3,655 | 39.175824 | 167 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/models/T5.py | from torch import nn
from transformers import T5Model, T5Tokenizer
import json
from typing import List, Dict, Optional
import os
import numpy as np
import logging
class T5(nn.Module):
"""DEPRECATED: Please use models.Transformer instead.
T5 model to generate token embeddings.
Each token is mapped to an o... | 3,402 | 37.235955 | 206 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/models/RoBERTa.py | from torch import Tensor
from torch import nn
from transformers import RobertaModel, RobertaTokenizer
import json
from typing import Union, Tuple, List, Dict, Optional
import os
import numpy as np
import logging
class RoBERTa(nn.Module):
"""DEPRECATED: Please use models.Transformer instead.
RoBERTa model to g... | 3,445 | 37.719101 | 167 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/models/CamemBERT.py | from torch import Tensor
from torch import nn
from transformers import CamembertModel, CamembertTokenizer
import json
from typing import Union, Tuple, List, Dict, Optional
import os
import numpy as np
import logging
class CamemBERT(nn.Module):
"""DEPRECATED: Please use models.Transformer instead.
CamemBERT m... | 3,584 | 38.395604 | 167 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/models/BERT.py | from torch import nn
from transformers import BertModel, BertTokenizer
import json
from typing import List, Dict, Optional
import os
import numpy as np
import logging
class BERT(nn.Module):
"""DEPRECATED: Please use models.Transformer instead.
BERT model to generate token embeddings.
Each token is mapped... | 3,361 | 36.355556 | 167 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/models/XLNet.py | from torch import Tensor
from torch import nn
from transformers import XLNetModel, XLNetTokenizer
import json
from typing import Union, Tuple, List, Dict, Optional
import os
import numpy as np
class XLNet(nn.Module):
"""DEPRECATED: Please use models.Transformer instead.
XLNet model to generate token embedding... | 3,474 | 39.406977 | 167 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/models/WordWeights.py | import torch
from torch import Tensor
from torch import nn
from typing import Union, Tuple, List, Iterable, Dict
import os
import json
import logging
class WordWeights(nn.Module):
"""This model can weight word embeddings, for example, with idf-values."""
def __init__(self, vocab: List[str], word_weights: Dict... | 3,017 | 39.783784 | 196 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/models/WKPooling.py | import torch
from torch import Tensor
from torch import nn
from typing import Union, Tuple, List, Iterable, Dict
import os
import json
import numpy as np
class WKPooling(nn.Module):
"""
Pooling based on the paper: "SBERT-WK: A Sentence Embedding Method ByDissecting BERT-based Word Models"
https://arxiv.or... | 5,864 | 40.595745 | 130 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/models/ALBERT.py | from torch import Tensor
from torch import nn
from transformers import AlbertModel, AlbertTokenizer
import json
from typing import Union, Tuple, List, Dict, Optional
import os
import numpy as np
import logging
class ALBERT(nn.Module):
"""DEPRECATED: Please use models.Transformer instead.
ALBERT model to gener... | 3,482 | 37.7 | 167 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/models/Dense.py | import torch
from torch import Tensor
from torch import nn
from torch import functional as F
from typing import Union, Tuple, List, Iterable, Dict
import os
import json
from ..util import fullname, import_from_string
class Dense(nn.Module):
"""Feed-forward function with activiation function.
This layer take... | 2,116 | 40.509804 | 175 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/models/BoW.py | import torch
from torch import Tensor
from torch import nn
from typing import Union, Tuple, List, Iterable, Dict
import os
import json
import logging
import numpy as np
from .tokenizer import WhitespaceTokenizer
class BoW(nn.Module):
"""Implements a Bag-of-Words (BoW) model to derive sentence embeddings.
A we... | 2,940 | 37.194805 | 150 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/models/LASER.py | import torch
from torch import nn
from typing import List
import os
import json
class LASER(nn.Module):
"""
Implementation of LASER
Paper: Mikel Artetxe and Holger Schwenk, Massively Multilingual Sentence Embeddings for Zero-Shot Cross-Lingual Transfer and Beyond arXiv, Dec 26 2018.
Code: https://git... | 8,454 | 35.287554 | 155 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/models/Pooling.py | import torch
from torch import Tensor
from torch import nn
from typing import Union, Tuple, List, Iterable, Dict
import os
import json
class Pooling(nn.Module):
"""Performs pooling (max or mean) on the token embeddings.
Using pooling, it generates from a variable sized sentence a fixed sized sentence embeddi... | 4,313 | 45.891304 | 198 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/models/LSTM.py | import torch
from torch import nn
from typing import List
import os
import json
class LSTM(nn.Module):
"""
Bidirectional LSTM running over word embeddings.
"""
def __init__(self, word_embedding_dimension: int, hidden_dim: int, num_layers: int = 1, dropout: float = 0, bidirectional: bool = True):
... | 2,323 | 35.888889 | 155 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/models/DistilBERT.py | from torch import Tensor
from torch import nn
from transformers import DistilBertModel, DistilBertTokenizer
import json
from typing import Union, Tuple, List, Dict, Optional
import os
import numpy as np
import logging
class DistilBERT(nn.Module):
"""DEPRECATED: Please use models.Transformer instead.
DistilBER... | 3,511 | 38.022222 | 167 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/datasets/SentenceLabelDataset.py | from torch.utils.data import Dataset
from typing import List
import bisect
import torch
import logging
import numpy as np
from tqdm import tqdm
from .. import SentenceTransformer
from ..readers.InputExample import InputExample
from multiprocessing import Pool, cpu_count
import multiprocessing
class SentenceLabelDatase... | 8,156 | 43.091892 | 161 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/datasets/SentencesDataset.py | from torch.utils.data import Dataset
from typing import List
import torch
from .. import SentenceTransformer
from ..readers.InputExample import InputExample
class SentencesDataset(Dataset):
"""
Dataset for smart batching, that is each batch is only padded to its longest sequence instead of padding all
sequ... | 1,443 | 34.219512 | 115 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/datasets/EncodeDataset.py | from torch.utils.data import Dataset
from typing import List, Union
from .. import SentenceTransformer
class EncodeDataset(Dataset):
def __init__(self,
sentences: Union[List[str], List[int]],
model: SentenceTransformer,
is_tokenized: bool = True):
"""
... | 777 | 28.923077 | 103 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/datasets/ParallelSentencesDataset.py | from torch.utils.data import Dataset
import logging
import gzip
from queue import Queue
from .. import SentenceTransformer
from typing import List
import random
class ParallelSentencesDataset(Dataset):
"""
This dataset reader can be used to read-in parallel sentences, i.e., it reads in a file with tab-seperate... | 7,074 | 43.496855 | 153 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/datasets/sampler/LabelSampler.py | """
This file contains sampler functions, that can be used to sample mini-batches with specific properties.
"""
from torch.utils.data import Sampler
import numpy as np
from ...datasets import SentenceLabelDataset
class LabelSampler(Sampler):
"""
This sampler is used for some specific Triplet Losses like BATCH... | 3,097 | 39.763158 | 121 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/losses/CosineSimilarityLoss.py | import torch
from torch import nn, Tensor
from typing import Iterable, Dict
from ..SentenceTransformer import SentenceTransformer
class CosineSimilarityLoss(nn.Module):
"""
CosineSimilarityLoss expects, that the InputExamples consists of two texts and a float label.
It computes the vectors u = model(inpu... | 2,213 | 50.488372 | 177 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/losses/MSELoss.py | import torch
from torch import nn, Tensor
from typing import Union, Tuple, List, Iterable, Dict
class MSELoss(nn.Module):
"""
Computes the MSE loss between the computed sentence embedding and a target sentence embedding. This loss
is used when extending sentence embeddings to new languages as described in... | 898 | 38.086957 | 118 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/losses/TripletLoss.py | import torch
from torch import nn, Tensor
from typing import Union, Tuple, List, Iterable, Dict
import torch.nn.functional as F
from enum import Enum
from ..SentenceTransformer import SentenceTransformer
class TripletDistanceMetric(Enum):
"""
The metric for the triplet loss
"""
COSINE = lambda x, y: 1 ... | 2,728 | 45.254237 | 164 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/losses/BatchHardSoftMarginTripletLoss.py | import torch
from torch import nn, Tensor
from typing import Union, Tuple, List, Iterable, Dict
from .BatchHardTripletLoss import BatchHardTripletLoss, BatchHardTripletLossDistanceFunction
from sentence_transformers.SentenceTransformer import SentenceTransformer
class BatchHardSoftMarginTripletLoss(BatchHardTripletLos... | 4,988 | 54.433333 | 162 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/losses/BatchHardTripletLoss.py | import torch
from torch import nn, Tensor
from typing import Union, Tuple, List, Iterable, Dict
from sentence_transformers import util
from sentence_transformers.SentenceTransformer import SentenceTransformer
class BatchHardTripletLossDistanceFunction:
"""
This class defines distance functions, that can be us... | 9,443 | 45.522167 | 162 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/losses/MultipleNegativesRankingLoss.py | import torch
from torch import nn, Tensor
from typing import Iterable, Dict
from ..SentenceTransformer import SentenceTransformer
class MultipleNegativesRankingLoss(nn.Module):
"""
This loss expects as input a batch consisting of sentence pairs (a_1, b_1), (a_2, b_2)..., (a_n, b_n)
where we assume ... | 3,100 | 44.602941 | 138 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/losses/BatchAllTripletLoss.py | import torch
from torch import nn, Tensor
from typing import Union, Tuple, List, Iterable, Dict
from .BatchHardTripletLoss import BatchHardTripletLoss, BatchHardTripletLossDistanceFunction
from sentence_transformers.SentenceTransformer import SentenceTransformer
class BatchAllTripletLoss(nn.Module):
"""
Batch... | 4,745 | 51.153846 | 162 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/losses/BatchSemiHardTripletLoss.py | import torch
from torch import nn, Tensor
from typing import Union, Tuple, List, Iterable, Dict
from .BatchHardTripletLoss import BatchHardTripletLoss, BatchHardTripletLossDistanceFunction
from sentence_transformers.SentenceTransformer import SentenceTransformer
class BatchSemiHardTripletLoss(nn.Module):
"""
... | 5,631 | 48.840708 | 162 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/losses/OnlineContrastiveLoss.py | from typing import Iterable, Dict
import torch.nn.functional as F
from torch import nn, Tensor
from .ContrastiveLoss import SiameseDistanceMetric
from sentence_transformers.SentenceTransformer import SentenceTransformer
class OnlineContrastiveLoss(nn.Module):
"""
Online Contrastive loss. Similar to Constrativ... | 2,732 | 51.557692 | 162 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/losses/ContrastiveLoss.py | from enum import Enum
from typing import Iterable, Dict
import torch.nn.functional as F
from torch import nn, Tensor
from sentence_transformers.SentenceTransformer import SentenceTransformer
class SiameseDistanceMetric(Enum):
"""
The metric for the contrastive loss
"""
EUCLIDEAN = lambda x, y: F.pai... | 2,794 | 44.080645 | 162 | py |
KoSentenceBERT-SKT | KoSentenceBERT-SKT-main/sentence_transformers/losses/SoftmaxLoss.py | import torch
from torch import nn, Tensor
from typing import Union, Tuple, List, Iterable, Dict
from ..SentenceTransformer import SentenceTransformer
import logging
class SoftmaxLoss(nn.Module):
"""
This loss was used in our SBERT publication (https://arxiv.org/abs/1908.10084) to train the SentenceTransformer
... | 3,637 | 45.050633 | 152 | py |
torch-adaptive-imle | torch-adaptive-imle-main/cli/synth-cli.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import torch as t
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.colors as colors
from torch import Tensor
from imle.ste import ste as my_ste
from imle.imle import imle as my_imle
from imle.aimle import aimle as my_aimle
from imle.target import Tar... | 37,646 | 38.75396 | 119 | py |
torch-adaptive-imle | torch-adaptive-imle-main/cli/gradient-samples-cli.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys
import torch
import numpy as np
from torch import Tensor, nn
from imle.ste import ste as ste
from imle.imle import imle as imle
from imle.aimle import aimle as aimle
from imle.target import BaseTargetDistribution, TargetDistribution, AdaptiveTarget... | 16,797 | 38.995238 | 115 | py |
torch-adaptive-imle | torch-adaptive-imle-main/cli/warcraft-cli.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import sys
import os
from logging import WARNING
import warnings
import numpy as np
import psutil
import ray
import re
import torch
import getpass
from aaai23.maprop.logger import Logger
from aaai23.maprop.utils import set_seed, save_metrics_params, update_params_fro... | 5,638 | 28.52356 | 112 | py |
torch-adaptive-imle | torch-adaptive-imle-main/cli/nri-cli.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
from __future__ import division
from __future__ import print_function
import sys
import json
import itertools
import math
import time
import argparse
import pickle
import os
from functools import partial
import numpy as np
import torch
import torch.nn.functional as F
... | 44,627 | 49.771331 | 169 | py |
torch-adaptive-imle | torch-adaptive-imle-main/cli/l2x-cli.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys
import time
import numpy as np
import argparse
import torch
from torch import optim, Tensor
from torch.utils.data import TensorDataset
from torch.utils.data import DataLoader
from imle.imle import imle
from imle.aimle import aimle
from imle.ste i... | 18,819 | 41.387387 | 124 | py |
torch-adaptive-imle | torch-adaptive-imle-main/cli/expected-sparsity-cli.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
# This is an extended version of gradient-cli.py that supports AIMLE
# Remember to replace gradient-cli.py with this one
import os
import sys
import torch
import numpy as np
from torch import Tensor, nn
from aaai23.synth import distributions, utils, sfe2 as sfe
impor... | 3,417 | 27.247934 | 115 | py |
torch-adaptive-imle | torch-adaptive-imle-main/cli/gradient-sparsity-bias-cli.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
# This is an extended version of gradient-cli.py that supports AIMLE
# Remember to replace gradient-cli.py with this one
import os
import sys
import torch
import numpy as np
from torch import Tensor, nn
import torch.nn.functional as F
from imle.ste import ste as ste
f... | 18,995 | 41.591928 | 130 | py |
torch-adaptive-imle | torch-adaptive-imle-main/cli/gradient-cli.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
# This is an extended version of gradient-cli.py that supports AIMLE
# Remember to replace gradient-cli.py with this one
import os
import sys
import torch
import numpy as np
from torch import Tensor, nn
from imle.ste import ste as ste
from imle.imle import imle as iml... | 14,339 | 40.325648 | 115 | py |
torch-adaptive-imle | torch-adaptive-imle-main/cli/vae-cli.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys
import numpy as np
import torch
import torch.nn.functional as F
from torch import nn, optim, Tensor
from imle.imle import imle
from imle.aimle import aimle
from imle.ste import ste
from imle.target import TargetDistribution, AdaptiveTargetDistribu... | 14,808 | 38.80914 | 119 | py |
torch-adaptive-imle | torch-adaptive-imle-main/aaai23/torch/modules.py | # -*- coding: utf-8 -*-
import torch
from torch import nn, Tensor
from torch.distributions.gamma import Gamma
from torch.distributions import Uniform
import math
from typing import Optional, Tuple, Callable
import logging
logger = logging.getLogger(__name__)
def init(layer: nn.Module):
if isinstance(layer, ... | 12,902 | 34.254098 | 128 | py |
torch-adaptive-imle | torch-adaptive-imle-main/aaai23/torch/utils.py | # -*- coding: utf-8 -*-
import json
import numpy as np
import random
import torch
from torch import nn, Tensor
from torch.distributions.gamma import Gamma
from torch.distributions import Uniform
import math
from aaai23.utils import pad_sequences
from typing import Optional, Tuple, Callable
import logging
logge... | 2,895 | 31.909091 | 112 | py |
torch-adaptive-imle | torch-adaptive-imle-main/aaai23/torch/dvae/modules.py | # -*- coding: utf-8 -*-
import torch
import torch.nn.functional as F
from torch import nn, Tensor
from typing import Callable, Tuple
import logging
logger = logging.getLogger(__name__)
def init(layer: nn.Module):
if isinstance(layer, nn.Conv1d) or isinstance(layer, nn.Linear):
torch.nn.init.xavier_un... | 3,838 | 28.530769 | 88 | py |
torch-adaptive-imle | torch-adaptive-imle-main/aaai23/synth/distributions.py | # -*- coding: utf-8 -*-
import itertools
import numpy as np
import torch
class DiscreteExpFamily:
def __init__(self, m) -> None:
"""
Base class for (constrained) exponential family distributions.
When subclassing, one must at least implement the `states` function.
:param m: dimen... | 5,382 | 31.427711 | 100 | py |
torch-adaptive-imle | torch-adaptive-imle-main/aaai23/synth/sfe.py | # -*- coding: utf-8 -*-
"""Score function estimator"""
import torch
from aaai23.synth.utils import _maybe_ctx_call
def sfe(sampler, loss_f, grad_log_p):
# print(f'sfe.sfe({sampler}, {loss_f}, {grad_log_p})')
return lambda theta: _SFE.apply(theta, sampler, loss_f, grad_log_p)
# noinspection PyMethodOverrid... | 958 | 28.060606 | 91 | py |
torch-adaptive-imle | torch-adaptive-imle-main/aaai23/synth/utils.py | # -*- coding: utf-8 -*-
import inspect
import torch
import numpy as np
def expect_obj(dist, theta, obj):
"""
Computes \mathbb{E}_{z\sim dist(z, theta)} [ obj(z) ] =
= sum_{z in dist.states} dist(z) * obj(z)
:param dist:
:param theta:
:param obj:
:return:
"""
... | 1,384 | 21.33871 | 82 | py |
torch-adaptive-imle | torch-adaptive-imle-main/aaai23/synth/imle.py | # -*- coding: utf-8 -*-
"""Implicit maximum likelihood estimator (I-MLE)"""
import torch
from aaai23.synth.utils import _maybe_ctx_call
def imle_pid(lmd, sampler, use_fw_pass_for_mu_p=True, marginals_approx=None,
normalized=False):
"""
I-MLE ``layer'' with target distribution given by perturba... | 2,351 | 41 | 118 | py |
torch-adaptive-imle | torch-adaptive-imle-main/aaai23/synth/ste.py | # -*- coding: utf-8 -*-
"""Straight through estimator"""
import torch
def ste(sampler):
return lambda theta: _StraightThroughEstimator.apply(theta, sampler)
# noinspection PyMethodOverriding
class _StraightThroughEstimator(torch.autograd.Function):
@staticmethod
def forward(ctx, theta, sampler):
... | 436 | 18.863636 | 72 | py |
torch-adaptive-imle | torch-adaptive-imle-main/aaai23/synth/sfe2.py | # -*- coding: utf-8 -*-
"""Score function estimator"""
import torch
from aaai23.synth.utils import _maybe_ctx_call
def sfe(sampler, loss_f, grad_log_p, nb_samples):
# print(f'sfe2.sfe({sampler}, {loss_f}, {grad_log_p})')
return lambda theta: _SFE.apply(theta, sampler, loss_f, grad_log_p, nb_samples)
# noi... | 1,832 | 33.584906 | 99 | py |
torch-adaptive-imle | torch-adaptive-imle-main/aaai23/maprop/utils.py | # -*- coding: utf-8 -*-
import os
import sys
import pickle
import random
import torch
import csv
import ray
import itertools
from collections import defaultdict, deque
import time
from functools import lru_cache
import ast
import collections
import json
from copy import deepcopy
from warnings import warn
import numpy... | 16,722 | 32.114851 | 120 | py |
torch-adaptive-imle | torch-adaptive-imle-main/aaai23/maprop/perturbations.py | # -*- coding: utf-8 -*-
"""Introduces differentiation via perturbations.
Example of usage:
@perturbed
def sign_or(x, axis=-1):
s = ((torch.sign(x) + 1) / 2.0).type(torch.bool)
result = torch.any(s, dim=-1)
return result.type(torch.float) * 2.0 - 1
Then sign_or is differentiable (unlike what it seem... | 8,022 | 40.569948 | 98 | py |
torch-adaptive-imle | torch-adaptive-imle-main/aaai23/maprop/fenchel_young.py | # -*- coding: utf-8 -*-
"""Implementation of a Fenchel-Young loss using perturbation techniques."""
import torch
import torch.nn as nn
from torch import Tensor
from aaai23.maprop import perturbations
from typing import Callable, Optional
class PerturbedFunc(torch.autograd.Function):
"""Implementation of a Fe... | 3,200 | 38.036585 | 110 | py |
torch-adaptive-imle | torch-adaptive-imle-main/aaai23/maprop/models.py | # -*- coding: utf-8 -*-
from math import sqrt
import torch
import torch.nn as nn
import torch.nn.functional as F
import torchvision
def get_model(model_name, out_features, in_channels, arch_params):
preloaded_models = {"ResNet18": torchvision.models.resnet18}
own_models = {"ConvNet": ConvNet, "MLP": MLP, "... | 4,809 | 37.48 | 120 | py |
torch-adaptive-imle | torch-adaptive-imle-main/aaai23/maprop/decorators.py | # -*- coding: utf-8 -*-
from itertools import chain
import torch
from abc import ABC, abstractmethod
from functools import update_wrapper, partial
class Decorator(ABC):
def __init__(self, f):
self.func = f
update_wrapper(self, f, updated=[]) # updated=[] so that 'self' attributes are not overw... | 1,611 | 25.42623 | 103 | py |
torch-adaptive-imle | torch-adaptive-imle-main/aaai23/maprop/warcraft_shortest_path/trainers.py | # -*- coding: utf-8 -*-
import random
import time
from abc import ABC, abstractmethod
import torch
from aaai23.maprop.blackbox.losses import HammingLoss
from aaai23.maprop.blackbox.dijkstra import ShortestPath
from aaai23.maprop.logger import Logger
from aaai23.maprop.models import get_model
from aaai23.maprop.util... | 10,765 | 37.45 | 176 | py |
torch-adaptive-imle | torch-adaptive-imle-main/aaai23/maprop/warcraft_shortest_path/maprop.py | # -*- coding: utf-8 -*-
import numpy as np
import torch
from torch import Tensor
from aaai23.maprop.blackbox.losses import HammingLoss
from aaai23.maprop.warcraft_shortest_path.trainers import ShortestPathAbstractTrainer
from aaai23.maprop.blackbox.dijkstra import get_solver
from aaai23.maprop.utils import maybe_p... | 6,796 | 38.748538 | 137 | py |
torch-adaptive-imle | torch-adaptive-imle-main/aaai23/maprop/blackbox/losses.py | # -*- coding: utf-8 -*-
import torch
class HammingLoss(torch.nn.Module):
def forward(self, suggested, target):
errors = suggested * (1.0 - target) + (1.0 - suggested) * target
return errors.mean(dim=0).sum()
| 231 | 22.2 | 72 | py |
torch-adaptive-imle | torch-adaptive-imle-main/aaai23/maprop/blackbox/dijkstra.py | # -*- coding: utf-8 -*-
import numpy as np
import heapq
import torch
from functools import partial
from aaai23.maprop.blackbox.utils import get_neighbourhood_func
from collections import namedtuple
from aaai23.maprop.utils import maybe_parallelize
DijkstraOutput = namedtuple("DijkstraOutput", ["shortest_path", "is_un... | 3,187 | 35.643678 | 99 | py |
torch-adaptive-imle | torch-adaptive-imle-main/aaai23/tf/utils.py | # -*- coding: utf-8 -*-
import json
import tensorflow as tf
import numpy as np
from tensorflow.keras.layers import Layer, Conv1D, GlobalMaxPooling1D, Embedding, Dense, Dropout
from tensorflow.keras import backend as K
from tensorflow.keras.preprocessing import sequence
import logging
logger = logging.getLogger(__n... | 11,352 | 33.507599 | 108 | py |
torch-adaptive-imle | torch-adaptive-imle-main/tests/imle/test_imle.py | #!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
import sys
import numpy as np
import torch
from torch import nn, Tensor, Size
from imle.imle import imle
from imle.aimle import aimle
from imle.target import TargetDistribution
from imle.noise import BaseNoiseDistribution
from imle.solvers import select_k, ma... | 10,550 | 36.282686 | 121 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.