Table Of Contents

This Page

composition Package

composition_model Module

Created on Oct 5, 2012

@author: georgianadinu

class composes.composition.composition_model.CompositionModel

Bases: object

Parent class of the composition models.

compose(data, arg_space)

Uses a composition model to compose elements.

Args:

data: data to be composed. List of tuples, each containing 3 strings: (arg1, arg2, composed_phrase). arg1 and arg2 are the elements to be composed and composed_phrase is the string associated to their composition.

arg_space: argument space(s). Space object or a tuple of two Space objects (e.g. my_space, or (my_space1, my_space2)). If two spaces are provided, arg1 elements of data are interpreted in space1, and arg2 in space2.

Returns:
composed space: a new object of type Space, containing the phrases obtained through composition.
composed_id2column = None

List of strings, the column strings of the resulted composed space.

export(filename)

Prints the parameters of the composition model to file.

Args:
filename: output filename, string

Prints the parameters of the compositional model in an appropriate format, specific to each model.

classmethod extract_arg_spaces(arg_space)

TO BE MOVED TO A UTILS MODULE!

get_name()
name

String, name of the composition model.

train(train_data, arg_space, phrase_space)

Trains a composition model and sets its learned parameters.

Args:

train_data: list of string tuples. Each tuple contains 3 string elements: (arg1, arg2, phrase).

arg_space: argument space(s). Space object or a tuple of two Space objects (e.g. my_space, or (my_space1, my_space2)). If two spaces are provided, arg1 elements of train data are interpreted in space1, and arg2 in space2.

phrase space: phrase space, of type Space.

Calls the specific training routine of the current composition model. Training tuples which contain strings not found in their respective spaces are ignored.

The id2column attribute of the resulted composed space is set to be equal to that of the phrase space given as an input.

valid_data_to_lists(data, (row2id1, row2id2, row2id3))

TO BE MOVED TO A UTILS MODULE!

dilation Module

Created on Oct 15, 2012

@author: georgianadinu

class composes.composition.dilation.Dilation(lambda_=None)

Bases: composes.composition.composition_model.CompositionModel

Implements the dilation compositional model:

\(\vec{p} = (\vec{u} \cdot \vec{u}) \vec{v} + (\lambda - 1) (\vec{u} \cdot \vec{v}) \vec{u}\)

where \(\vec{p}\) is the vector of the composed phrase, \(\vec{u}, \vec{v}\) the vectors of the components and \(\lambda\) is a scalar.

get_lambda()

full_additive Module

Created on Oct 5, 2012

@author: georgianadinu

class composes.composition.full_additive.FullAdditive(**kwargs)

Bases: composes.composition.composition_model.CompositionModel

Implements the full additive compositional model:

\(\vec{p} = A \vec{u} + B \vec{v}\)

where \(\vec{p}\) is the vector of the composed phrase, \(\vec{u}, \vec{v}\), the vectors of the components and \(A\), \(B\) are two matrices.

get_mat_a_t()
get_mat_b_t()
get_regression_learner()
mat_a_t

Transpose of matrix A parameter, of type Matrix.

mat_b_t

Transpose of matrix B parameter, of type Matrix.

regression_learner

Regression method to be used in training, of type RegressionLearner. Default is LstsqRegressionLearner.

set_regression_learner(regression_learner)

lexical_function Module

Created on Oct 11, 2012

@author: georgianadinu

class composes.composition.lexical_function.LexicalFunction(**kwargs)

Bases: composes.composition.composition_model.CompositionModel

Implements the lexical function compositional model.

\(\vec{p} = U \vec{v}\)

where \(\vec{p}\) is the vector of the composed phrase, \(U\) is the matrix representation of the first component (the lexical function) and \(\vec{v}\) is the vector representation of the second component

MIN_SAMPLES

Minimal number of samples for each training instance. Default 3.

compose(data, arg_space)

Uses a lexical function composition model to compose elements.

Args:

data: data to be composed. List of tuples, each containing 3 strings: (function_word, arg, composed_phrase). function_word and arg are the elements to be composed and composed_phrase is the string associated to their composition. function_word elements are interpreted in self.function_space.

arg_space: argument space, of type Space. arg elements of data are interpreted in this space.

Returns:
composed space: a new object of type Space, containing the phrases obtained through composition.
function_space

Function space parameter, containing the lexical functions, of type Space. Can be set through training or through initialization, default None.

get_function_space()
get_has_intercept()
get_min_samples()
get_regression_learner()
has_intercept

Has intercept parameter, boolean. If True, then the function_space is assumed to contain intercept. Can be set through training or through initialization, default is assumed to be False.

regression_learner

Regression method to be used in training, of type RegressionLearner. Default is RidgeRegressionLearner(param=1).

set_min_samples(min_samples)
set_regression_learner(regression_learner)
train(train_data, arg_space, phrase_space)

Trains a lexical function composition model to learn a function space and sets the function_space parameter.

Args:

train_data: list of string tuples. Each tuple contains 3 string elements: (function_word, arg, phrase).

arg_space: argument space, of type Space. arg elements of train data are interpreted in this space.

phrase space: phrase space, of type Space. phrase elements of the train data are interpreted in this space.

Training tuples which contain strings not found in their respective spaces are ignored. Function words containing less than _MIN_SAMPLES training instances are ignored. For example, if _MIN_SAMPLES=2 and function word “red” occurs in only one phrase, “red” is ignored.

The id2column attribute of the resulted composed space is set to be equal to that of the phrase space given as an input.

multiplicative Module

Created on Oct 5, 2012

@author: georgianadinu

class composes.composition.multiplicative.Multiplicative

Bases: composes.composition.composition_model.CompositionModel

Implements the component-wise multiplication compositional model:

\(\vec{p} = \vec{u} \cdot \vec{v}\)

where \(\vec{p}\) is the vector of the composed phrase and \(\vec{u}, \vec{v}\) are the vectors of the components.

\(\vec{u} \cdot \vec{v} = (u_1v_1,...,u_nv_n)\)

export(filename)

Current multiplicative model cannot be exported, it has no parameters.

train()

Current multiplicative model cannot be trained, it has no parameters.

weighted_additive Module

Created on Oct 5, 2012

@author: georgianadinu

class composes.composition.weighted_additive.WeightedAdditive(alpha=None, beta=None)

Bases: composes.composition.composition_model.CompositionModel

Implements weighted additive compositional model:

\(\vec{p} = \alpha \vec{u} + \beta \vec{v}\)

where \(\vec{p}\) is the vector of the composed phrase and \(\vec{u}, \vec{v}\) are the vectors of the components

When \(\alpha=\beta=0.5\) the model performs simple vector addition.

alpha

Alpha parameter, default 0.5.

beta

Beta parameter, default 0.5.

get_alpha()
get_beta()