⚡️ Speed up function sentence_count by 59%
          #4080
        
          
      
                
     Merged
            
            
          
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
Saurabh's comments - The changes look good, especially because they have been rigorously tested with a variety of cases, which makes me feel confident
📄 59% (0.59x) speedup for
sentence_countinunstructured/partition/text_type.py⏱️ Runtime :
190 milliseconds→119 milliseconds(best of39runs)📝 Explanation and details
Major speedups.
If you wish to maximize compatibility with sentences containing non-whitespace-separable tokens (e.g. CJK languages), consider further optimization on the token counting line as needed for your domain. Otherwise,
str.split()after punctuation removal suffices and is far faster than a full NLP tokenizer.✅ Correctness verification report:
⚙️ Existing Unit Tests and Runtime
partition/test_text_type.py::test_item_titlespartition/test_text_type.py::test_sentence_counttest_tracer_py__replay_test_0.py::test_unstructured_partition_text_type_sentence_counttest_tracer_py__replay_test_2.py::test_unstructured_partition_text_type_sentence_counttest_tracer_py__replay_test_3.py::test_unstructured_partition_text_type_sentence_count🌀 Generated Regression Tests and Runtime
To edit these changes
git checkout codeflash/optimize-sentence_count-mcglwwcnand push.