Fast n-gram calculation

后端 未结 3 1741
谎友^
谎友^ 2020-12-02 12:47

I\'m using NLTK to search for n-grams in a corpus but it\'s taking a very long time in some cases. I\'ve noticed calculating n-grams isn\'t an uncommon feature in other pack

3条回答
  •  盖世英雄少女心
    2020-12-02 13:16

    You might find a pythonic, elegant and fast ngram generation function using zip and splat (*) operator here :

    def find_ngrams(input_list, n):
      return zip(*[input_list[i:] for i in range(n)])
    

提交回复
热议问题