PanPhon

raw JSON →
0.22.2 verified Mon Apr 27 auth: no python

Tools for using the International Phonetic Alphabet (IPA) with phonological features. Supports feature extraction, segment similarity, alignment, and manipulation of Unicode IPA strings. Current version 0.22.2, release cadence irregular.

pip install panphon
error ImportError: No module named 'panphon.editdistance'
cause The `editdistance` module was removed in version 0.19. Use `panphon.distance` instead.
fix
Use from panphon.distance import Distance and call methods like Distance().dolgo_prime_distance(...).
error YAML load error.
cause Deprecated YAML.load call in older versions (fixed in 0.19). Update to 0.19+ or use safe loader.
fix
Upgrade to panphon 0.19 or later: pip install --upgrade panphon.
gotcha FeatureTable() loads a default feature set. If you need a custom set, pass a file path. The default is based on the 'panphon' bundle (SPE features plus extensions).
fix Use FeatureTable('path/to/features.yaml') to load custom features.
deprecated The `panphon.editdistance` module and its functions (e.g., `dolgo_prime_distance`) are deprecated in favor of `panphon.distance.Distance` class methods.
fix Replace `from panphon.editdistance import dolgo_prime_distance` with `from panphon.distance import Distance; Distance().dolgo_prime_distance(...)`.
gotcha The `word_fts` method returns a list of feature vectors for each segment, not a single tensor. Iterate over the list to get individual segment vectors.
fix Use `for vec in ft.word_fts('hello'):` to process each segment.

Load feature table, get feature vectors, compute segment distances.

from panphon import FeatureTable

ft = FeatureTable()
# Feature vector for a segment
vec = ft.word_fts('p')
print(vec)
# Segment similarity
sim = ft.hamming_distance('p', 'b')
print(sim)
# Feature-based edit distance
from panphon.distance import Distance
d = Distance()
print(d.dolgo_prime_distance('pan', 'ban'))