# Path: dsenser/svd/svdbase.py
# class SVDBaseSenser(NNBaseSenser):
#     """Abstract class for disambiguating relation senses.
# 
#     Attributes:
#       n_y (int): number of distinct classes
# 
#     """
# 
#     def _init_nn(self):
#         """Initialize neural network.
# 
#         """
#         self.intm_dim = max(MIN_DIM, self.ndim - (self.ndim - self.n_y) / 2)
#         # indices of word embeddings
#         self.W_INDICES_ARG1 = TT.ivector(name="W_INDICES_ARG1")
#         self.W_INDICES_ARG2 = TT.ivector(name="W_INDICES_ARG2")
#         # connective's index
#         self.CONN_INDEX = TT.iscalar(name="CONN_INDEX")
#         # initialize the matrix of word embeddings
#         self.init_w_emb()
#         # word embeddings of the arguments
#         self.EMB_ARG1 = self.W_EMB[self.W_INDICES_ARG1]
#         self.EMB_ARG2 = self.W_EMB[self.W_INDICES_ARG2]
#         # connective's embedding
#         self._init_conn_emb()
#         self.EMB_CONN = self.CONN_EMB[self.CONN_INDEX]
#         # perform matrix decomposition
#         _, _, self.ARG1 = TT.nlinalg.svd(self.EMB_ARG1,
#                                          full_matrices=True)
#         _, _, self.ARG2 = TT.nlinalg.svd(self.EMB_ARG2,
#                                          full_matrices=True)
#         self.ARG_DIFF = self.ARG1 - self.ARG2
#         # map decomposed matrices to the intermediate level
#         self.ARG_DIFF2I = theano.shared(value=HE_UNIFORM((self.ndim, 1)),
#                                         name="ARG_DIFF2I")
#         self.arg_diff_bias = theano.shared(value=HE_UNIFORM((1, self.ndim)),
#                                            name="arg_diff_bias")
#         self._params.extend([self.ARG_DIFF2I, self.arg_diff_bias])
#         self.ARGS = (TT.dot(self.ARG_DIFF, self.ARG_DIFF2I).T +
#                      self.arg_diff_bias).flatten()
#         # define final units
#         self.I = TT.concatenate((self.ARGS, self.EMB_CONN))
#         self.I2Y = theano.shared(value=HE_UNIFORM((self.n_y,
#                                                    self.ndim + self.intm_dim)),
#                                  name="I2Y")
#         self.y_bias = theano.shared(value=HE_UNIFORM((1, self.n_y)),
#                                     name="y_bias")
#         self._params.extend([self.I2Y, self.y_bias])
#         self.Y_pred = TT.nnet.softmax(TT.dot(self.I2Y, self.I).T + self.y_bias)
#         # initialize cost and optimization functions
#         self.Y_gold = TT.vector(name="Y_gold")
#         self._cost = TT.sum((self.Y_pred - self.Y_gold) ** 2)
#         self._dev_cost = TT.sum((self.Y_pred - self.Y_gold) ** 2)
#         self._pred_class = TT.argmax(self.Y_pred)
#         grads = TT.grad(self._cost, wrt=self._params)
#         self._init_funcs(grads)
# 
# Path: dsenser/utils.py
# class timeit(object):
#     """Decorator class for measuring time performance.
# 
#     Attributes:
#       msg (str): message to be printed on method invocation
# 
#     """
# 
#     def __init__(self, a_msg):
#         """Class constructor.
# 
#         Args:
#           a_msg (str): debug message to print
# 
#         """
#         self.msg = a_msg
# 
#     def __call__(self, a_func):
#         """Decorator function.
# 
#         Args:
#           a_func (method): decorated method
# 
#         Returns:
#           method: wrapped method
# 
#         """
#         def _wrapper(*args, **kwargs):
#             print(self.msg + " started", file=sys.stderr)
#             start_time = datetime.utcnow()
#             a_func(*args, **kwargs)
#             end_time = datetime.utcnow()
#             time_delta = (end_time - start_time).total_seconds()
#             print(self.msg + " finished ({:.2f} sec)".format(time_delta),
#                   file=sys.stderr)
#         return wraps(a_func)(_wrapper)


from dsenser.svd.svdbase import SVDBaseSenser
from dsenser.utils import timeit
#!/usr/bin/env python
# -*- coding: utf-8; mode: python; -*-

"""Module providing class for SVD sense disambiguation.

Attributes:
  SVDImplicitSenser (class):
    class that predicts senses of implicit relations

"""

##################################################################
# Imports
from __future__ import absolute_import, print_function


##################################################################
# Variables and Constants


##################################################################
# Classes
class SVDImplicitSenser(SVDBaseSenser):
    """Class for disambiguating implicit discourse relations.

    """


