box-key / cyzil

A tool for fast and in-depth analysis of sequence generation model in Cython
Apache License 2.0
1 stars 0 forks source link

Optimize code #3

Closed box-key closed 4 years ago

box-key commented 4 years ago

If the sentence length is less than n gram order, it should skip the following loop. https://github.com/box-key/cyzil/blob/9907a51a815daea610e1dfb1d3fb2e4db7971304/src/bleu.pyx#L40

box-key commented 4 years ago

Also, this if statement seems redundant as the condition is passed into min function.

https://github.com/box-key/cyzil/blob/9907a51a815daea610e1dfb1d3fb2e4db7971304/src/bleu.pyx#L26

I can change this code to:

c2 = m2.count(t1)
if c2:
  overlap[t1] = min(c1, c2)
box-key commented 4 years ago

I ended up using map.find() instead of map.count() because the time complexity of map.find() is O(1) whereas the time complexity of map.count() is O(n).