Esempio n. 1
0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

import random
import os
import copy
import numpy as np
import tensorflow as tf
from . import utils
from os.path import isdir, join

tf.NotDifferentiable("Spans")
tf.NotDifferentiable("Antecedents")
tf.NotDifferentiable("ExtractMentions")
tf.NotDifferentiable("DistanceBins")

seed = 5
tf.set_random_seed(seed)


class CorefModel(object):
    """
    End-to-end neural model for coreference resolution.
    Class that create model from https://homes.cs.washington.edu/~kentonl/pub/lhlz-emnlp.2017.pdf
    """
    def __init__(self, opt):
        """Initialize the class and model according to the given parameters in opt."""
Esempio n. 2
0
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import tensorflow as tf
from tensorflow.python import pywrap_tensorflow

coref_op_library = tf.load_op_library(
    "/scratch/sanjay/Improved-Coref/coref_kernels.so")

extract_spans = coref_op_library.extract_spans
tf.NotDifferentiable("ExtractSpans")
Esempio n. 3
0
"""Builds a DRAGNN graph for local training."""

import collections
import tensorflow as tf

from tensorflow.core.protobuf import saver_pb2
from tensorflow.python.platform import tf_logging as logging

from dragnn.protos import spec_pb2
from dragnn.python import component
from dragnn.python import composite_optimizer
from dragnn.python import dragnn_ops
from syntaxnet.util import check

try:
    tf.NotDifferentiable('ExtractFixedFeatures')
except KeyError, e:
    logging.info(str(e))


def _validate_grid_point(hyperparams, is_sub_optimizer=False):
    """Validates that a grid point's configuration is reasonable.

  Args:
    hyperparams (spec_pb2.GridPoint): Grid point to validate.
    is_sub_optimizer (bool): Whether this optimizer is a sub-optimizer of
      a composite optimizer.

  Raises:
    ValueError: If the grid point is not valid.
  """
Esempio n. 4
0
import os.path

import tensorflow as tf

__all__ = 'detection_matching'

this_path = os.path.dirname(os.path.realpath(__file__))
matching_module = tf.load_op_library(os.path.join(this_path,
                                                  'det_matching.so'))
tf.NotDifferentiable("DetectionMatching")

detection_matching = matching_module.detection_matching
Esempio n. 5
0
    model_proto: The sentencepiece model serialized proto.
                 Either `model_file` or `model_proto` must be set.
    reverse: Reverses the tokenized sequence (Default = false)
    name: The name argument that is passed to the op function.

  Returns:
    text: A 1D string tensor of decoded string.
  """

    return _gen_sentencepiece_processor_op.sentencepiece_decode(
        pieces,
        sequence_length,
        model_file=model_file,
        model_proto=model_proto,
        reverse=reverse,
        name=name)


# Adds an alias for encode_dense. Accepts the `encode` function.
encode = encode_dense
sparse_encode = encode_sparse
dense_encode = encode_dense

tf.NotDifferentiable('SentencepieceGetPieceSize')
tf.NotDifferentiable('SentencepieceIdToPiece')
tf.NotDifferentiable('SentencepiecePieceToId')
tf.NotDifferentiable('SentencepieceGetPieceType')
tf.NotDifferentiable('SentencepieceEncodeDense')
tf.NotDifferentiable('SentencepieceEncodeSparse')
tf.NotDifferentiable('SentencepieceDecode')
    left_context: Integer, number of preceding frames to attach to each frame.
    right_context: Integer, number of preceding frames to attach to each frame.
    frame_stride: Integer, M frames to skip over, where output[n] = frame[n*M].
    zero_padding: Bool, if left/right context is out-of-bounds, attach frame of
      zeroes. Otherwise, frame[0] or frame[size-1] will be copied.
    out_scale: Integer, divide all filterbanks by this number.
    out_type: DType, type of the output Tensor, defaults to UINT16.

  Returns:
    filterbanks: 2D Tensor, each row is a time frame, each column is a channel.

  Raises:
    ValueError: If the audio tensor is not explicitly a vector.
  """
    audio_shape = audio.get_shape()
    if audio_shape.ndims is None:
        raise ValueError(
            "Input to `AudioMicrofrontend` should have known rank.")
    if len(audio_shape) > 1:
        audio = tf.reshape(audio, [-1])

    return gen_audio_microfrontend_op.audio_microfrontend(
        audio, sample_rate, window_size, window_step, num_channels,
        upper_band_limit, lower_band_limit, smoothing_bits, even_smoothing,
        odd_smoothing, min_signal_remaining, enable_pcan, pcan_strength,
        pcan_offset, gain_bits, enable_log, scale_shift, left_context,
        right_context, frame_stride, zero_padding, out_scale, out_type)


tf.NotDifferentiable("AudioMicrofrontend")
Esempio n. 7
0
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
# ==============================================================================
"""Build structured parser models."""

import tensorflow as tf

from tensorflow.python.ops import control_flow_ops as cf
from tensorflow.python.ops import state_ops
from tensorflow.python.ops import tensor_array_ops

from syntaxnet import graph_builder
from syntaxnet.ops import gen_parser_ops

tf.NotDifferentiable('BeamParseReader')
tf.NotDifferentiable('BeamParser')
tf.NotDifferentiable('BeamParserOutput')


