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 |
|---|---|---|---|---|---|---|
roosterize | roosterize-master/roosterize/ml/onmt/MultiSourceTranslator.py | from typing import *
import codecs
from itertools import count
from roosterize.ml.onmt.CustomTranslator import CustomTranslator
from roosterize.ml.onmt.MultiSourceDataset import MultiSourceDataset
from roosterize.ml.onmt.MultiSourceInputter import MultiSourceInputter
from roosterize.ml.onmt.MultiSourceModelBuilder imp... | 22,045 | 38.508961 | 509 | py |
roosterize | roosterize-master/roosterize/ml/onmt/MultiSourceCopyGenerator.py | from typing import *
from onmt.modules.copy_generator import collapse_copy_scores
from onmt.utils.loss import NMTLossCompute
from onmt.utils.misc import aeq
import torch
import torch.nn as nn
import torch.nn.utils
from seutil import LoggingUtils
class MultiSourceCopyGenerator(nn.Module):
"""An implementation of... | 8,739 | 34.673469 | 116 | py |
roosterize | roosterize-master/roosterize/ml/onmt/MultiSourceTranslationBuilder.py | import torch
from seutil import LoggingUtils
from roosterize.ml.onmt.MultiSourceTranslation import MultiSourceTranslation
class MultiSourceTranslationBuilder:
logger = LoggingUtils.get_logger(__name__)
def __init__(self, src_types, data, fields, n_best=1, replace_unk=False,
has_tgt=False,... | 4,245 | 38.314815 | 100 | py |
roosterize | roosterize-master/roosterize/ml/onmt/CustomRNNEncoder.py | from typing import *
from onmt.encoders.rnn_encoder import RNNEncoder
from torch.nn.utils.rnn import pack_padded_sequence as pack
from torch.nn.utils.rnn import pad_packed_sequence as unpack
class CustomRNNEncoder(RNNEncoder):
@classmethod
def from_opt(cls, opt, embeddings):
"""Alternate constructor... | 1,398 | 30.088889 | 73 | py |
roosterize | roosterize-master/roosterize/ml/onmt/MultiSourceNMTModel.py | from typing import *
from onmt.decoders import DecoderBase
from onmt.encoders import EncoderBase
import torch
import torch.nn as nn
from seutil import LoggingUtils
class MultiSourceNMTModel(nn.Module):
logger = LoggingUtils.get_logger(__name__)
def __init__(self,
encoders: List[EncoderBase],
... | 2,529 | 35.142857 | 101 | py |
roosterize | roosterize-master/roosterize/ml/onmt/MultiSourceDataset.py | from typing import *
import collections
from itertools import chain, starmap
import torch
from torchtext.data import Dataset as TorchtextDataset
from torchtext.data import Example, Field
from torchtext.vocab import Vocab
def _join_dicts(*args):
"""
Args:
dictionaries with disjoint keys.
Returns:... | 7,581 | 37.292929 | 82 | py |
roosterize | roosterize-master/roosterize/ml/onmt/CustomTranslator.py | from typing import *
import codecs
from itertools import count
import onmt
import onmt.inputters as inputters
import os
import time
from seutil import LoggingUtils
from onmt.translate.translator import Translator
class CustomTranslator(Translator):
logger = LoggingUtils.get_logger(__name__)
@classmethod
... | 10,135 | 38.135135 | 498 | py |
roosterize | roosterize-master/roosterize/ml/onmt/MultiSourceInputter.py | from typing import *
import codecs
import collections
import glob
from itertools import chain, cycle
import math
from onmt.inputters.text_dataset import text_fields, TextMultiField
import os
import torch
import torchtext.data
from torchtext.data import Field, RawField
from torchtext.data.utils import RandomShuffler
fr... | 27,140 | 38.391872 | 148 | py |
roosterize | roosterize-master/roosterize/ml/onmt/MultiSourceModelBuilder.py | from typing import *
from roosterize.ml.onmt.CustomRNNEncoder import CustomRNNEncoder
from roosterize.ml.onmt.MultiSourceCopyGenerator import MultiSourceCopyGenerator
from roosterize.ml.onmt.MultiSourceInputFeedRNNDecoder import MultiSourceInputFeedRNNDecoder
from roosterize.ml.onmt.MultiSourceNMTModel import MultiSou... | 10,460 | 37.601476 | 105 | py |
roosterize | roosterize-master/roosterize/ml/onmt/MultiSourceGlobalAttention.py | from typing import *
from onmt.modules.global_attention import GlobalAttention
from onmt.modules.sparse_activations import sparsemax
from onmt.utils.misc import aeq, sequence_mask
import torch
import torch.nn as nn
import torch.nn.functional as F
from seutil import LoggingUtils
class MultiSourceGlobalAttention(Glob... | 3,708 | 34.32381 | 169 | py |
roosterize | roosterize-master/onmt/opts.py | """ Implementation of all available options """
from __future__ import print_function
import configargparse
from onmt.models.sru import CheckSRU
def config_opts(parser):
parser.add('-config', '--config', required=False,
is_config_file_arg=True, help='config file path')
parser.add('-save_config... | 39,915 | 51.314548 | 79 | py |
roosterize | roosterize-master/onmt/train_single.py | #!/usr/bin/env python
"""Training on a single process."""
import os
import torch
from onmt.inputters.inputter import build_dataset_iter, \
load_old_vocab, old_style_vocab, build_dataset_iter_multiple
from onmt.model_builder import build_model
from onmt.utils.optimizers import Optimizer
from onmt.utils.misc import... | 4,939 | 32.605442 | 79 | py |
roosterize | roosterize-master/onmt/model_builder.py | """
This file is for models creation, which consults options
and creates each encoder and decoder accordingly.
"""
import re
import torch
import torch.nn as nn
from torch.nn.init import xavier_uniform_
import onmt.inputters as inputters
import onmt.modules
from onmt.encoders import str2enc
from onmt.decoders import s... | 8,477 | 34.033058 | 78 | py |
roosterize | roosterize-master/onmt/trainer.py | """
This is the loadable seq2seq trainer library that is
in charge of training details, loss compute, and statistics.
See train.py for a use case of this library.
Note: To make this a general library, we implement *only*
mechanism things here(i.e. what to do), and leave the strategy
... | 18,157 | 38.733042 | 79 | py |
roosterize | roosterize-master/onmt/inputters/text_dataset.py | # -*- coding: utf-8 -*-
from functools import partial
import six
import torch
from torchtext.data import Field, RawField
from onmt.inputters.datareader_base import DataReaderBase
class TextDataReader(DataReaderBase):
def read(self, sequences, side, _dir=None):
"""Read text data from disk.
Args:... | 6,904 | 34.410256 | 77 | py |
roosterize | roosterize-master/onmt/inputters/dataset_base.py | # coding: utf-8
from itertools import chain, starmap
from collections import Counter
import torch
from torchtext.data import Dataset as TorchtextDataset
from torchtext.data import Example
from torchtext.vocab import Vocab
def _join_dicts(*args):
"""
Args:
dictionaries with disjoint keys.
Return... | 6,528 | 41.122581 | 78 | py |
roosterize | roosterize-master/onmt/inputters/inputter.py | # -*- coding: utf-8 -*-
import glob
import os
import codecs
import math
from collections import Counter, defaultdict
from itertools import chain, cycle
import torch
import torchtext.data
from torchtext.data import Field, RawField
from torchtext.vocab import Vocab
from torchtext.data.utils import RandomShuffler
from ... | 29,961 | 35.76319 | 79 | py |
roosterize | roosterize-master/onmt/inputters/audio_dataset.py | # -*- coding: utf-8 -*-
import os
from tqdm import tqdm
import torch
from torchtext.data import Field
from onmt.inputters.datareader_base import DataReaderBase
# imports of datatype-specific dependencies
try:
import torchaudio
import librosa
import numpy as np
except ImportError:
torchaudio, librosa,... | 8,459 | 36.93722 | 79 | py |
roosterize | roosterize-master/onmt/inputters/image_dataset.py | # -*- coding: utf-8 -*-
import os
import torch
from torchtext.data import Field
from onmt.inputters.datareader_base import DataReaderBase
# domain specific dependencies
try:
from PIL import Image
from torchvision import transforms
import cv2
except ImportError:
Image, transforms, cv2 = None, None, N... | 3,378 | 30.579439 | 77 | py |
roosterize | roosterize-master/onmt/inputters/vec_dataset.py | import os
import torch
from torchtext.data import Field
from onmt.inputters.datareader_base import DataReaderBase
try:
import numpy as np
except ImportError:
np = None
class VecDataReader(DataReaderBase):
"""Read feature vector data from disk.
Raises:
onmt.inputters.datareader_base.MissingD... | 5,447 | 35.32 | 78 | py |
roosterize | roosterize-master/onmt/modules/sparse_losses.py | import torch
import torch.nn as nn
from torch.autograd import Function
from onmt.modules.sparse_activations import _threshold_and_support
from onmt.utils.misc import aeq
class SparsemaxLossFunction(Function):
@staticmethod
def forward(ctx, input, target):
"""
input (FloatTensor): ``(n, num_cl... | 2,804 | 35.428571 | 78 | py |
roosterize | roosterize-master/onmt/modules/sparse_activations.py | """
An implementation of sparsemax (Martins & Astudillo, 2016). See
:cite:`DBLP:journals/corr/MartinsA16` for detailed description.
By Ben Peters and Vlad Niculae
"""
import torch
from torch.autograd import Function
import torch.nn as nn
def _make_ix_like(input, dim=0):
d = input.size(dim)
rho = torch.arang... | 2,649 | 26.040816 | 78 | py |
roosterize | roosterize-master/onmt/modules/structured_attention.py | import torch.nn as nn
import torch
import torch.cuda
class MatrixTree(nn.Module):
"""Implementation of the matrix-tree theorem for computing marginals
of non-projective dependency parsing. This attention layer is used
in the paper "Learning Structured Text Representations"
:cite:`DBLP:journals/corr/Li... | 1,414 | 35.282051 | 77 | py |
roosterize | roosterize-master/onmt/modules/util_class.py | """ Misc classes """
import torch
import torch.nn as nn
# At the moment this class is only used by embeddings.Embeddings look-up tables
class Elementwise(nn.ModuleList):
"""
A simple network container.
Parameters are a list of modules.
Inputs are a 3d Tensor whose last dimension is the same length
... | 1,486 | 29.346939 | 79 | py |
roosterize | roosterize-master/onmt/modules/conv_multi_step_attention.py | """ Multi Step Attention for CNN """
import torch
import torch.nn as nn
import torch.nn.functional as F
from onmt.utils.misc import aeq
SCALE_WEIGHT = 0.5 ** 0.5
def seq_linear(linear, x):
""" linear transform for 3-d tensor """
batch, hidden_size, length, _ = x.size()
h = linear(torch.transpose(x, 1, 2... | 2,865 | 34.382716 | 79 | py |
roosterize | roosterize-master/onmt/modules/average_attn.py | # -*- coding: utf-8 -*-
"""Average Attention module."""
import torch
import torch.nn as nn
from onmt.modules.position_ffn import PositionwiseFeedForward
class AverageAttention(nn.Module):
"""
Average Attention module from
"Accelerating Neural Transformer via an Average Attention Network"
:cite:`DBLP... | 4,227 | 36.75 | 79 | py |
roosterize | roosterize-master/onmt/modules/copy_generator.py | import torch
import torch.nn as nn
from onmt.utils.misc import aeq
from onmt.utils.loss import NMTLossCompute
def collapse_copy_scores(scores, batch, tgt_vocab, src_vocabs=None,
batch_dim=1, batch_offset=None):
"""
Given scores from an expanded dictionary
corresponeding to a batc... | 9,415 | 34.938931 | 79 | py |
roosterize | roosterize-master/onmt/modules/embeddings.py | """ Embeddings module """
import math
import warnings
import torch
import torch.nn as nn
from onmt.modules.util_class import Elementwise
class PositionalEncoding(nn.Module):
"""Sinusoidal positional encoding for non-recurrent neural networks.
Implementation based on "Attention Is All You Need"
:cite:`D... | 10,689 | 36.640845 | 79 | py |
roosterize | roosterize-master/onmt/modules/global_attention.py | """Global attention modules (Luong / Bahdanau)"""
import torch
import torch.nn as nn
import torch.nn.functional as F
from onmt.modules.sparse_activations import sparsemax
from onmt.utils.misc import aeq, sequence_mask
# This class is mainly used by decoder.py for RNNs but also
# by the CNN / transformer decoder when ... | 7,830 | 33.346491 | 79 | py |
roosterize | roosterize-master/onmt/modules/gate.py | """ ContextGate module """
import torch
import torch.nn as nn
def context_gate_factory(gate_type, embeddings_size, decoder_size,
attention_size, output_size):
"""Returns the correct ContextGate class"""
gate_types = {'source': SourceContextGate,
'target': TargetCont... | 3,635 | 38.521739 | 79 | py |
roosterize | roosterize-master/onmt/modules/weight_norm.py | """ Weights normalization modules """
import torch
import torch.nn as nn
import torch.nn.functional as F
from torch.nn import Parameter
def get_var_maybe_avg(namespace, var_name, training, polyak_decay):
""" utility for retrieving polyak averaged params
Update average
"""
v = getattr(namespace, ... | 9,775 | 38.578947 | 78 | py |
roosterize | roosterize-master/onmt/modules/position_ffn.py | """Position feed-forward network from "Attention is All You Need"."""
import torch.nn as nn
class PositionwiseFeedForward(nn.Module):
""" A two-layer Feed-Forward-Network with residual layer norm.
Args:
d_model (int): the size of input for the first-layer of the FFN.
d_ff (int): the hidden l... | 1,308 | 30.166667 | 73 | py |
roosterize | roosterize-master/onmt/modules/multi_headed_attn.py | """ Multi-Head Attention module """
import math
import torch
import torch.nn as nn
from onmt.utils.misc import generate_relative_positions_matrix,\
relative_matmul
# from onmt.utils.misc import aeq
class MultiHeadedAttention(nn.Module):
"""Multi-Head Attention module from "Attention i... | 8,168 | 34.211207 | 77 | py |
roosterize | roosterize-master/onmt/models/stacked_rnn.py | """ Implementation of ONMT RNN for Input Feeding Decoding """
import torch
import torch.nn as nn
class StackedLSTM(nn.Module):
"""
Our own implementation of stacked LSTM.
Needed for the decoder, because we do input feeding.
"""
def __init__(self, num_layers, input_size, rnn_size, dropout):
... | 1,994 | 29.227273 | 66 | py |
roosterize | roosterize-master/onmt/models/model.py | """ Onmt NMT Model base class definition """
import torch.nn as nn
class NMTModel(nn.Module):
"""
Core trainable object in OpenNMT. Implements a trainable interface
for a simple, generic encoder + decoder model.
Args:
encoder (onmt.encoders.EncoderBase): an encoder object
decoder (onmt.de... | 1,961 | 36.018868 | 77 | py |
roosterize | roosterize-master/onmt/models/model_saver.py | import os
import torch
import torch.nn as nn
from collections import deque
from onmt.utils.logging import logger
from copy import deepcopy
def build_model_saver(model_opt, opt, model, fields, optim):
model_saver = ModelSaver(opt.save_model,
model,
model_... | 4,413 | 30.304965 | 79 | py |
roosterize | roosterize-master/onmt/models/sru.py | """ SRU Implementation """
# flake8: noqa
import subprocess
import platform
import os
import re
import configargparse
import torch
import torch.nn as nn
from torch.autograd import Function
from collections import namedtuple
# For command-line option parsing
class CheckSRU(configargparse.Action):
def __init__(sel... | 24,302 | 36.27454 | 81 | py |
roosterize | roosterize-master/onmt/decoders/transformer.py | """
Implementation of "Attention is All You Need"
"""
import torch
import torch.nn as nn
from onmt.decoders.decoder import DecoderBase
from onmt.modules import MultiHeadedAttention, AverageAttention
from onmt.modules.position_ffn import PositionwiseFeedForward
from onmt.utils.misc import sequence_mask
class Transfo... | 9,539 | 36.70751 | 79 | py |
roosterize | roosterize-master/onmt/decoders/decoder.py | import torch
import torch.nn as nn
from onmt.models.stacked_rnn import StackedLSTM, StackedGRU
from onmt.modules import context_gate_factory, GlobalAttention
from onmt.utils.rnn_factory import rnn_factory
from onmt.utils.misc import aeq
class DecoderBase(nn.Module):
"""Abstract class for decoders.
Args:
... | 15,484 | 34.193182 | 79 | py |
roosterize | roosterize-master/onmt/decoders/ensemble.py | """Ensemble decoding.
Decodes using multiple models simultaneously,
combining their prediction distributions by averaging.
All models in the ensemble must share a target vocabulary.
"""
import torch
import torch.nn as nn
from onmt.encoders.encoder import EncoderBase
from onmt.decoders.decoder import DecoderBase
from... | 5,930 | 37.512987 | 79 | py |
roosterize | roosterize-master/onmt/decoders/cnn_decoder.py | """Implementation of the CNN Decoder part of
"Convolutional Sequence to Sequence Learning"
"""
import torch
import torch.nn as nn
from onmt.modules import ConvMultiStepAttention, GlobalAttention
from onmt.utils.cnn_factory import shape_transform, GatedConv
from onmt.decoders.decoder import DecoderBase
SCALE_WEIGHT = ... | 4,890 | 35.5 | 78 | py |
roosterize | roosterize-master/onmt/encoders/mean_encoder.py | """Define a minimal encoder."""
from onmt.encoders.encoder import EncoderBase
from onmt.utils.misc import sequence_mask
import torch
class MeanEncoder(EncoderBase):
"""A trivial non-recurrent encoder. Simply applies mean pooling.
Args:
num_layers (int): number of replicated layers
embeddings (o... | 1,404 | 29.543478 | 79 | py |
roosterize | roosterize-master/onmt/encoders/image_encoder.py | """Image Encoder."""
import torch.nn as nn
import torch.nn.functional as F
import torch
from onmt.encoders.encoder import EncoderBase
class ImageEncoder(EncoderBase):
"""A simple encoder CNN -> RNN for image src.
Args:
num_layers (int): number of encoder layers.
bidirectional (bool): bidirec... | 4,839 | 35.666667 | 76 | py |
roosterize | roosterize-master/onmt/encoders/rnn_encoder.py | """Define RNN-based encoders."""
import torch.nn as nn
import torch.nn.functional as F
from torch.nn.utils.rnn import pack_padded_sequence as pack
from torch.nn.utils.rnn import pad_packed_sequence as unpack
from onmt.encoders.encoder import EncoderBase
from onmt.utils.rnn_factory import rnn_factory
class RNNEncode... | 4,274 | 34.92437 | 73 | py |
roosterize | roosterize-master/onmt/encoders/audio_encoder.py | """Audio encoder"""
import math
import torch.nn as nn
from torch.nn.utils.rnn import pack_padded_sequence as pack
from torch.nn.utils.rnn import pad_packed_sequence as unpack
from onmt.utils.rnn_factory import rnn_factory
from onmt.encoders.encoder import EncoderBase
class AudioEncoder(EncoderBase):
"""A simpl... | 6,055 | 40.197279 | 77 | py |
roosterize | roosterize-master/onmt/encoders/encoder.py | """Base class for encoders and generic multi encoders."""
import torch.nn as nn
from onmt.utils.misc import aeq
class EncoderBase(nn.Module):
"""
Base encoder class. Specifies the interface used by different encoder types
and required by :class:`onmt.Models.NMTModel`.
.. mermaid::
graph BT
... | 1,383 | 22.457627 | 79 | py |
roosterize | roosterize-master/onmt/encoders/transformer.py | """
Implementation of "Attention is All You Need"
"""
import torch.nn as nn
from onmt.encoders.encoder import EncoderBase
from onmt.modules import MultiHeadedAttention
from onmt.modules.position_ffn import PositionwiseFeedForward
from onmt.utils.misc import sequence_mask
class TransformerEncoderLayer(nn.Module):
... | 4,661 | 33.279412 | 75 | py |
roosterize | roosterize-master/onmt/encoders/cnn_encoder.py | """
Implementation of "Convolutional Sequence to Sequence Learning"
"""
import torch.nn as nn
from onmt.encoders.encoder import EncoderBase
from onmt.utils.cnn_factory import shape_transform, StackedCNN
SCALE_WEIGHT = 0.5 ** 0.5
class CNNEncoder(EncoderBase):
"""Encoder based on "Convolutional Sequence to Seque... | 1,860 | 32.232143 | 73 | py |
roosterize | roosterize-master/onmt/translate/translation_server.py | #!/usr/bin/env python
"""REST Translation server."""
from __future__ import print_function
import codecs
import sys
import os
import time
import json
import threading
import re
import traceback
import importlib
import torch
import onmt.opts
from onmt.utils.logging import init_logger
from onmt.utils.misc import set_ran... | 21,856 | 32.992224 | 79 | py |
roosterize | roosterize-master/onmt/translate/decode_strategy.py | import torch
class DecodeStrategy(object):
"""Base class for generation strategies.
Args:
pad (int): Magic integer in output vocab.
bos (int): Magic integer in output vocab.
eos (int): Magic integer in output vocab.
batch_size (int): Current batch size.
device (torch.d... | 5,508 | 38.92029 | 79 | py |
roosterize | roosterize-master/onmt/translate/translation.py | """ Translation main class """
from __future__ import unicode_literals, print_function
import torch
from onmt.inputters.text_dataset import TextMultiField
class TranslationBuilder(object):
"""
Build a word-based translation from the batch output
of translator and the underlying dictionaries.
Replace... | 6,172 | 36.871166 | 78 | py |
roosterize | roosterize-master/onmt/translate/beam_search.py | import torch
from onmt.translate.decode_strategy import DecodeStrategy
class BeamSearch(DecodeStrategy):
"""Generation beam search.
Note that the attributes list is not exhaustive. Rather, it highlights
tensors to document their shape. (Since the state variables' "batch"
size decreases as beams fini... | 12,834 | 44.514184 | 79 | py |
roosterize | roosterize-master/onmt/translate/beam.py | from __future__ import division
import torch
from onmt.translate import penalties
import warnings
class Beam(object):
"""Class for managing the internals of the beam search process.
Takes care of beams, back pointers, and scores.
Args:
size (int): Number of beams to use.
pad (int): Magi... | 11,404 | 37.792517 | 78 | py |
roosterize | roosterize-master/onmt/translate/penalties.py | from __future__ import division
import torch
class PenaltyBuilder(object):
"""Returns the Length and Coverage Penalty function for Beam Search.
Args:
length_pen (str): option name of length pen
cov_pen (str): option name of cov pen
Attributes:
has_cov_pen (bool): Whether coverage... | 3,710 | 35.029126 | 78 | py |
roosterize | roosterize-master/onmt/translate/random_sampling.py | import torch
from onmt.translate.decode_strategy import DecodeStrategy
def sample_with_temperature(logits, sampling_temp, keep_topk):
"""Select next tokens randomly from the top k possible next tokens.
Samples from a categorical distribution over the ``keep_topk`` words using
the category probabilities ... | 6,440 | 41.375 | 79 | py |
roosterize | roosterize-master/onmt/translate/translator.py | #!/usr/bin/env python
""" Translator Class and builder """
from __future__ import print_function
import codecs
import os
import math
import time
from itertools import count
import torch
import onmt.model_builder
import onmt.translate.beam
import onmt.inputters as inputters
import onmt.decoders.ensemble
from onmt.tran... | 31,472 | 36.158205 | 79 | py |
roosterize | roosterize-master/onmt/utils/rnn_factory.py | """
RNN tools
"""
import torch.nn as nn
import onmt.models
def rnn_factory(rnn_type, **kwargs):
""" rnn factory, Use pytorch version when available. """
no_pack_padded_seq = False
if rnn_type == "SRU":
# SRU doesn't support PackedSequence.
no_pack_padded_seq = True
rnn = onmt.mode... | 432 | 23.055556 | 60 | py |
roosterize | roosterize-master/onmt/utils/optimizers.py | """ Optimizers class """
import torch
import torch.optim as optim
from torch.nn.utils import clip_grad_norm_
import operator
import functools
from copy import copy
from math import sqrt
def build_torch_optimizer(model, opt):
"""Builds the PyTorch optimizer.
We use the default parameters for Adam that are sug... | 19,281 | 36.368217 | 79 | py |
roosterize | roosterize-master/onmt/utils/loss.py | """
This includes: LossComputeBase and the standard NMTLossCompute, and
sharded loss compute stuff.
"""
from __future__ import division
import torch
import torch.nn as nn
import torch.nn.functional as F
import onmt
from onmt.modules.sparse_losses import SparsemaxLoss
from onmt.modules.sparse_activations... | 12,991 | 37.324484 | 79 | py |
roosterize | roosterize-master/onmt/utils/misc.py | # -*- coding: utf-8 -*-
import torch
import random
import inspect
from itertools import islice
def split_corpus(path, shard_size):
with open(path, "rb") as f:
if shard_size <= 0:
yield f.readlines()
else:
while True:
shard = list(islice(f, shard_size))
... | 3,824 | 29.11811 | 78 | py |
roosterize | roosterize-master/onmt/utils/cnn_factory.py | """
Implementation of "Convolutional Sequence to Sequence Learning"
"""
import torch
import torch.nn as nn
import torch.nn.init as init
import onmt.modules
SCALE_WEIGHT = 0.5 ** 0.5
def shape_transform(x):
""" Tranform the size of the tensors to fit for conv input. """
return torch.unsqueeze(torch.transpose... | 1,620 | 28.472727 | 78 | py |
roosterize | roosterize-master/onmt/utils/statistics.py | """ Statistics calculation utility """
from __future__ import division
import time
import math
import sys
from onmt.utils.logging import logger
class Statistics(object):
"""
Accumulator for loss statistics.
Currently calculates:
* accuracy
* perplexity
* elapsed time
"""
def __init_... | 4,291 | 30.328467 | 79 | py |
roosterize | roosterize-master/onmt/utils/distributed.py | """ Pytorch Distributed utils
This piece of code was heavily inspired by the equivalent of Fairseq-py
https://github.com/pytorch/fairseq
"""
from __future__ import print_function
import math
import pickle
import torch.distributed
from onmt.utils.logging import logger
def is_master(opt, device_id):
ret... | 3,926 | 30.926829 | 77 | py |
roosterize | roosterize-master/onmt/utils/parse.py | import configargparse as cfargparse
import os
import torch
import onmt.opts as opts
from onmt.utils.logging import logger
class ArgumentParser(cfargparse.ArgumentParser):
def __init__(
self,
config_file_parser_class=cfargparse.YAMLConfigFileParser,
formatter_class=cfargparse.... | 5,644 | 39.321429 | 78 | py |
MCUa-Model | MCUa-Model-main/test_mean_std.py | from src import *
from src import datasets1, datasets2
import numpy as np
from src import models_N1, networks_N1
from src import models_N2, networks_N2
from src import models_N3, networks_N3
from src import models_P4, networks_P4
from src import models_P5, networks_P5
from src import models_P6, networks_P6
from src i... | 15,948 | 35.002257 | 162 | py |
MCUa-Model | MCUa-Model-main/train.py | from src import *
from src import datasets1, datasets2
from src import models_N1,networks_N1
#from src import models_N2,networks_N2
#from src import models_N3,networks_N3
#from src import models_P4,networks_P4
#from src import models_P5,networks_P5
#from src import models_P6,networks_P6
#from src import models1_N1,ne... | 6,470 | 39.192547 | 88 | py |
MCUa-Model | MCUa-Model-main/src/networks_P6.py | import numpy as np
import torch.nn as nn
import torch.nn.functional as F
import torchvision
class BaseNetwork(nn.Module):
def __init__(self, name, channels=1):
super(BaseNetwork, self).__init__()
self._name = name
self._channels = channels
def name(self):
return self._name
... | 3,724 | 31.391304 | 103 | py |
MCUa-Model | MCUa-Model-main/src/networks1_N1.py | import numpy as np
import torch.nn as nn
import torch.nn.functional as F
import torchvision
class BaseNetwork1(nn.Module):
def __init__(self, name, channels=1):
super(BaseNetwork1, self).__init__()
self._name = name
self._channels = channels
def name(self):
return self._name
... | 3,769 | 32.070175 | 103 | py |
MCUa-Model | MCUa-Model-main/src/models1_P4.py | import time
import time
import ntpath
import datetime
import matplotlib.pyplot as plt
import torch.optim as optim
import torch.nn.functional as F
import matplotlib.pyplot as ply
from torch.autograd import Variable
from torch.utils.data import DataLoader, TensorDataset
from sklearn.metrics import roc_curve, auc
from skl... | 24,366 | 37.073438 | 170 | py |
MCUa-Model | MCUa-Model-main/src/networks1_P5.py | import numpy as np
import torch.nn as nn
import torch.nn.functional as F
import torchvision
class BaseNetwork1(nn.Module):
def __init__(self, name, channels=1):
super(BaseNetwork1, self).__init__()
self._name = name
self._channels = channels
def name(self):
return self._name
... | 3,769 | 32.070175 | 103 | py |
MCUa-Model | MCUa-Model-main/src/models2_P6.py | import time
import time
import ntpath
import datetime
import matplotlib.pyplot as plt
import torch.optim as optim
import torch.nn.functional as F
import matplotlib.pyplot as ply
from torch.autograd import Variable
from torch.utils.data import DataLoader, TensorDataset
from sklearn.metrics import roc_curve, auc
from skl... | 21,689 | 35.270903 | 170 | py |
MCUa-Model | MCUa-Model-main/src/models1_N2.py | import time
import time
import ntpath
import datetime
import matplotlib.pyplot as plt
import torch.optim as optim
import torch.nn.functional as F
import matplotlib.pyplot as ply
from torch.autograd import Variable
from torch.utils.data import DataLoader, TensorDataset
from sklearn.metrics import roc_curve, auc
from skl... | 23,132 | 36.251208 | 170 | py |
MCUa-Model | MCUa-Model-main/src/models_P5.py | import time
import time
import ntpath
import datetime
import matplotlib.pyplot as plt
import torch.optim as optim
import torch.nn.functional as F
import matplotlib.pyplot as ply
from torch.autograd import Variable
from torch.utils.data import DataLoader, TensorDataset
from sklearn.metrics import roc_curve, auc
from skl... | 24,268 | 37.039185 | 170 | py |
MCUa-Model | MCUa-Model-main/src/networks1_P8.py | import numpy as np
import torch.nn as nn
import torch.nn.functional as F
import torchvision
class BaseNetwork1(nn.Module):
def __init__(self, name, channels=1):
super(BaseNetwork1, self).__init__()
self._name = name
self._channels = channels
def name(self):
return self._name
... | 3,763 | 31.730435 | 103 | py |
MCUa-Model | MCUa-Model-main/src/models_P4.py | import time
import time
import ntpath
import datetime
import matplotlib.pyplot as plt
import torch.optim as optim
import torch.nn.functional as F
import matplotlib.pyplot as ply
from torch.autograd import Variable
from torch.utils.data import DataLoader, TensorDataset
from sklearn.metrics import roc_curve, auc
from skl... | 23,733 | 36.613312 | 170 | py |
MCUa-Model | MCUa-Model-main/src/models2_P4.py | import time
import time
import ntpath
import datetime
import matplotlib.pyplot as plt
import torch.optim as optim
import torch.nn.functional as F
import matplotlib.pyplot as ply
from torch.autograd import Variable
from torch.utils.data import DataLoader, TensorDataset
from sklearn.metrics import roc_curve, auc
from skl... | 23,041 | 36.164516 | 170 | py |
MCUa-Model | MCUa-Model-main/src/networks_N3.py | import numpy as np
import torch.nn as nn
import torch.nn.functional as F
import torchvision
class BaseNetwork(nn.Module):
def __init__(self, name, channels=1):
super(BaseNetwork, self).__init__()
self._name = name
self._channels = channels
def name(self):
return self._name
... | 3,718 | 31.622807 | 103 | py |
MCUa-Model | MCUa-Model-main/src/networks1_P4.py | import numpy as np
import torch.nn as nn
import torch.nn.functional as F
import torchvision
class BaseNetwork1(nn.Module):
def __init__(self, name, channels=1):
super(BaseNetwork1, self).__init__()
self._name = name
self._channels = channels
def name(self):
return self._name
... | 3,760 | 32.283186 | 103 | py |
MCUa-Model | MCUa-Model-main/src/models1_N1.py | import time
import time
import ntpath
import datetime
import matplotlib.pyplot as plt
import torch.optim as optim
import torch.nn.functional as F
import matplotlib.pyplot as ply
from torch.autograd import Variable
from torch.utils.data import DataLoader, TensorDataset
from sklearn.metrics import roc_curve, auc
from skl... | 23,339 | 36.95122 | 170 | py |
MCUa-Model | MCUa-Model-main/src/networks_N2.py | import numpy as np
import torch.nn as nn
import torch.nn.functional as F
import torchvision
class BaseNetwork(nn.Module):
def __init__(self, name, channels=1):
super(BaseNetwork, self).__init__()
self._name = name
self._channels = channels
def name(self):
return self._name
... | 3,718 | 31.622807 | 103 | py |
MCUa-Model | MCUa-Model-main/src/networks2_N3.py | import numpy as np
import torch.nn as nn
import torch.nn.functional as F
import torchvision
class BaseNetwork2(nn.Module):
def __init__(self, name, channels=1):
super(BaseNetwork2, self).__init__()
self._name = name
self._channels = channels
def name(self):
return self._name
... | 3,677 | 31.263158 | 103 | py |
MCUa-Model | MCUa-Model-main/src/models_N1.py | import time
import time
import ntpath
import datetime
import matplotlib.pyplot as plt
import torch.optim as optim
import torch.nn.functional as F
import matplotlib.pyplot as ply
from torch.autograd import Variable
from torch.utils.data import DataLoader, TensorDataset
from sklearn.metrics import roc_curve, auc
from skl... | 23,536 | 36.539075 | 170 | py |
MCUa-Model | MCUa-Model-main/src/models1_P8.py | import time
import time
import ntpath
import datetime
import matplotlib.pyplot as plt
import torch.optim as optim
import torch.nn.functional as F
import matplotlib.pyplot as ply
from torch.autograd import Variable
from torch.utils.data import DataLoader, TensorDataset
from sklearn.metrics import roc_curve, auc
from skl... | 22,251 | 35.780165 | 170 | py |
MCUa-Model | MCUa-Model-main/src/models2_P5.py | import time
import time
import ntpath
import datetime
import matplotlib.pyplot as plt
import torch.optim as optim
import torch.nn.functional as F
import matplotlib.pyplot as ply
from torch.autograd import Variable
from torch.utils.data import DataLoader, TensorDataset
from sklearn.metrics import roc_curve, auc
from skl... | 23,558 | 36.634185 | 170 | py |
MCUa-Model | MCUa-Model-main/src/models_N2.py | import time
import time
import ntpath
import datetime
import matplotlib.pyplot as plt
import torch.optim as optim
import torch.nn.functional as F
import matplotlib.pyplot as ply
from torch.autograd import Variable
from torch.utils.data import DataLoader, TensorDataset
from sklearn.metrics import roc_curve, auc
from skl... | 24,147 | 36.496894 | 170 | py |
MCUa-Model | MCUa-Model-main/src/networks_P5.py | import numpy as np
import torch.nn as nn
import torch.nn.functional as F
import torchvision
class BaseNetwork(nn.Module):
def __init__(self, name, channels=1):
super(BaseNetwork, self).__init__()
self._name = name
self._channels = channels
def name(self):
return self._name
... | 3,709 | 31.831858 | 103 | py |
MCUa-Model | MCUa-Model-main/src/models1_P6.py | import time
import time
import ntpath
import datetime
import matplotlib.pyplot as plt
import torch.optim as optim
import torch.nn.functional as F
import matplotlib.pyplot as ply
from torch.autograd import Variable
from torch.utils.data import DataLoader, TensorDataset
from sklearn.metrics import roc_curve, auc
from skl... | 22,678 | 36.05719 | 170 | py |
MCUa-Model | MCUa-Model-main/src/models1_P5.py | import time
import time
import ntpath
import datetime
import matplotlib.pyplot as plt
import torch.optim as optim
import torch.nn.functional as F
import matplotlib.pyplot as ply
from torch.autograd import Variable
from torch.utils.data import DataLoader, TensorDataset
from sklearn.metrics import roc_curve, auc
from skl... | 23,288 | 36.2624 | 170 | py |
MCUa-Model | MCUa-Model-main/src/datasets2.py | import os
import glob
import torch
import numpy as np
from PIL import Image, ImageEnhance
from torch.utils.data import Dataset
from torchvision.transforms import transforms
from .patch_extractor import PatchExtractor
LABELS = ['Normal', 'Benign', 'InSitu', 'Invasive']
#IMAGE_SIZE = (2048, 1536)
PATCH_SIZE = 224
clas... | 5,236 | 34.869863 | 166 | py |
MCUa-Model | MCUa-Model-main/src/networks2_P4.py | import numpy as np
import torch.nn as nn
import torch.nn.functional as F
import torchvision
class BaseNetwork2(nn.Module):
def __init__(self, name, channels=1):
super(BaseNetwork2, self).__init__()
self._name = name
self._channels = channels
def name(self):
return self._name
... | 3,677 | 31.263158 | 103 | py |
MCUa-Model | MCUa-Model-main/src/datasets.py | import os
import glob
import torch
import numpy as np
from PIL import Image, ImageEnhance
from torch.utils.data import Dataset
from torchvision.transforms import transforms
from .patch_extractor import PatchExtractor
LABELS = ['Normal', 'Benign', 'InSitu', 'Invasive']
#IMAGE_SIZE = (2048, 1536)
PATCH_SIZE = 224
clas... | 5,233 | 34.849315 | 166 | py |
MCUa-Model | MCUa-Model-main/src/networks2_P6.py | import numpy as np
import torch.nn as nn
import torch.nn.functional as F
import torchvision
class BaseNetwork2(nn.Module):
def __init__(self, name, channels=1):
super(BaseNetwork2, self).__init__()
self._name = name
self._channels = channels
def name(self):
return self._name
... | 3,665 | 31.442478 | 103 | py |
MCUa-Model | MCUa-Model-main/src/networks1_N2.py | import numpy as np
import torch.nn as nn
import torch.nn.functional as F
import torchvision
class BaseNetwork1(nn.Module):
def __init__(self, name, channels=1):
super(BaseNetwork1, self).__init__()
self._name = name
self._channels = channels
def name(self):
return self._name
... | 3,762 | 32.008772 | 103 | py |
MCUa-Model | MCUa-Model-main/src/networks1_P6.py | import numpy as np
import torch.nn as nn
import torch.nn.functional as F
import torchvision
class BaseNetwork1(nn.Module):
def __init__(self, name, channels=1):
super(BaseNetwork1, self).__init__()
self._name = name
self._channels = channels
def name(self):
return self._name
... | 3,762 | 32.008772 | 103 | py |
MCUa-Model | MCUa-Model-main/src/options.py | from __future__ import print_function
import os
import torch
import argparse
class ModelOptions:
def __init__(self):
parser = argparse.ArgumentParser(description='Classification of breast cancer histology')
parser.add_argument('--dataset-path', type=str, default='./dataset', help='dataset path (d... | 3,328 | 71.369565 | 175 | py |
MCUa-Model | MCUa-Model-main/src/models2_N2.py | import time
import time
import ntpath
import datetime
import matplotlib.pyplot as plt
import torch.optim as optim
import torch.nn.functional as F
import matplotlib.pyplot as ply
from torch.autograd import Variable
from torch.utils.data import DataLoader, TensorDataset
from sklearn.metrics import roc_curve, auc
from skl... | 23,612 | 36.010972 | 170 | py |
MCUa-Model | MCUa-Model-main/src/networks2_N1.py | import numpy as np
import torch.nn as nn
import torch.nn.functional as F
import torchvision
class BaseNetwork2(nn.Module):
def __init__(self, name, channels=1):
super(BaseNetwork2, self).__init__()
self._name = name
self._channels = channels
def name(self):
return self._name
... | 3,678 | 31.27193 | 103 | py |
MCUa-Model | MCUa-Model-main/src/models_N3.py | import time
import time
import ntpath
import datetime
import matplotlib.pyplot as plt
import torch.optim as optim
import torch.nn.functional as F
import matplotlib.pyplot as ply
from torch.autograd import Variable
from torch.utils.data import DataLoader, TensorDataset
from sklearn.metrics import roc_curve, auc
from skl... | 23,722 | 36.59588 | 170 | py |
MCUa-Model | MCUa-Model-main/src/networks2_N2.py | import numpy as np
import torch.nn as nn
import torch.nn.functional as F
import torchvision
class BaseNetwork2(nn.Module):
def __init__(self, name, channels=1):
super(BaseNetwork2, self).__init__()
self._name = name
self._channels = channels
def name(self):
return self._name
... | 3,677 | 31.263158 | 103 | py |
MCUa-Model | MCUa-Model-main/src/networks_P4.py | import numpy as np
import torch.nn as nn
import torch.nn.functional as F
import torchvision
class BaseNetwork(nn.Module):
def __init__(self, name, channels=1):
super(BaseNetwork, self).__init__()
self._name = name
self._channels = channels
def name(self):
return self._name
... | 3,709 | 31.831858 | 103 | py |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.