Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve example/template.py for speed, functionality, and readability #100

Closed

Conversation

tianjianjiang
Copy link

@tianjianjiang tianjianjiang commented Feb 26, 2018

  • python 2-to-3 compatibility
  • eliminate redundant function calls
    • especially regex replace calls
  • use pool.imap for multi-process
  • supporting scale-decorated template, e.g. U:%x[0,0]:-1.5
  • applying several linting guidelines

This revision trades memory footprint and multicore for speed.
For example, when processing 50k sentences of some Japanese corpus, if the original version spent 3 minutes and 37 seconds, the revised version only needed 20 seconds with 4 processes.

@tianjianjiang tianjianjiang force-pushed the improve_example_template_py branch 2 times, most recently from 15a8384 to 4627dd0 Compare February 26, 2018 15:03
@tianjianjiang tianjianjiang changed the title Revised example/template.py Improve example/template.py for speed, functionality, and readability Feb 26, 2018
- python 2-to-3 compatibility
- eliminate redundant function calls
  - especially regex replace calls
- use pool.imap for multi-process
- supporting scale-decorated template, e.g. `U:%x[0,0]:-1.5`
- applying several linting guidelines
@tianjianjiang tianjianjiang force-pushed the improve_example_template_py branch from 4627dd0 to 8864ac2 Compare February 26, 2018 15:06
@cynthia
Copy link
Collaborator

cynthia commented Jun 6, 2019

I think this patch has good parts and unnecessary parts.

Redundant calls, Py3 compatibility and cleaner/idiomatic code is something I think is needed. That said, the parts I don't agree is the performance patches. I strongly believe that example code should have a strong focus on it's pedagogical properties; nothing more, nothing less. Introducing extra complexity for the sake of performance in example code increases the learning curve, and seems like it would bring in more harm than gain.

@cynthia
Copy link
Collaborator

cynthia commented Jun 6, 2019

See also: #109

@tianjianjiang
Copy link
Author

@cynthia I don't have strong opinions about this PR. It is indeed nice to keep one and only one strong focus for each example.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants