repo stringlengths 2 99 | file stringlengths 13 225 | code stringlengths 0 18.3M | file_length int64 0 18.3M | avg_line_length float64 0 1.36M | max_line_length int64 0 4.26M | extension_type stringclasses 1
value |
|---|---|---|---|---|---|---|
lama-cleaner | lama-cleaner-main/lama_cleaner/plugins/segment_anything/modeling/transformer.py | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch import Tensor, nn
import math
from typing import Tuple, Type
from .common import MLPBlock
clas... | 8,396 | 33.842324 | 89 | py |
lama-cleaner | lama-cleaner-main/lama_cleaner/plugins/segment_anything/modeling/common.py | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
import torch.nn as nn
from typing import Type
class MLPBlock(nn.Module):
def __init__(
self,
... | 1,479 | 32.636364 | 136 | py |
lama-cleaner | lama-cleaner-main/lama_cleaner/plugins/segment_anything/modeling/sam.py | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
import torch
from torch import nn
from torch.nn import functional as F
from typing import Any, Dict, List, Tuple
from .i... | 7,225 | 40.291429 | 95 | py |
lama-cleaner | lama-cleaner-main/lama_cleaner/plugins/segment_anything/modeling/__init__.py | # Copyright (c) Meta Platforms, Inc. and affiliates.
# All rights reserved.
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
from .sam import Sam
from .image_encoder import ImageEncoderViT
from .mask_decoder import MaskDecoder
from .prompt_encoder... | 385 | 31.166667 | 61 | py |
lama-cleaner | lama-cleaner-main/lama_cleaner/tests/test_paint_by_example.py | from pathlib import Path
import cv2
import pytest
import torch
from PIL import Image
from lama_cleaner.model_manager import ModelManager
from lama_cleaner.schema import HDStrategy
from lama_cleaner.tests.test_model import get_config, get_data
current_dir = Path(__file__).parent.absolute().resolve()
save_dir = curren... | 3,985 | 36.252336 | 114 | py |
lama-cleaner | lama-cleaner-main/lama_cleaner/tests/test_load_img.py | from pathlib import Path
from lama_cleaner.helper import load_img
current_dir = Path(__file__).parent.absolute().resolve()
png_img_p = current_dir / "image.png"
jpg_img_p = current_dir / "bunny.jpeg"
def test_load_png_image():
with open(png_img_p, "rb") as f:
np_img, alpha_channel = load_img(f.read())
... | 596 | 26.136364 | 56 | py |
lama-cleaner | lama-cleaner-main/lama_cleaner/tests/test_instruct_pix2pix.py | from pathlib import Path
import pytest
import torch
from lama_cleaner.model_manager import ModelManager
from lama_cleaner.tests.test_model import get_config, assert_equal
from lama_cleaner.schema import HDStrategy
current_dir = Path(__file__).parent.absolute().resolve()
save_dir = current_dir / 'result'
save_dir.mkd... | 2,322 | 35.873016 | 119 | py |
lama-cleaner | lama-cleaner-main/lama_cleaner/tests/test_controlnet.py | import os
from lama_cleaner.const import SD_CONTROLNET_CHOICES
os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1"
from pathlib import Path
import pytest
import torch
from lama_cleaner.model_manager import ModelManager
from lama_cleaner.schema import HDStrategy, SDSampler
from lama_cleaner.tests.test_model import get_c... | 6,219 | 30.734694 | 85 | py |
lama-cleaner | lama-cleaner-main/lama_cleaner/tests/test_plugins.py | import hashlib
import os
import time
from lama_cleaner.plugins.anime_seg import AnimeSeg
os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1"
from pathlib import Path
import cv2
import pytest
import torch.cuda
from lama_cleaner.plugins import (
RemoveBG,
RealESRGANUpscaler,
GFPGANPlugin,
RestoreFormerPlu... | 2,965 | 27.519231 | 73 | py |
lama-cleaner | lama-cleaner-main/lama_cleaner/tests/test_model_md5.py | def test_load_model():
from lama_cleaner.plugins import InteractiveSeg
from lama_cleaner.model_manager import ModelManager
interactive_seg_model = InteractiveSeg('vit_l', 'cpu')
models = [
"lama",
"ldm",
"zits",
"mat",
"fcf",
"manga",
]
for m in ... | 1,505 | 29.12 | 77 | py |
lama-cleaner | lama-cleaner-main/lama_cleaner/tests/test_sd_model.py | import os
os.environ["PYTORCH_ENABLE_MPS_FALLBACK"] = "1"
from pathlib import Path
import pytest
import torch
from lama_cleaner.model_manager import ModelManager
from lama_cleaner.schema import HDStrategy, SDSampler
from lama_cleaner.tests.test_model import get_config, assert_equal
current_dir = Path(__file__).pare... | 7,647 | 30.603306 | 99 | py |
lama-cleaner | lama-cleaner-main/lama_cleaner/tests/__init__.py | 0 | 0 | 0 | py | |
lama-cleaner | lama-cleaner-main/lama_cleaner/tests/test_model.py | from pathlib import Path
import cv2
import pytest
import torch
from lama_cleaner.model_manager import ModelManager
from lama_cleaner.schema import Config, HDStrategy, LDMSampler, SDSampler
current_dir = Path(__file__).parent.absolute().resolve()
save_dir = current_dir / "result"
save_dir.mkdir(exist_ok=True, parents... | 5,826 | 28.882051 | 91 | py |
lama-cleaner | lama-cleaner-main/lama_cleaner/tests/test_save_exif.py | import io
from pathlib import Path
from PIL import Image
from lama_cleaner.helper import pil_to_bytes, load_img
current_dir = Path(__file__).parent.absolute().resolve()
def print_exif(exif):
for k, v in exif.items():
print(f"{k}: {v}")
def run_test(img_p: Path):
print(img_p)
ext = img_p.suffi... | 1,128 | 24.659091 | 85 | py |
lama-cleaner | lama-cleaner-main/lama_cleaner/model/base.py | import abc
from typing import Optional
import cv2
import torch
import numpy as np
from loguru import logger
from lama_cleaner.helper import (
boxes_from_mask,
resize_max_size,
pad_img_to_modulo,
switch_mps_device,
)
from lama_cleaner.schema import Config, HDStrategy
class InpaintModel:
name = "b... | 9,600 | 31.110368 | 107 | py |
lama-cleaner | lama-cleaner-main/lama_cleaner/model/opencv2.py | import cv2
from lama_cleaner.model.base import InpaintModel
from lama_cleaner.schema import Config
flag_map = {"INPAINT_NS": cv2.INPAINT_NS, "INPAINT_TELEA": cv2.INPAINT_TELEA}
class OpenCV2(InpaintModel):
name = "cv2"
pad_mod = 1
@staticmethod
def is_downloaded() -> bool:
return True
d... | 716 | 23.724138 | 77 | py |
lama-cleaner | lama-cleaner-main/lama_cleaner/model/lama.py | import os
import cv2
import numpy as np
import torch
from lama_cleaner.helper import (
norm_img,
get_cache_path_by_url,
load_jit_model,
)
from lama_cleaner.model.base import InpaintModel
from lama_cleaner.schema import Config
LAMA_MODEL_URL = os.environ.get(
"LAMA_MODEL_URL",
"https://github.com/... | 1,480 | 27.480769 | 85 | py |
lama-cleaner | lama-cleaner-main/lama_cleaner/model/controlnet.py | import gc
import PIL.Image
import cv2
import numpy as np
import torch
from diffusers import ControlNetModel
from loguru import logger
from lama_cleaner.model.base import DiffusionInpaintModel
from lama_cleaner.model.utils import torch_gc, get_scheduler
from lama_cleaner.schema import Config
class CPUTextEncoderWrap... | 10,883 | 36.531034 | 154 | py |
lama-cleaner | lama-cleaner-main/lama_cleaner/model/utils.py | import math
import random
from typing import Any
import torch
import numpy as np
import collections
from itertools import repeat
from diffusers import (
DDIMScheduler,
PNDMScheduler,
LMSDiscreteScheduler,
EulerDiscreteScheduler,
EulerAncestralDiscreteScheduler,
DPMSolverMultistepScheduler,
... | 33,811 | 34.893843 | 148 | py |
lama-cleaner | lama-cleaner-main/lama_cleaner/model/zits.py | import os
import time
import cv2
import torch
import torch.nn.functional as F
from lama_cleaner.helper import get_cache_path_by_url, load_jit_model
from lama_cleaner.schema import Config
import numpy as np
from lama_cleaner.model.base import InpaintModel
ZITS_INPAINT_MODEL_URL = os.environ.get(
"ZITS_INPAINT_MO... | 15,613 | 33.852679 | 132 | py |
lama-cleaner | lama-cleaner-main/lama_cleaner/model/ddim_sampler.py | import torch
import numpy as np
from tqdm import tqdm
from lama_cleaner.model.utils import make_ddim_timesteps, make_ddim_sampling_parameters, noise_like
from loguru import logger
class DDIMSampler(object):
def __init__(self, model, schedule="linear"):
super().__init__()
self.model = model
... | 6,873 | 34.43299 | 99 | py |
lama-cleaner | lama-cleaner-main/lama_cleaner/model/instruct_pix2pix.py | import PIL.Image
import cv2
import torch
from loguru import logger
from lama_cleaner.model.base import DiffusionInpaintModel
from lama_cleaner.model.utils import set_seed
from lama_cleaner.schema import Config
class InstructPix2Pix(DiffusionInpaintModel):
name = "instruct_pix2pix"
pad_mod = 8
min_size = ... | 3,175 | 36.809524 | 118 | py |
lama-cleaner | lama-cleaner-main/lama_cleaner/model/mat.py | import os
import random
import cv2
import numpy as np
import torch
import torch.nn as nn
import torch.nn.functional as F
import torch.utils.checkpoint as checkpoint
from lama_cleaner.helper import load_model, get_cache_path_by_url, norm_img
from lama_cleaner.model.base import InpaintModel
from lama_cleaner.model.util... | 62,603 | 31.336777 | 110 | py |
lama-cleaner | lama-cleaner-main/lama_cleaner/model/manga.py | import os
import random
import cv2
import numpy as np
import torch
import time
from loguru import logger
from lama_cleaner.helper import get_cache_path_by_url, load_jit_model
from lama_cleaner.model.base import InpaintModel
from lama_cleaner.schema import Config
MANGA_INPAINTOR_MODEL_URL = os.environ.get(
"MANG... | 2,884 | 30.358696 | 84 | py |
lama-cleaner | lama-cleaner-main/lama_cleaner/model/ldm.py | import os
import numpy as np
import torch
from loguru import logger
from lama_cleaner.model.base import InpaintModel
from lama_cleaner.model.ddim_sampler import DDIMSampler
from lama_cleaner.model.plms_sampler import PLMSSampler
from lama_cleaner.schema import Config, LDMSampler
torch.manual_seed(42)
import torch.nn... | 11,275 | 33.169697 | 116 | py |
lama-cleaner | lama-cleaner-main/lama_cleaner/model/__init__.py | 0 | 0 | 0 | py | |
lama-cleaner | lama-cleaner-main/lama_cleaner/model/paint_by_example.py | import PIL
import PIL.Image
import cv2
import torch
from diffusers import DiffusionPipeline
from loguru import logger
from lama_cleaner.model.base import DiffusionInpaintModel
from lama_cleaner.model.utils import set_seed
from lama_cleaner.schema import Config
class PaintByExample(DiffusionInpaintModel):
name = ... | 2,934 | 35.6875 | 88 | py |
lama-cleaner | lama-cleaner-main/lama_cleaner/model/plms_sampler.py | # From: https://github.com/CompVis/latent-diffusion/blob/main/ldm/models/diffusion/plms.py
import torch
import numpy as np
from lama_cleaner.model.utils import make_ddim_timesteps, make_ddim_sampling_parameters, noise_like
from tqdm import tqdm
class PLMSSampler(object):
def __init__(self, model, schedule="linear... | 11,851 | 51.442478 | 131 | py |
lama-cleaner | lama-cleaner-main/lama_cleaner/model/fcf.py | import os
import random
import cv2
import torch
import numpy as np
import torch.fft as fft
from lama_cleaner.schema import Config
from lama_cleaner.helper import (
load_model,
get_cache_path_by_url,
norm_img,
boxes_from_mask,
resize_max_size,
)
from lama_cleaner.model.base import InpaintModel
fro... | 57,098 | 31.929066 | 124 | py |
lama-cleaner | lama-cleaner-main/lama_cleaner/model/sd.py | import gc
import PIL.Image
import cv2
import numpy as np
import torch
from loguru import logger
from lama_cleaner.model.base import DiffusionInpaintModel
from lama_cleaner.model.utils import torch_gc, get_scheduler
from lama_cleaner.schema import Config
class CPUTextEncoderWrapper:
def __init__(self, text_encod... | 6,644 | 33.252577 | 154 | py |
lama-cleaner | lama-cleaner-main/lama_cleaner/model/pipeline/__init__.py | from .pipeline_stable_diffusion_controlnet_inpaint import (
StableDiffusionControlNetInpaintPipeline,
)
| 108 | 26.25 | 59 | py |
lama-cleaner | lama-cleaner-main/lama_cleaner/model/pipeline/pipeline_stable_diffusion_controlnet_inpaint.py | # Copyright 2023 The HuggingFace 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/LICENSE-2.0
#
# Unless required by applicabl... | 28,155 | 47.047782 | 146 | py |
pygcn | pygcn-master/setup.py | from setuptools import setup
from setuptools import find_packages
setup(name='pygcn',
version='0.1',
description='Graph Convolutional Networks in PyTorch',
author='Thomas Kipf',
author_email='thomas.kipf@gmail.com',
url='https://tkipf.github.io',
download_url='https://github.com/tki... | 553 | 31.588235 | 60 | py |
pygcn | pygcn-master/pygcn/utils.py | import numpy as np
import scipy.sparse as sp
import torch
def encode_onehot(labels):
classes = set(labels)
classes_dict = {c: np.identity(len(classes))[i, :] for i, c in
enumerate(classes)}
labels_onehot = np.array(list(map(classes_dict.get, labels)),
dtype... | 2,848 | 34.17284 | 78 | py |
pygcn | pygcn-master/pygcn/layers.py | import math
import torch
from torch.nn.parameter import Parameter
from torch.nn.modules.module import Module
class GraphConvolution(Module):
"""
Simple GCN layer, similar to https://arxiv.org/abs/1609.02907
"""
def __init__(self, in_features, out_features, bias=True):
super(GraphConvolution... | 1,297 | 29.186047 | 77 | py |
pygcn | pygcn-master/pygcn/models.py | import torch.nn as nn
import torch.nn.functional as F
from pygcn.layers import GraphConvolution
class GCN(nn.Module):
def __init__(self, nfeat, nhid, nclass, dropout):
super(GCN, self).__init__()
self.gc1 = GraphConvolution(nfeat, nhid)
self.gc2 = GraphConvolution(nhid, nclass)
se... | 541 | 27.526316 | 62 | py |
pygcn | pygcn-master/pygcn/__init__.py | from __future__ import print_function
from __future__ import division
from .layers import *
from .models import *
from .utils import * | 135 | 21.666667 | 37 | py |
pygcn | pygcn-master/pygcn/train.py | from __future__ import division
from __future__ import print_function
import time
import argparse
import numpy as np
import torch
import torch.nn.functional as F
import torch.optim as optim
from pygcn.utils import load_data, accuracy
from pygcn.models import GCN
# Training settings
parser = argparse.ArgumentParser(... | 3,427 | 31.037383 | 72 | py |
r_em | r_em-master/setup.py | from setuptools import setup, find_packages
from os import path
_dir = path.abspath(path.dirname(__file__))
with open(path.join(_dir, 'tk_r_em', 'version.py')) as f:
exec(f.read())
setup(
name=__name__,
version=__version__,
description=__description__,
url=__url__,
author=__author__,
... | 1,124 | 26.439024 | 75 | py |
r_em | r_em-master/example_exp_data.py | """
tk_r_em network suites designed to restore different modalities of electron microscopy data
Author: Ivan Lobato
Email: Ivanlh20@gmail.com
"""
import os
import matplotlib
# Check if running on remote SSH and use appropriate backend for matplotlib
remote_ssh = "SSH_CONNECTION" in os.environ
matplotlib.use('Agg' if ... | 2,162 | 26.730769 | 116 | py |
r_em | r_em-master/example_sim_data.py | """
tk_r_em network suites designed to restore different modalities of electron microscopy data
Author: Ivan Lobato
Email: Ivanlh20@gmail.com
"""
import os
import matplotlib
# Check if running on remote SSH and use appropriate backend for matplotlib
remote_ssh = "SSH_CONNECTION" in os.environ
matplotlib.use('Agg' if... | 2,460 | 26.651685 | 116 | py |
r_em | r_em-master/example_sgl_exp_data.py | """
tk_r_em network suites designed to restore different modalities of electron microscopy data
Author: Ivan Lobato
Email: Ivanlh20@gmail.com
"""
import os
import matplotlib
# Check if running on remote SSH and use appropriate backend for matplotlib
remote_ssh = "SSH_CONNECTION" in os.environ
matplotlib.use('Agg' if ... | 1,891 | 27.666667 | 116 | py |
r_em | r_em-master/training/nn_fcns_local.py | #-*- coding: utf-8 -*-
"""
Created on Sun Feb 17 22:30:18 2019
__author__ = "Ivan Lobato"
"""
from __future__ import absolute_import, division, print_function, unicode_literals
import os
import numpy as np
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
import sys
sys.path.append('E:/Neural_... | 52,012 | 34.215301 | 204 | py |
r_em | r_em-master/training/nn_training.py | #-*- coding: utf-8 -*-
"""
Created on Thu Sep 26 14:31:55 2019
@author: Ivan
"""
from __future__ import absolute_import, division, print_function, unicode_literals
import os
import numpy as np
import sys
#########################################################################################
import tensorflow as t... | 4,069 | 33.786325 | 121 | py |
r_em | r_em-master/tk_r_em/version.py | __version__ = '1.0.4'
__name__ = 'tk_r_em'
__description__ = 'Deep convolutional neural networks to restore single-shot electron microscopy images'
__author__ = 'Ivan Lobato'
__author_email__='ivanlh20@gmail.com'
__url__ = 'https://github.com/Ivanlh20/r_em/'
__credits__ = 'University of Antwerp'
__license__ = 'GPLv3' | 318 | 38.875 | 104 | py |
r_em | r_em-master/tk_r_em/__init__.py | from .tk_r_em import load_network, load_sim_test_data, load_hrstem_exp_test_data | 80 | 80 | 80 | py |
r_em | r_em-master/tk_r_em/tk_r_em.py | """
r_em network suites designed to restore different modalities of electron microscopy data
Author: Ivan Lobato
Email: Ivanlh20@gmail.com
"""
import os
import pathlib
from typing import Tuple
import h5py
import numpy as np
import tensorflow as tf
def expand_dimensions(x):
if x.ndim == 2:
return np.expan... | 8,852 | 32.534091 | 136 | py |
ramps | ramps-master/examples/simulated-unicycle/simulator.py | #!/usr/bin/python
#
# Simulates an MDP-Strategy
import math
import sys
import resource
import subprocess
import signal
import tempfile
import copy
import itertools
import random
from PIL import Image
import pygame, pygame.locals
# ==================================
# Settings
# ==================================
MAGN... | 14,622 | 36.494872 | 149 | py |
ramps | ramps-master/examples/two-robots/simulator.py | #!/usr/bin/python
#
# Simulates an MDP-Strategy
import math
import os
import sys
import resource
import subprocess
import signal
import tempfile
import copy
import itertools
import random
from PIL import Image
import pygame, pygame.locals
# ==================================
# Settings
# =============================... | 18,269 | 42.396675 | 181 | py |
pyRVtest | pyRVtest-main/setup.py | """Sets up the package."""
from pathlib import Path
from setuptools import find_packages, setup
# define a function that reads a file in this directory
read = lambda p: Path(Path(__file__).resolve().parent / p).read_text()
# set up the package
setup(
name='pyRVtest',
author='Marco Duarte, Lorenzo Magnolfi, ... | 1,038 | 32.516129 | 99 | py |
pyRVtest | pyRVtest-main/pyRVtest/version.py | """Current package version."""
__version__ = '0.2.0'
| 54 | 12.75 | 30 | py |
pyRVtest | pyRVtest-main/pyRVtest/primitives.py | """Primitive data structures that constitute the foundation of the BLP model."""
import abc
from typing import Any, Dict, Mapping, Optional, Sequence, Tuple, Union
import numpy as np
from pyblp.utilities.basics import Array, Data, Groups, RecArray, extract_matrix, structure_matrices
from pyblp.configurations.formulat... | 18,680 | 44.014458 | 120 | py |
pyRVtest | pyRVtest-main/pyRVtest/options.py | r"""Global options.
Attributes
----------
digits : `int`
Number of digits displayed by status updates. The default number of digits is ``7``. The number of digits can be
changed to, for example, ``2``, with ``pyblp.options.digits = 2``.
verbose : `bool`
Whether to output status updates. By default, verbosi... | 6,539 | 57.392857 | 120 | py |
pyRVtest | pyRVtest-main/pyRVtest/construction.py | """Data construction."""
import contextlib
import os
from pathlib import Path
import pickle
from typing import Any, Callable, Mapping, Optional, Union
import numpy as np
from numpy.linalg import inv
from pyblp.utilities.basics import Array, RecArray, extract_matrix, get_indices
from . import options
def build_owne... | 15,264 | 48.083601 | 120 | py |
pyRVtest | pyRVtest-main/pyRVtest/__init__.py | """Public-facing objects."""
from . import data, options
from .configurations.formulation import Formulation, ModelFormulation
from .construction import (
build_ownership, build_markups, construct_passthrough_matrix, evaluate_first_order_conditions, read_pickle
)
from .economies.problem import Problem
from .primit... | 699 | 37.888889 | 110 | py |
pyRVtest | pyRVtest-main/pyRVtest/results/problem_results.py | """Economy-level structuring of conduct testing problem results."""
from pathlib import Path
import pickle
from typing import List, Union, TYPE_CHECKING
from pyblp.utilities.basics import Array
from .results import Results
from ..utilities.basics import format_table
# only import objects that create import cycles ... | 6,114 | 38.96732 | 120 | py |
pyRVtest | pyRVtest-main/pyRVtest/results/results.py | """Economy-level structuring of abstract BLP problem results."""
import abc
from typing import Any, Optional, TYPE_CHECKING
import numpy as np
from pyblp.utilities.basics import Array, StringRepresentation
# only import objects that create import cycles when checking types
if TYPE_CHECKING:
from ..economies.pr... | 1,092 | 32.121212 | 109 | py |
pyRVtest | pyRVtest-main/pyRVtest/results/__init__.py | """Structuring of conduct testing results."""
| 46 | 22.5 | 45 | py |
pyRVtest | pyRVtest-main/pyRVtest/economies/problem.py | """Economy-level conduct testing problem functionality."""
import abc
import contextlib
import itertools
import math
import os
import time
from typing import Mapping, Optional, Sequence
import numpy as np
from pyblp.utilities.algebra import precisely_identify_collinearity
from pyblp.utilities.basics import Array, Rec... | 44,071 | 50.971698 | 120 | py |
pyRVtest | pyRVtest-main/pyRVtest/economies/economy.py | """Economy underlying the firm conduct testing model."""
import abc
from typing import Any, Dict, Hashable, List, Mapping, Optional, Sequence, Tuple, Union
import numpy as np
from pyblp.utilities.basics import Array, RecArray, StringRepresentation, format_table, get_indices
from ..configurations.formulation import F... | 6,566 | 45.574468 | 119 | py |
pyRVtest | pyRVtest-main/pyRVtest/economies/__init__.py | """Economies underlying the conduct testing model."""
| 54 | 26.5 | 53 | py |
pyRVtest | pyRVtest-main/pyRVtest/utilities/basics.py | """Basic functionality."""
from typing import Any, Container, Dict, List, Optional, Sequence, Tuple
# define common types
Array = Any
RecArray = Any
Data = Dict[str, Array]
Options = Dict[str, Any]
Bounds = Tuple[Array, Array]
# define a pool managed by parallel and used by generate_items
pool = None
def format_t... | 3,811 | 39.126316 | 120 | py |
pyRVtest | pyRVtest-main/pyRVtest/utilities/__init__.py | """General functionality."""
| 29 | 14 | 28 | py |
pyRVtest | pyRVtest-main/pyRVtest/configurations/formulation.py | """Formulation of data matrices and absorption of fixed effects."""
import token
from typing import Any, Callable, Dict, List, Mapping, Optional, Set, Tuple, Type, Union
import numpy as np
import patsy
import patsy.builtins
import patsy.contrasts
import patsy.desc
import patsy.design_info
import patsy.origin
from pyb... | 26,918 | 53.602434 | 120 | py |
pyRVtest | pyRVtest-main/pyRVtest/configurations/__init__.py | """Configuration classes."""
| 29 | 14 | 28 | py |
pyRVtest | pyRVtest-main/pyRVtest/data/__init__.py | r"""Locations of critival value tables that are used to evaluate whether the instruments being tested are weak for size
or power.
Attributes
----------
F_CRITICAL_VALUES_POWER_RHO : `str`
Location of a CSV file containing critical values for power for each combination of :math:`\rho` and number of
instruments.... | 727 | 33.666667 | 119 | py |
pyRVtest | pyRVtest-main/docs/conf.py | """Sphinx configuration."""
import ast
import copy
import json
import os
from pathlib import Path
import re
import shutil
from typing import Any, Optional, Tuple
import astunparse
import sphinx.application
# get the location of the source directory
source_path = Path(__file__).resolve().parent
# project information... | 6,312 | 39.729032 | 119 | py |
MCSE | MCSE-master/simcse_to_huggingface.py | """
Convert SimCSE's checkpoints to Huggingface style.
code from https://github.com/princeton-nlp/SimCSE
"""
import argparse
import torch
import os
import json
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--path", type=str, help="Path of SimCSE checkpoint folder")
args = parser.par... | 1,340 | 29.477273 | 107 | py |
MCSE | MCSE-master/src/utils.py | import sys
import torch
# Set path to SentEval
PATH_TO_SENTEVAL = './SentEval'
PATH_TO_DATA = './SentEval/data'
# Import SentEval
sys.path.insert(0, PATH_TO_SENTEVAL)
import senteval
def evaluate(model, tokenizer):
def prepare(params, samples):
return
def batcher(params, batch):
sentences = [... | 1,592 | 30.235294 | 84 | py |
MCSE | MCSE-master/src/model.py | import torch
import torch.nn as nn
from transformers.models.bert.modeling_bert import BertPreTrainedModel, BertModel, BertLMPredictionHead
from transformers.models.roberta.modeling_roberta import RobertaPreTrainedModel, RobertaModel, RobertaLMHead
from transformers.modeling_outputs import SequenceClassifierOutput, Base... | 7,235 | 35.730964 | 137 | py |
MCSE | MCSE-master/src/data.py | import torch
from torch.utils.data import Dataset
import h5py
import numpy as np
from torchvision.datasets.folder import default_loader
class ImgSentDataset(Dataset):
def __init__(self,
text_file,
feature_file=None,
shuffle_imgs=False,
random_img... | 1,990 | 25.905405 | 65 | py |
MCSE | MCSE-master/src/evaluation.py | import sys
import os
import logging
import argparse
from prettytable import PrettyTable
import torch
from transformers import AutoModel, AutoTokenizer
# Set PATHs
PATH_TO_SENTEVAL = './SentEval'
PATH_TO_DATA = './SentEval/data'
# Import SentEval
sys.path.insert(0, PATH_TO_SENTEVAL)
import senteval
def print_full_ta... | 9,443 | 39.706897 | 155 | py |
MCSE | MCSE-master/src/train.py | import argparse
import logging
import math
import os
import random
import datasets
from torch.utils.data.dataloader import DataLoader
import torch
from tqdm.auto import tqdm
import transformers
from accelerate import Accelerator
from transformers import (
AdamW,
AutoConfig,
AutoModelForSequenceClassifica... | 15,256 | 34.399072 | 155 | py |
MCSE | MCSE-master/src/train_mix.py | import argparse
import logging
import math
import os
import datasets
from torch.utils.data.dataloader import DataLoader
import torch
from tqdm.auto import tqdm
import transformers
from accelerate import Accelerator
from transformers import (
AdamW,
AutoConfig,
AutoModelForSequenceClassification,
Auto... | 16,025 | 34.852349 | 155 | py |
MCSE | MCSE-master/preprocess/prepare_coco.py | __author__ = 'tylin'
__version__ = '2.0'
# Interface for accessing the Microsoft COCO dataset.
# Microsoft COCO is a large image dataset designed for object detection,
# segmentation, and caption generation. pycocotools is a Python API that
# assists in loading, parsing and visualizing the annotations in COCO.
# Pleas... | 19,410 | 41.197826 | 128 | py |
MCSE | MCSE-master/preprocess/extract_visn_feature.py | import os.path as osp
import h5py
import tqdm
import torch
import torch.nn as nn
import torchvision.transforms as transforms
import torchvision.models as models
from torchvision.datasets.folder import default_loader
def get_visn_arch(arch):
try:
return getattr(models, arch)
except AttributeError as e... | 3,518 | 32.198113 | 112 | py |
MCSE | MCSE-master/preprocess/prepare_flickr.py | import xml.etree.ElementTree as ET
import argparse
import os.path as osp
import tqdm
import random
from extract_visn_feature import ResnetFeatureExtractor
def get_sentence_data(fn):
"""
Parses a sentence file from the Flickr30K Entities dataset
input:
fn - full file path to the sentence file to p... | 6,353 | 36.157895 | 97 | py |
MCSE | MCSE-master/SentEval/setup.py | # Copyright (c) 2017-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
import io
from setuptools import setup, find_packages
with io.open('./README.md', encoding='utf-8') as f:
readme = f.read(... | 567 | 24.818182 | 61 | py |
MCSE | MCSE-master/SentEval/__init__.py | 0 | 0 | 0 | py | |
MCSE | MCSE-master/SentEval/examples/infersent.py | # Copyright (c) 2017-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
"""
InferSent models. See https://github.com/facebookresearch/InferSent.
"""
from __future__ import absolute_import, division,... | 2,462 | 30.987013 | 92 | py |
MCSE | MCSE-master/SentEval/examples/bow.py | # Copyright (c) 2017-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
from __future__ import absolute_import, division, unicode_literals
import sys
import io
import numpy as np
import logging
# ... | 3,423 | 29.300885 | 82 | py |
MCSE | MCSE-master/SentEval/examples/googleuse.py | # Copyright (c) 2017-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
from __future__ import absolute_import, division
import os
import sys
import logging
import tensorflow as tf
import tensorflow... | 2,205 | 31.441176 | 86 | py |
MCSE | MCSE-master/SentEval/examples/models.py | # Copyright (c) 2017-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
"""
This file contains the definition of encoders used in https://arxiv.org/pdf/1705.02364.pdf
"""
import numpy as np
import t... | 9,875 | 36.12782 | 94 | py |
MCSE | MCSE-master/SentEval/examples/gensen.py | # Copyright (c) 2017-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
"""
Clone GenSen repo here: https://github.com/Maluuba/gensen.git
And follow instructions for loading the model used in batcher... | 2,429 | 31.4 | 82 | py |
MCSE | MCSE-master/SentEval/examples/skipthought.py | # Copyright (c) 2017-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
from __future__ import absolute_import, division, unicode_literals
"""
Example of file for SkipThought in SentEval
"""
import ... | 2,048 | 32.048387 | 97 | py |
MCSE | MCSE-master/SentEval/senteval/engine.py | # Copyright (c) 2017-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
'''
Generic sentence evaluation scripts wrapper
'''
from __future__ import absolute_import, division, unicode_literals
from ... | 6,525 | 49.2 | 139 | py |
MCSE | MCSE-master/SentEval/senteval/rank.py | # Copyright (c) 2017-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
'''
Image-Caption Retrieval with COCO dataset
'''
from __future__ import absolute_import, division, unicode_literals
import os... | 4,643 | 41.605505 | 129 | py |
MCSE | MCSE-master/SentEval/senteval/snli.py | # Copyright (c) 2017-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
'''
SNLI - Entailment
'''
from __future__ import absolute_import, division, unicode_literals
import codecs
import os
import io... | 4,577 | 39.157895 | 75 | py |
MCSE | MCSE-master/SentEval/senteval/utils.py | # Copyright (c) 2017-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
from __future__ import absolute_import, division, unicode_literals
import numpy as np
import re
import inspect
from torch impo... | 2,713 | 27.270833 | 79 | py |
MCSE | MCSE-master/SentEval/senteval/binary.py | # Copyright (c) 2017-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
'''
Binary classifier and corresponding datasets : MR, CR, SUBJ, MPQA
'''
from __future__ import absolute_import, division, uni... | 3,712 | 38.924731 | 79 | py |
MCSE | MCSE-master/SentEval/senteval/mrpc.py | # Copyright (c) 2017-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
'''
MRPC : Microsoft Research Paraphrase (detection) Corpus
'''
from __future__ import absolute_import, division, unicode_liter... | 4,202 | 39.028571 | 80 | py |
MCSE | MCSE-master/SentEval/senteval/sts.py | # Copyright (c) 2017-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
'''
STS-{2012,2013,2014,2015,2016} (unsupervised) and
STS-benchmark (supervised) tasks
'''
from __future__ import absolute_imp... | 12,674 | 42.407534 | 129 | py |
MCSE | MCSE-master/SentEval/senteval/probing.py | # Copyright (c) 2017-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
'''
probing tasks
'''
from __future__ import absolute_import, division, unicode_literals
import os
import io
import copy
impo... | 6,786 | 38.459302 | 120 | py |
MCSE | MCSE-master/SentEval/senteval/sick.py | # Copyright (c) 2017-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
'''
SICK Relatedness and Entailment
'''
from __future__ import absolute_import, division, unicode_literals
import os
import io... | 9,243 | 41.599078 | 80 | py |
MCSE | MCSE-master/SentEval/senteval/__init__.py | # Copyright (c) 2017-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
from __future__ import absolute_import
from senteval.engine import SE
| 264 | 23.090909 | 61 | py |
MCSE | MCSE-master/SentEval/senteval/trec.py | # Copyright (c) 2017-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
'''
TREC question-type classification
'''
from __future__ import absolute_import, division, unicode_literals
import os
import... | 3,565 | 38.622222 | 79 | py |
MCSE | MCSE-master/SentEval/senteval/sst.py | # Copyright (c) 2017-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
'''
SST - binary classification
'''
from __future__ import absolute_import, division, unicode_literals
import os
import io
im... | 3,946 | 39.690722 | 94 | py |
MCSE | MCSE-master/SentEval/senteval/tools/relatedness.py | # Copyright (c) 2017-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
"""
Semantic Relatedness (supervised) with Pytorch
"""
from __future__ import absolute_import, division, unicode_literals
impo... | 4,552 | 32.725926 | 100 | py |
MCSE | MCSE-master/SentEval/senteval/tools/validation.py | # Copyright (c) 2017-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
"""
Validation and classification
(train) : inner-kfold classifier
(train, test) : kfold classifier
(train, d... | 10,358 | 40.939271 | 93 | py |
MCSE | MCSE-master/SentEval/senteval/tools/classifier.py | # Copyright (c) 2017-present, Facebook, Inc.
# All rights reserved.
#
# This source code is licensed under the license found in the
# LICENSE file in the root directory of this source tree.
#
"""
Pytorch Classifier class in the style of scikit-learn
Classifiers include Logistic Regression and MLP
"""
from __future__ ... | 7,737 | 37.118227 | 94 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.