python_code
stringlengths
0
4.04M
repo_name
stringlengths
7
58
file_path
stringlengths
5
147
import numpy as np import torch import torch.nn as nn from transformers import CLIPConfig, CLIPVisionModel, PreTrainedModel from ...utils import logging logger = logging.get_logger(__name__) def cosine_distance(image_embeds, text_embeds): normalized_image_embeds = nn.functional.normalize(image_embeds) nor...
diffusers-main
src/diffusers/pipelines/stable_diffusion/safety_checker.py
from dataclasses import dataclass from typing import List, Optional, Union import numpy as np import PIL from PIL import Image from ...utils import BaseOutput, is_flax_available, is_onnx_available, is_torch_available, is_transformers_available @dataclass class StableDiffusionPipelineOutput(BaseOutput): """ ...
diffusers-main
src/diffusers/pipelines/stable_diffusion/__init__.py
import inspect from typing import Callable, List, Optional, Union import torch from transformers import CLIPFeatureExtractor, CLIPTextModel, CLIPTokenizer from ...configuration_utils import FrozenDict from ...models import AutoencoderKL, UNet2DConditionModel from ...pipeline_utils import DiffusionPipeline from ...sc...
diffusers-main
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion.py
import inspect from typing import Callable, List, Optional, Union import numpy as np import torch import PIL from transformers import CLIPFeatureExtractor, CLIPTextModel, CLIPTokenizer from ...configuration_utils import FrozenDict from ...models import AutoencoderKL, UNet2DConditionModel from ...pipeline_utils impor...
diffusers-main
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_img2img.py
import inspect from typing import Callable, List, Optional, Union import numpy as np from transformers import CLIPFeatureExtractor, CLIPTokenizer from ...onnx_utils import OnnxRuntimeModel from ...pipeline_utils import DiffusionPipeline from ...schedulers import DDIMScheduler, LMSDiscreteScheduler, PNDMScheduler fro...
diffusers-main
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_onnx.py
import inspect from typing import Callable, List, Optional, Union import numpy as np import torch import PIL from tqdm.auto import tqdm from transformers import CLIPFeatureExtractor, CLIPTextModel, CLIPTokenizer from ...configuration_utils import FrozenDict from ...models import AutoencoderKL, UNet2DConditionModel f...
diffusers-main
src/diffusers/pipelines/stable_diffusion/pipeline_stable_diffusion_inpaint.py
# Copyright 2022 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...
diffusers-main
src/diffusers/pipelines/pndm/pipeline_pndm.py
# flake8: noqa from .pipeline_pndm import PNDMPipeline
diffusers-main
src/diffusers/pipelines/pndm/__init__.py
# flake8: noqa from .pipeline_ddpm import DDPMPipeline
diffusers-main
src/diffusers/pipelines/ddpm/__init__.py
# Copyright 2022 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...
diffusers-main
src/diffusers/pipelines/ddpm/pipeline_ddpm.py
# coding=utf-8 # Copyright 2020 Optuna, Hugging Face # # 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 o...
diffusers-main
src/diffusers/utils/logging.py
# This file is autogenerated by the command `make fix-copies`, do not edit. # flake8: noqa from ..utils import DummyObject, requires_backends class StableDiffusionOnnxPipeline(metaclass=DummyObject): _backends = ["torch", "transformers", "onnx"] def __init__(self, *args, **kwargs): requires_backends...
diffusers-main
src/diffusers/utils/dummy_torch_and_transformers_and_onnx_objects.py
# This file is autogenerated by the command `make fix-copies`, do not edit. # flake8: noqa from ..utils import DummyObject, requires_backends class ModelMixin(metaclass=DummyObject): _backends = ["torch"] def __init__(self, *args, **kwargs): requires_backends(self, ["torch"]) @classmethod d...
diffusers-main
src/diffusers/utils/dummy_pt_objects.py
import inspect import os import random import re import unittest from distutils.util import strtobool from pathlib import Path from typing import Union import PIL.Image import PIL.ImageOps import requests from packaging import version from .import_utils import is_flax_available, is_torch_available global_rng = rand...
diffusers-main
src/diffusers/utils/testing_utils.py
# Copyright 2022 The HuggingFace Inc. team. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by appl...
diffusers-main
src/diffusers/utils/__init__.py
# This file is autogenerated by the command `make fix-copies`, do not edit. # flake8: noqa from ..utils import DummyObject, requires_backends class LDMTextToImagePipeline(metaclass=DummyObject): _backends = ["torch", "transformers"] def __init__(self, *args, **kwargs): requires_backends(self, ["torc...
diffusers-main
src/diffusers/utils/dummy_torch_and_transformers_objects.py
# This file is autogenerated by the command `make fix-copies`, do not edit. # flake8: noqa from ..utils import DummyObject, requires_backends class FlaxStableDiffusionPipeline(metaclass=DummyObject): _backends = ["flax", "transformers"] def __init__(self, *args, **kwargs): requires_backends(self, ["...
diffusers-main
src/diffusers/utils/dummy_flax_and_transformers_objects.py
# Copyright 2022 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...
diffusers-main
src/diffusers/utils/import_utils.py
# This file is autogenerated by the command `make fix-copies`, do not edit. # flake8: noqa from ..utils import DummyObject, requires_backends class LMSDiscreteScheduler(metaclass=DummyObject): _backends = ["torch", "scipy"] def __init__(self, *args, **kwargs): requires_backends(self, ["torch", "scip...
diffusers-main
src/diffusers/utils/dummy_torch_and_scipy_objects.py
import inspect import warnings from typing import Any, Dict, Optional, Union from packaging import version def deprecate(*args, take_from: Optional[Union[Dict, Any]] = None, standard_warn=True): from .. import __version__ deprecated_kwargs = take_from values = () if not isinstance(args[0], tuple): ...
diffusers-main
src/diffusers/utils/deprecation_utils.py
# This file is autogenerated by the command `make fix-copies`, do not edit. # flake8: noqa from ..utils import DummyObject, requires_backends class FlaxModelMixin(metaclass=DummyObject): _backends = ["flax"] def __init__(self, *args, **kwargs): requires_backends(self, ["flax"]) @classmethod ...
diffusers-main
src/diffusers/utils/dummy_flax_objects.py
# Copyright 2022 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...
diffusers-main
src/diffusers/utils/outputs.py
# Copyright 2022 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...
diffusers-main
src/diffusers/models/attention.py
# Copyright 2022 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...
diffusers-main
src/diffusers/models/unet_2d_condition.py
# Copyright 2022 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...
diffusers-main
src/diffusers/models/unet_blocks_flax.py
# Copyright 2022 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...
diffusers-main
src/diffusers/models/attention_flax.py
# Copyright 2022 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...
diffusers-main
src/diffusers/models/__init__.py
# Copyright 2022 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...
diffusers-main
src/diffusers/models/resnet_flax.py
# Copyright 2022 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...
diffusers-main
src/diffusers/models/unet_blocks.py
# Copyright 2022 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...
diffusers-main
src/diffusers/models/unet_2d_condition_flax.py
# Copyright 2022 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...
diffusers-main
src/diffusers/models/embeddings.py
from functools import partial import torch import torch.nn as nn import torch.nn.functional as F class Upsample2D(nn.Module): """ An upsampling layer with an optional convolution. Parameters: channels: channels in the inputs and outputs. use_conv: a bool determining if a convolution is a...
diffusers-main
src/diffusers/models/resnet.py
# Copyright 2022 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...
diffusers-main
src/diffusers/models/unet_2d.py
# Copyright 2022 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...
diffusers-main
src/diffusers/models/embeddings_flax.py
# Copyright 2022 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...
diffusers-main
src/diffusers/models/vae_flax.py
# Copyright 2022 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...
diffusers-main
src/diffusers/models/vae.py
# Copyright 2022 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...
diffusers-main
src/diffusers/commands/env.py
# Copyright 2022 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...
diffusers-main
src/diffusers/commands/__init__.py
#!/usr/bin/env python # Copyright 2022 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...
diffusers-main
src/diffusers/commands/diffusers_cli.py
# Copyright 2022 NVIDIA and 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 b...
diffusers-main
src/diffusers/schedulers/scheduling_karras_ve_flax.py
# Copyright 2022 UC Berkeley Team and 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 ...
diffusers-main
src/diffusers/schedulers/scheduling_ddpm.py
# Copyright 2022 Zhejiang University Team and 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 # #...
diffusers-main
src/diffusers/schedulers/scheduling_pndm_flax.py
# Copyright 2022 Google Brain and 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 requ...
diffusers-main
src/diffusers/schedulers/scheduling_sde_vp.py
# Copyright 2022 UC Berkeley Team and 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 ...
diffusers-main
src/diffusers/schedulers/scheduling_ddpm_flax.py
# Copyright 2022 NVIDIA and 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 b...
diffusers-main
src/diffusers/schedulers/scheduling_karras_ve.py
# Copyright 2022 Google Brain and 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 requ...
diffusers-main
src/diffusers/schedulers/scheduling_sde_ve_flax.py
# Copyright 2022 Katherine Crowson and 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...
diffusers-main
src/diffusers/schedulers/scheduling_lms_discrete_flax.py
# Copyright 2022 Katherine Crowson and 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...
diffusers-main
src/diffusers/schedulers/scheduling_lms_discrete.py
# Copyright 2022 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...
diffusers-main
src/diffusers/schedulers/__init__.py
# Copyright 2022 Stanford University Team and 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 # #...
diffusers-main
src/diffusers/schedulers/scheduling_ddim_flax.py
# Copyright 2022 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...
diffusers-main
src/diffusers/schedulers/scheduling_utils.py
# Copyright 2022 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...
diffusers-main
src/diffusers/schedulers/scheduling_utils_flax.py
# Copyright 2022 Google Brain and 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 requ...
diffusers-main
src/diffusers/schedulers/scheduling_sde_ve.py
# Copyright 2022 Stanford University Team and 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 # #...
diffusers-main
src/diffusers/schedulers/scheduling_ddim.py
# Copyright 2022 Zhejiang University Team and 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 # #...
diffusers-main
src/diffusers/schedulers/scheduling_pndm.py
# coding=utf-8 # 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. # # Copyright 2021 Huawei Technologies Co., Ltd. # # Licensed under the Apache License, Version 2.0 (the "L...
bit-main
utils_squad.py
# coding=utf-8 # 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. # # 2022.09.25 - Add distill_attn argument for removing attention distillation # Meta Platform...
bit-main
kd_learner_glue.py
# coding=utf-8 # 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. # # Copyright 2021 Huawei Technologies Co., Ltd. # # Licensed under the Apache License, Version 2.0 (the "L...
bit-main
helper.py
# coding=utf-8 # 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. # # 2022.09.25 - Add support for using quantized Bert model as teacher # Meta Platforms, Inc. ...
bit-main
quant_task_distill_squad.py
# coding=utf-8 # 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. # # 2022.09.25 - Add default learning rate and batch size # Meta Platforms, Inc. <zechunliu@fb...
bit-main
utils_glue.py
# coding=utf-8 # 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. # # 2022.09.25 - Add distill_attn argument for removing attention distillation # Meta Platform...
bit-main
kd_learner_squad.py
# coding=utf-8 # 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. # # 2022.09.25 - Add support for using quantized Bert model as teacher # Meta Platforms, Inc. ...
bit-main
quant_task_distill_glue.py
# coding=utf-8 # 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. # # Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team. # Copyright (c) 2018,...
bit-main
transformer/configuration_utils.py
# coding=utf-8 # 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. # # Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team. # Copyright (c) 2018,...
bit-main
transformer/configuration_bert.py
# coding=utf-8 # 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. # # 2022.09.25 - Add elastic quantization support # Meta Platforms, Inc. <zechunliu@fb.com> # ...
bit-main
transformer/modeling_bert_quant.py
# coding=utf-8 # 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 import logging import math class LearnableBias(nn.Module): def __i...
bit-main
transformer/utils_quant.py
# coding=utf-8 # 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. # # Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team. # # Licensed under th...
bit-main
transformer/optimization.py
# coding=utf-8 # 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. # # Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team. # # Licensed under th...
bit-main
transformer/tokenization.py
# coding=utf-8 # 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. # # Copyright 2018 The Google AI Language Team Authors and The HuggingFace Inc. team. # Copyright (c) 2018,...
bit-main
transformer/modeling_bert.py
# coding=utf-8 # 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. """ Utilities for working with the local dataset cache. This file is adapted from the AllenNLP library at h...
bit-main
transformer/file_utils.py
from IPython.core.display import display_html, HTML, display_javascript, Javascript import json import numpy as np import inspect import re from collections import defaultdict from copy import deepcopy class TransactionManager: """ Class for maintaining a set of n_threads + 1 states Allows these states to be rea...
cs145-notebooks-2016-master
lecture-7-8/txn_viewer.py
from collections import namedtuple, OrderedDict from copy import copy import numpy as np from IPython.core.display import display_html, HTML, display_javascript, Javascript import json import random class BufferMemoryException(Exception): pass class PageNotFoundException(Exception): pass class FileNotFoundExcept...
cs145-notebooks-2016-master
bonus/io_backend.py
from collections import namedtuple, OrderedDict from copy import copy import numpy as np from IPython.core.display import display_html, HTML, display_javascript, Javascript import json import random class BufferMemoryException(Exception): pass class PageNotFoundException(Exception): pass class FileNotFoundExcept...
cs145-notebooks-2016-master
lecture-14-15/io_backend.py
from IPython.core.display import display_html, HTML def to_html_table(res, style=None): html = '<table' + (' style="' + style + '"' if style else '') + '><tr><th>' html += '</th><th>'.join(res.keys) + '</th></tr><tr><td>' html += '</td></tr><tr><td>'.join(['</td><td>'.join([str(cell) for cell in row]) for row in...
cs145-notebooks-2016-master
lecture-14-15/display_tools.py
# Utilities import csv import numpy as np from collections import namedtuple from collections import defaultdict from collections import Counter def loadData(): PlayerTeam = namedtuple('PlayerTeam','teamname playername') PlayerCollege = namedtuple('PlayerCollege', 'playername collegename') teams =...
cs145-notebooks-2016-master
PS3/nfl.py
from collections import namedtuple, OrderedDict from copy import copy import numpy as np from IPython.core.display import display_html, HTML, display_javascript, Javascript import json import random class BufferMemoryException(Exception): pass class PageNotFoundException(Exception): pass class FileNotFoundExcept...
cs145-notebooks-2016-master
PS3/io_backend.py
from IPython.core.display import display_html, HTML def to_html_table(res, style=None): html = '<table' + (' style="' + style + '"' if style else '') + '><tr><th>' html += '</th><th>'.join(res.keys) + '</th></tr><tr><td>' html += '</td></tr><tr><td>'.join(['</td><td>'.join([str(cell) for cell in row]) for row in...
cs145-notebooks-2016-master
lecture-16/display_tools.py
# TODO: # 1. Remove asserts and replace with exceptions. # 2. There is a lot of unpythonic code in here, someone who likes python can fix it :) def get_result(x): return [tuple(t) for t in x] def generate_dict(t, schema_index): d = dict() for x in schema_index.keys(): d[x] = t[schema_index[x]] ret...
cs145-notebooks-2016-master
lecture-16/relation_algebra.py
from IPython.core.display import display_html, HTML def to_html_table(res, style=None): html = '<table' + (' style="' + style + '"' if style else '') + '><tr><th>' html += '</th><th>'.join(res.keys) + '</th></tr><tr><td>' html += '</td></tr><tr><td>'.join(['</td><td>'.join([str(cell) for cell in row]) for row in...
cs145-notebooks-2016-master
lecture-17/display_tools.py
# TODO: # 1. Remove asserts and replace with exceptions. # 2. There is a lot of unpythonic code in here, someone who likes python can fix it :) def get_result(x): return [tuple(t) for t in x] def generate_dict(t, schema_index): d = dict() for x in schema_index.keys(): d[x] = t[schema_index[x]] ret...
cs145-notebooks-2016-master
lecture-17/relation_algebra.py
# A = set(["name", "category"]) # These are the attribute set. # fds = [ (set(["name"]),"color"), # (set(["category"]), "department"), # (set(["color", "category"]), "price") ] def to_set(x): """Convert input int, string, list, tuple, set -> set""" if type(x) == set: return x elif type(x) in...
cs145-notebooks-2016-master
lecture-5-6/closure.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. from typing import Optional from overrides import overrides from allennlp.training.metrics.metric import Metric import torch import numpy as np from curiosity.util import get_logger log = get_logger(__name__) @Metric.register("mean_reciproc...
curiosity-main
curiosity/metrics.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. """ A database containing all the wikipedia/entity linking information. """ import random import re import subprocess import os from contextlib import contextmanager from collections import defaultdict from typing import List, Tuple, Dict, Name...
curiosity-main
curiosity/db.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. import os import numpy as np from overrides import overrides from allennlp.common.util import JsonDict from allennlp.data import Instance from allennlp.predictors.predictor import Predictor from allennlp.data.dataset_readers.dataset_reader impo...
curiosity-main
curiosity/predictors.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. from typing import Dict, Optional, Union import math import torch from torch import nn from allennlp.nn.util import ( get_text_field_mask, sequence_cross_entropy_with_logits, masked_mean, ) from allennlp.data.vocabulary import Vocab...
curiosity-main
curiosity/models.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. """ Implement very simple similarity search """ from typing import List, Optional import pickle from sklearn.feature_extraction.text import TfidfVectorizer from sklearn.metrics.pairwise import cosine_similarity from curiosity.db import Fact, c...
curiosity-main
curiosity/similarity.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. import logging def get_logger(name): log = logging.getLogger(name) if len(log.handlers) < 2: formatter = logging.Formatter( "%(asctime)s - %(name)s - %(levelname)s - %(message)s" ) fh = logging.Fi...
curiosity-main
curiosity/util.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. from typing import Dict import torch from overrides import overrides from allennlp.common.registrable import Registrable from allennlp.modules.similarity_functions.similarity_function import SimilarityFunction class FactRanker(torch.nn.Module...
curiosity-main
curiosity/nn.py
curiosity-main
curiosity/__init__.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. from typing import Dict, Optional, Union import math import torch from torch import nn from allennlp.nn.util import ( get_text_field_mask, sequence_cross_entropy_with_logits, masked_mean ) from allennlp.data.vocabulary import Vocabulary...
curiosity-main
curiosity/baseline_models.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. """ Reader for curiosity dialog dataset. Below is a sample json with relevant structure { "dialogs": [ { "messages": [ { "message": "Hi, what do you know about St. Louis' history?", ...
curiosity-main
curiosity/reader.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. import os import json from itertools import cycle import click import _jsonnet from curiosity.stats import ( MajorityLikes, TfidfFactBaseline, MajorityDialogActs, MajorityPolicyActs, save_metrics, fact_length_stats, ) f...
curiosity-main
curiosity/cli.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. """ This file computes baseline accuracies based on majority based voting """ from typing import Dict, Optional, List import json import numpy as np import pandas as pd from allennlp.data.tokenizers.token import Token from curiosity.reader impo...
curiosity-main
curiosity/stats.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. from typing import Dict, Union import torch from pytorch_pretrained_bert.modeling import BertModel from allennlp.modules.token_embedders.bert_token_embedder import PretrainedBertModel class BertEncoder(torch.nn.Module): """ Adapted ...
curiosity-main
curiosity/bert.py
#!/usr/bin/env python3 #Copyright (c) Facebook, Inc. and its affiliates. """ Reader for curiosity dialog dataset. Below is a sample json with relevant structure { "dialogs": [ { "messages": [ { "message": "Hi, what do you know about St. Louis' history?", ...
curiosity-main
curiosity/baseline_reader.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. from typing import Dict, List, Tuple, Optional import numpy from overrides import overrides import torch import torch.nn.functional as F from torch.nn.modules.linear import Linear from torch.nn.modules.rnn import LSTMCell from torch.nn import ...
curiosity-main
curiosity/paraphrase_models.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. from curiosity.reader import CuriosityDialogReader, USER, ASSISTANT def test_text_to_instance(): facts_0 = [ {"fid": 1, "used": True}, {"fid": 1, "used": False}, {"fid": 1, "used": False}, ] facts_1 = [ ...
curiosity-main
curiosity/tests/test_reader.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. import torch import pytest from curiosity.metrics import MeanReciprocalRank def test_mrr(): logits = torch.tensor([1, 2, 0.5, 0, 4, 3]).reshape(1, 1, -1) labels = torch.tensor([0, 1, 0, 0, 0, 1]).reshape(1, 1, -1) mask = torch.ten...
curiosity-main
curiosity/tests/test_metrics.py
curiosity-main
curiosity/tests/__init__.py
#!/usr/bin/env python3 # Copyright (c) Facebook, Inc. and its affiliates. All Rights Reserved import glob import os import shutil from os import path from typing import List from setuptools import find_packages, setup cwd = os.path.dirname(os.path.abspath(__file__)) version = "0.0.1" try: if not os.getenv("RELEA...
d2go-main
setup.py