-
Notifications
You must be signed in to change notification settings - Fork 132
/
test_lesk_speed.py
34 lines (28 loc) · 1.28 KB
/
test_lesk_speed.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#!/usr/bin/env python -*- coding: utf-8 -*-
#
# Python Word Sense Disambiguation (pyWSD): WSD all-words lesk speed tests
#
# Copyright (C) 2014-2015 alvations
# URL:
# For license information, see LICENSE.md
from __future__ import print_function
import time
from nltk.corpus import brown
from pywsd.lesk import simple_lesk, original_lesk, cosine_lesk, adapted_lesk
from pywsd.allwords_wsd import disambiguate
print("======== TESTING all-words lesk (`from_cache=True`)===========")
start = time.time()
for sentence in brown.sents()[:10]:
sentence = " ".join(sentence)
disambiguate(sentence, simple_lesk, prefersNone=True, keepLemmas=True)
disambiguate(sentence, original_lesk)
disambiguate(sentence, adapted_lesk, keepLemmas=True)
print('Disambiguating 100 brown sentences took {} secs'.format(time.time() - start))
print("======== TESTING all-words lesk (`from_cache=False`)===========")
start = time.time()
for sentence in brown.sents()[:10]:
sentence = " ".join(sentence)
disambiguate(sentence, simple_lesk, prefersNone=True, keepLemmas=True, from_cache=False)
disambiguate(sentence, original_lesk, from_cache=False)
disambiguate(sentence, adapted_lesk, keepLemmas=True, from_cache=False)
print('Disambiguating 10 brown sentences took {} secs'.format(time.time() - start))