Repository navigation
Refactor syllabification algorithm - #269
Conversation
|
@mmcauliffe Do we have a pinned minimum Python version that we are planning to support? I don't seem to see it in the code base, but the CI version is pinned to 3.9, which is why tests are failing rn. |
|
If we want this to replace |
|
@tonyhu-x We can probably bump the testing version to 3.11, since that's the current minimum version for conda forge: https://github.com/conda-forge/conda-forge-pinning-feedstock/blob/main/recipe/conda_build_config.yaml#L995-L999, which looks to be the version adding typing.LiteralString. I'll do a separate PR for it in case it causes any issues with the current codebase and you can pull that in. To address @massimolipari 's point, it might be better to have add a check for syllables being encoded on those functions and throw an exception if they haven't been? The call to |
|
Hmm, I don't think it's just a convenience thing, I'm pretty sure both those functions actually do require syllables to have already been encoded as is. |
|
Right they do require it, but I don't think scripts actually call |
|
Ah, yes we're saying the same thing then! I never got as far as figuring out why these functions call |
mmcauliffe
left a comment
There was a problem hiding this comment.
Left some comments but a couple of them are bigger points across the code.
For naming, we should stick to Max Onset as the name of the algorithm instead of Match Onset, since it's based on the Maximum Onset Principle in the literature. And then using Syllabfier or something a bit more condensed allows for adding it to the end of various algorithm names for class names (i.e. MaxOnsetSyllabifier, SonoritySyllabifier, etc).
For the casting of the query strings to LiteralString, is there a reason do that? I don't think the neo4j query function takes LiteralStrings specifically right? Sticking plain strings might simplify the query calls.
Finally just a couple of questions on implementation details:
- Did you do any time-based benchmarking of the new version versus old version? Probably need to run it more on larger datasets like the ones in stress testing to get tangible effects
- Did you play around with newer neo4j functionality to get rid of the speaker/discourse based processing? Same as above, would need a larger dataset for testing effectively
|
Merged #271 in for using 3.11 along with controlling it via a repo variable to bump it across all the workflows in the future, if you want to pull that into here, the pytest actions should pass now. |
Ok actually, looking at PolyglotDB/polyglotdb/corpus/syllabic.py Line 561 in fb93e6e enrich_syllables, not encode_syllables, where enrich_syllables is adding information taken from the phone labels to the syllables. And then encode_hierarchy is just updating the graph database so that it knows that "tone" or "stress" is available for query on syllables. So I don't think any modification is necessary here, just to close the loop.
|
|
No, sorry, I should have been more explicit. It's the PolyglotDB/polyglotdb/corpus/phonological.py Lines 114 to 160 in 2b823af |
2598f40 to
24f89a2
Compare
|
We also discussed stress testing, and agreed that it is a good idea to add syllabification-specific stress tests. I should investigate and set this up in the near future. |
This PR rewrites the
encode_syllablesfunction. The new function (encode_syllables_v2) uses dependency injection instead of hard-coding the syllabification algorithm. The function handles init, read/write operations, and hierarchy update, whereas the actual work to syllabify each word is handled by aSyllabificationAlgoobject.Currently, one
SyllabificationAlgoclass is implemented, namelyMatchOnset. This class is equivalent to the oldmaxonsetalgorithm, supporting both derived and custom onsets. Note, however, that the "custom" case is now the default, with derived onsets provided via an alternative initializerfrom_corpus().This PR also includes unit tests for
MatchOnsetand an equivalence test that ensures that the resulting graph from callingencode_syllables_v2is isomorphic to the one resulting fromencode_syllables.