Skip to content

Commit 0f9f96d

Browse files
committed
Use LRU cache when getting POS tagger to avoid loading weights each time pos_tag() is called.
1 parent 27e49f7 commit 0f9f96d

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

nltk/tag/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@
6565
isort:skip_file
6666
"""
6767

68+
import functools
69+
6870
from nltk.tag.api import TaggerI
6971
from nltk.tag.util import str2tuple, tuple2str, untag
7072
from nltk.tag.sequential import (
@@ -100,6 +102,7 @@
100102
}
101103

102104

105+
@functools.lru_cache
103106
def _get_tagger(lang=None):
104107
if lang == "rus":
105108
tagger = PerceptronTagger(lang=lang)

0 commit comments

Comments
 (0)