alex.ml package¶
Submodules¶
alex.ml.exceptions module¶
-
exception
alex.ml.exceptions.
FFNNException
[source]¶ Bases:
alex.AlexException
-
exception
alex.ml.exceptions.
NBListException
[source]¶ Bases:
alex.AlexException
alex.ml.features module¶
This module contains generic code for working with feature vectors (or, in general, collections of features).
-
class
alex.ml.features.
Abstracted
[source]¶ Bases:
object
-
instantiate
(type_, value, do_abstract=False)[source]¶ - Example: Let self represent
- da1(a1=T1:v1)&da2(a2=T2:v2)&da3(a3=T1:v3).
Calling self.instantiate(“T1”, “v1”) results in
da1(a1=T1)&da2(a2=v2)&da3(a3=v3) ..if do_abstract == False
da1(a1=T1)&da2(a2=v2)&da3(a3=T1_other) ..if do_abstract == True
Calling self.instantiate(“T1”, “x1”) results in
da1(a1=x1)&da2(a2=v2)&da3(a3=v3) ..if do_abstract == False
- da1(a1=T1_other)&da2(a2=v2)&da3(a3=T1_other)
- ..if do_abstract == True.
-
iter_typeval
()[source]¶ Iterates the abstracted items in self, yielding combined representations of the type and value of each such token. An abstract method of this class.
-
other_val
= '[OTHER]'¶
-
splitter
= '='¶
-
-
class
alex.ml.features.
Features
(*args, **kwargs)[source]¶ Bases:
object
A mostly abstract class representing features of an object.
- Attributes:
- features: mapping of the features to their values set: set of the features
-
get_feature_coords_vals
(feature_idxs)[source]¶ Builds the feature vector based on the provided mapping of features onto their indices. Returns the vector as a two lists, one of feature coordinates, one of feature values.
- Arguments:
- feature_idxs: a mapping { feature : feature index }
-
get_feature_vector
(feature_idxs)[source]¶ Builds the feature vector based on the provided mapping of features onto their indices.
- Arguments:
- feature_idxs: a mapping { feature : feature index }
-
classmethod
join
(feature_sets, distinguish=True)[source]¶ Joins a number of sets of features, keeping them distinct.
- Arguments:
- distinguish – whether to treat the feature sets as of different
- types (distinguish=True) or just merge features from them by adding their values (distinguish=False). Default is True.
Returns a new instance of JoinedFeatures.
-
class
alex.ml.features.
JoinedFeatures
(feature_sets)[source]¶ Bases:
alex.ml.features.Features
JoinedFeatures are indexed by tuples (feature_sets_index, feature) where feature_sets_index selects the required set of features. Sets of features are numbered with the same indices as they had in the list used to initialise JoinedFeatures.
- Attributes:
features: mapping { (feature_set_index, feature) : value of feature } set: set of the (feature_set_index, feature) tuples generic: mapping { (feature_set_index, abstracted_feature) :
generic_feature }- instantiable: mapping { feature : generic part of feature } for
- features from self.features.keys() that are abstracted
alex.ml.ffnn module¶
-
class
alex.ml.ffnn.
FFNN
[source]¶ Bases:
object
Implements simple feed-forward neural network with:
– input layer - activation function linear – hidden layers - activation function tanh – output layer - activation function softmax
-
add_layer
(w, b)[source]¶ Add next layer into the network.
Parameters: - w – next layer weights
- b – next layer biases
Returns: none
-
load
(file_name)[source]¶ Loads saved NN.
Parameters: file_name – file name of the saved NN Returns: None
-
predict
(input)[source]¶ Returns the output of the last layer.
- As it is output of a layer with softmax activation function, the output is a vector of probabilities of
- the classes being predicted.
Parameters: input – input vector for the first NN layer. Returns: return the output of the last activation layer
-
alex.ml.hypothesis module¶
This module collects classes representing the uncertainty about the actual value of a base type instance.
-
class
alex.ml.hypothesis.
ConfusionNetwork
[source]¶ Bases:
alex.ml.hypothesis.Hypothesis
Confusion network. In this representation, each fact breaks down into a sequence of elementary acts.
-
add_merge
(p, fact, combine=u'max')[source]¶ Add a fact and if it exists merge it according to the given combine strategy.
-
classmethod
from_fact
(fact)[source]¶ Constructs a deterministic confusion network that asserts the given `fact’. Note that `fact’ has to be an iterable of elementary acts.
-
merge
(conf_net, combine=u'max')[source]¶ Merges facts in the current and the given confusion networks.
- Arguments:
- combine – can be one of {‘new’, ‘max’, ‘add’, ‘arit’, ‘harm’}, and
- determines how two probabilities should be merged (default: ‘max’)
XXX As of now, we know that different values for the same slot are contradictory (and in general, the set of contradicting attr-value pairs could be larger). We should therefore consider them alternatives to each other.
-
-
class
alex.ml.hypothesis.
Hypothesis
[source]¶ Bases:
object
This is the base class for all forms of probabilistic hypotheses representations.
-
class
alex.ml.hypothesis.
NBList
[source]¶ Bases:
alex.ml.hypothesis.Hypothesis
This class represents the uncertainty using an n-best list.
When updating an N-best list, one should do the following.
- add utterances or parse a confusion network
- merge and normalise, in either order
-
add
(probability, fact)[source]¶ Finds the last hypothesis with a lower probability and inserts the new item before that one. Optimised for adding objects from the highest probability ones to the lowest probability ones.
alex.ml.logarithmetic module¶
-
alex.ml.logarithmetic.
add
(a, b)[source]¶ Computes pairwise addition of two vectors in the log domain.
This is equivalent to [a1+b1, a2+b2, ...] in the linear domain..
-
alex.ml.logarithmetic.
devide
(a, b)[source]¶ Computes pairwise division between vectors a and b in the log domain.
This is equivalent to [a1/b1, a2/b2, ...] in the linear domain.
-
alex.ml.logarithmetic.
dot
(a, b)[source]¶ Computes dot product in the log domain.
This is equivalent to a1*b1+a2*b2+... in the linear domain.
-
alex.ml.logarithmetic.
linear_to_log
(a)[source]¶ Converts a vector from the linear domain to the log domain.
-
alex.ml.logarithmetic.
log_to_linear
(a)[source]¶ Converts a vector from the log domain to the linear domain.
-
alex.ml.logarithmetic.
multiply
(a, b)[source]¶ Computes pairwise multiplication between vectors a and b in the log domain.
This is equivalent to [a1*b1, a2*b2, ...] in the linear domain.
-
alex.ml.logarithmetic.
normalise
(a)[source]¶ normalises the input probability vector to sum to one in the log domain.
This is equivalent to a/sum(a) in the linear domain.