def AddCrossEntropy(batch_size, n):
    """Adds a cross entropy cost function."""
    cross_entropies = []

    def _Pass():
        return tf.constant(0, dtype=tf.float32, shape=[1])

    for beam_id in range(batch_size):
        beam_gold_slot = tf.reshape(
            tf.strided_slice(n['gold_slot'], [beam_id], [beam_id + 1]), [1])
Esempio n. 8
0
from graphcnn.helper import *
import tensorflow as tf
import numpy as np
import math
import os
import os.path
from tensorflow.contrib.layers.python.layers import utils
from tensorflow.python.framework import ops
from tensorflow.python.ops import array_ops
from tensorflow.python.ops import sparse_ops
import scipy.sparse
import pdb
tf.NotDifferentiable('Unique')
here = os.path.dirname(__file__) + '/util/sparse/'
if os.path.isfile(os.path.join(here, 'SparseConv.so')):
    _graphcnn_conv_sparse_module = tf.load_op_library(
        os.path.join(here, 'SparseConv.so'))
    _graphcnn_conv_sparse_grad_module = tf.load_op_library(
        os.path.join(here, 'SparseConvGrad.so'))

if os.path.isfile(os.path.join(here, 'SparseAverageVertexPool.so')):
    _graphcnn_avg_vertex_pool_sparse_module = tf.load_op_library(
        os.path.join(here, 'SparseAverageVertexPool.so'))
    _graphcnn_avg_vertex_pool_sparse_grad_module = tf.load_op_library(
        os.path.join(here, 'SparseAverageVertexPoolGrad.so'))

if os.path.isfile(os.path.join(here, 'SparseMaxVertexPool.so')):
    _graphcnn_max_vertex_pool_sparse_module = tf.load_op_library(
        os.path.join(here, 'SparseMaxVertexPool.so'))
    _graphcnn_max_vertex_pool_sparse_grad_module = tf.load_op_library(
        os.path.join(here, 'SparseMaxVertexPoolGrad.so'))
Esempio n. 9
0
def RegisterWeaverOp(op_name):
  tf.NotDifferentiable(op_name)
Esempio n. 10
0
import tensorflow as tf
import utils

extract_patches_module = tf.load_op_library('extract_patches_op/extract_patches.so')
extract_patches = extract_patches_module.extract_patches
tf.NotDifferentiable('ExtractPatches')


def align_reference_shape(reference_shape, reference_shape_bb, im, bb):
    def norm(x):
        return tf.sqrt(tf.reduce_sum(tf.square(x - tf.reduce_mean(x, 0))))

    ratio = norm(bb) / norm(reference_shape_bb)
    align_mean_shape = (reference_shape - tf.reduce_mean(reference_shape_bb, 0)) * ratio + tf.reduce_mean(bb, 0)
    new_size = tf.to_int32(tf.to_float(tf.shape(im)[:2]) / ratio)
    return tf.image.resize_bilinear(tf.expand_dims(im, 0), new_size)[0, :, :, :], align_mean_shape / ratio, ratio


class MDMModel:
    def __init__(
            self, images, shapes, inits,
            batch_size, num_iterations, num_patches, patch_shape, num_channels,
            is_training=True
    ):
        self.in_images = images
        self.in_shapes = shapes
        self.in_init_shapes = inits
        self.num_iterations = num_iterations
        self.num_patches = num_patches
        self.patch_shape = patch_shape
        self.num_channels = num_channels
Esempio n. 11
0
import tensorflow as tf
from tensorflow.python import pywrap_tensorflow

coref_op_library = tf.load_op_library("./coref_kernels.so")

spans = coref_op_library.spans
tf.NotDifferentiable("Spans")

regression = coref_op_library.regression
tf.NotDifferentiable("Regression")

memory = coref_op_library.memory
tf.NotDifferentiable("Memory")

tagging = coref_op_library.tagging
tf.NotDifferentiable("Tagging")

antecedents = coref_op_library.antecedents
tf.NotDifferentiable("Antecedents")

extract_mentions = coref_op_library.extract_mentions
tf.NotDifferentiable("ExtractMentions")

distance_bins = coref_op_library.distance_bins
tf.NotDifferentiable("DistanceBins")
from __future__ import absolute_import
from __future__ import division
from __future__ import print_function

import tensorflow as tf

coref_op_library = tf.load_op_library("./coref_kernels.so")

extract_spans = coref_op_library.extract_spans
tf.NotDifferentiable("ExtractSpans")

gold_scores = coref_op_library.gold_scores
tf.NotDifferentiable("GoldScores")

gold_scores_with_split_antecedents = coref_op_library.gold_scores_with_split_antecedents
tf.NotDifferentiable("GoldScoresWithSplitAntecedents")

distance_bins = coref_op_library.distance_bins
tf.NotDifferentiable("DistanceBins")

cluster_width_bins = coref_op_library.cluster_width_bins
tf.NotDifferentiable("ClusterWidthBins")

extract_antecedent_labels = coref_op_library.extract_antecedent_labels
tf.NotDifferentiable("ExtractAntecedentLabels")

oracle_clusters = coref_op_library.oracle_clusters
tf.NotDifferentiable("OracleClusters")