# Path: dsenser/svd/svdbase.py
# class SVDBaseSenser(NNBaseSenser):
#     """Abstract class for disambiguating relation senses.
# 
#     Attributes:
#       n_y (int): number of distinct classes
# 
#     """
# 
#     def _init_nn(self):
#         """Initialize neural network.
# 
#         """
#         self.intm_dim = max(MIN_DIM, self.ndim - (self.ndim - self.n_y) / 2)
#         # indices of word embeddings
#         self.W_INDICES_ARG1 = TT.ivector(name="W_INDICES_ARG1")
#         self.W_INDICES_ARG2 = TT.ivector(name="W_INDICES_ARG2")
#         # connective's index
#         self.CONN_INDEX = TT.iscalar(name="CONN_INDEX")
#         # initialize the matrix of word embeddings
#         self.init_w_emb()
#         # word embeddings of the arguments
#         self.EMB_ARG1 = self.W_EMB[self.W_INDICES_ARG1]
#         self.EMB_ARG2 = self.W_EMB[self.W_INDICES_ARG2]
#         # connective's embedding
#         self._init_conn_emb()
#         self.EMB_CONN = self.CONN_EMB[self.CONN_INDEX]
#         # perform matrix decomposition
#         _, _, self.ARG1 = TT.nlinalg.svd(self.EMB_ARG1,
#                                          full_matrices=True)
#         _, _, self.ARG2 = TT.nlinalg.svd(self.EMB_ARG2,
#                                          full_matrices=True)
#         self.ARG_DIFF = self.ARG1 - self.ARG2
#         # map decomposed matrices to the intermediate level
#         self.ARG_DIFF2I = theano.shared(value=HE_UNIFORM((self.ndim, 1)),
#                                         name="ARG_DIFF2I")
#         self.arg_diff_bias = theano.shared(value=HE_UNIFORM((1, self.ndim)),
#                                            name="arg_diff_bias")
#         self._params.extend([self.ARG_DIFF2I, self.arg_diff_bias])
#         self.ARGS = (TT.dot(self.ARG_DIFF, self.ARG_DIFF2I).T +
#                      self.arg_diff_bias).flatten()
#         # define final units
#         self.I = TT.concatenate((self.ARGS, self.EMB_CONN))
#         self.I2Y = theano.shared(value=HE_UNIFORM((self.n_y,
#                                                    self.ndim + self.intm_dim)),
#                                  name="I2Y")
#         self.y_bias = theano.shared(value=HE_UNIFORM((1, self.n_y)),
#                                     name="y_bias")
#         self._params.extend([self.I2Y, self.y_bias])
#         self.Y_pred = TT.nnet.softmax(TT.dot(self.I2Y, self.I).T + self.y_bias)
#         # initialize cost and optimization functions
#         self.Y_gold = TT.vector(name="Y_gold")
#         self._cost = TT.sum((self.Y_pred - self.Y_gold) ** 2)
#         self._dev_cost = TT.sum((self.Y_pred - self.Y_gold) ** 2)
#         self._pred_class = TT.argmax(self.Y_pred)
#         grads = TT.grad(self._cost, wrt=self._params)
#         self._init_funcs(grads)
# 
# Path: dsenser/utils.py
# class timeit(object):
#     """Decorator class for measuring time performance.
# 
#     Attributes:
#       msg (str): message to be printed on method invocation
# 
#     """
# 
#     def __init__(self, a_msg):
#         """Class constructor.
# 
#         Args:
#           a_msg (str): debug message to print
# 
#         """
#         self.msg = a_msg
# 
#     def __call__(self, a_func):
#         """Decorator function.
# 
#         Args:
#           a_func (method): decorated method
# 
#         Returns:
#           method: wrapped method
# 
#         """
#         def _wrapper(*args, **kwargs):
#             print(self.msg + " started", file=sys.stderr)
#             start_time = datetime.utcnow()
#             a_func(*args, **kwargs)
#             end_time = datetime.utcnow()
#             time_delta = (end_time - start_time).total_seconds()
#             print(self.msg + " finished ({:.2f} sec)".format(time_delta),
#                   file=sys.stderr)
#         return wraps(a_func)(_wrapper)


# Path: dsenser/svd/implicit.py
from dsenser.svd.svdbase import SVDBaseSenser
from dsenser.utils import timeit

#!/usr/bin/env python
# -*- coding: utf-8; mode: python; -*-

"""Module providing class for SVD sense disambiguation.

Attributes:
  SVDImplicitSenser (class):
    class that predicts senses of implicit relations

"""

##################################################################
# Imports
from __future__ import absolute_import, print_function


##################################################################
# Variables and Constants


##################################################################
# Classes
class SVDImplicitSenser(SVDBaseSenser):
    """Class for disambiguating implicit discourse relations.

    """


    @timeit("Training implicit SVD classifier...")