Working with Distances
In [1]:
from phones import PhoneCollection
pc = PhoneCollection()
Across Languages¶
We can also compute the distance between phones across all languages, in which case the phone features are averaged.
In [2]:
pc.get_mean_phone_distance("ʉ", "u")
Out[2]:
Distance Weights¶
All methods involving distances also allow to specify a distance vector to give features more or less weight.
In [3]:
# find the name of the feature at index 3
pc.source.feature_columns[3]
Out[3]:
In [4]:
import numpy as np
# set feature weight of "back" to 0
weights = np.ones(len(pc.source.feature_columns))
weights[3] = 0
pc.get_mean_phone_distance("ʉ", "u", distance_weights=tuple(weights))
Out[4]:
By Vector¶
Another option is to find the closest phone to a particular phone vector.
In [5]:
pc.get_closest_by_vector(
[-1., 0., 1., -1., 0., -1., -1., 1., -1., 0., 0., 1., -1.,
0., -1., -1., -1., 0., -1., -1., 1., -1., -1., 1., -1., -1.,
0., -1., 1., -1., -1., 0., 1., -1., 0., 0., -1.]
)[:3]
Out[5]:
Allophone Distance¶
Another method allows you to compute the mean allophone distance of all phones and their allophones. This might be useful to evaluate how well the features represent the phones.
It is recommended you do this on a subset of languages or use show_progress=True
as this can take a long time.
In [6]:
pc.langs(["eng", "deu"]).get_mean_allophone_distance()
Out[6]: