Skip to content

Commit 697cb66

Browse files
committed
MFS working baseline and scorer
1 parent 791d7d6 commit 697cb66

File tree

5 files changed

+37
-42
lines changed

5 files changed

+37
-42
lines changed

MFS Baseline.ipynb

Lines changed: 2 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -4,47 +4,7 @@
44
"cell_type": "code",
55
"execution_count": 1,
66
"metadata": {},
7-
"outputs": [
8-
{
9-
"name": "stderr",
10-
"output_type": "stream",
11-
"text": [
12-
"/home/kanishka/anaconda3/lib/python3.7/site-packages/sklearn/feature_extraction/image.py:167: DeprecationWarning: `np.int` is a deprecated alias for the builtin `int`. To silence this warning, use `int` by itself. Doing this will not modify any behavior and is safe. When replacing `np.int`, you may wish to use e.g. `np.int64` or `np.int32` to specify the precision. If you wish to review your current use, check the release note link for additional information.\n",
13-
"Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
14-
" dtype=np.int):\n",
15-
"/home/kanishka/anaconda3/lib/python3.7/site-packages/sklearn/linear_model/least_angle.py:35: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\n",
16-
"Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
17-
" eps=np.finfo(np.float).eps,\n",
18-
"/home/kanishka/anaconda3/lib/python3.7/site-packages/sklearn/linear_model/least_angle.py:597: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\n",
19-
"Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
20-
" eps=np.finfo(np.float).eps, copy_X=True, fit_path=True,\n",
21-
"/home/kanishka/anaconda3/lib/python3.7/site-packages/sklearn/linear_model/least_angle.py:836: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\n",
22-
"Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
23-
" eps=np.finfo(np.float).eps, copy_X=True, fit_path=True,\n",
24-
"/home/kanishka/anaconda3/lib/python3.7/site-packages/sklearn/linear_model/least_angle.py:862: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\n",
25-
"Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
26-
" eps=np.finfo(np.float).eps, positive=False):\n",
27-
"/home/kanishka/anaconda3/lib/python3.7/site-packages/sklearn/linear_model/least_angle.py:1097: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\n",
28-
"Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
29-
" max_n_alphas=1000, n_jobs=None, eps=np.finfo(np.float).eps,\n",
30-
"/home/kanishka/anaconda3/lib/python3.7/site-packages/sklearn/linear_model/least_angle.py:1344: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\n",
31-
"Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
32-
" max_n_alphas=1000, n_jobs=None, eps=np.finfo(np.float).eps,\n",
33-
"/home/kanishka/anaconda3/lib/python3.7/site-packages/sklearn/linear_model/least_angle.py:1480: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\n",
34-
"Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
35-
" eps=np.finfo(np.float).eps, copy_X=True, positive=False):\n",
36-
"/home/kanishka/anaconda3/lib/python3.7/site-packages/sklearn/linear_model/randomized_l1.py:152: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\n",
37-
"Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
38-
" precompute=False, eps=np.finfo(np.float).eps,\n",
39-
"/home/kanishka/anaconda3/lib/python3.7/site-packages/sklearn/linear_model/randomized_l1.py:320: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\n",
40-
"Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
41-
" eps=np.finfo(np.float).eps, random_state=None,\n",
42-
"/home/kanishka/anaconda3/lib/python3.7/site-packages/sklearn/linear_model/randomized_l1.py:580: DeprecationWarning: `np.float` is a deprecated alias for the builtin `float`. To silence this warning, use `float` by itself. Doing this will not modify any behavior and is safe. If you specifically wanted the numpy scalar type, use `np.float64` here.\n",
43-
"Deprecated in NumPy 1.20; for more details and guidance: https://numpy.org/devdocs/release/1.20.0-notes.html#deprecations\n",
44-
" eps=4 * np.finfo(np.float).eps, n_jobs=None,\n"
45-
]
46-
}
47-
],
7+
"outputs": [],
488
"source": [
499
"from nltk.corpus import wordnet as wn\n",
5010
"from collections import defaultdict\n",
@@ -247,7 +207,7 @@
247207
"name": "python",
248208
"nbconvert_exporter": "python",
249209
"pygments_lexer": "ipython3",
250-
"version": "3.7.1"
210+
"version": "3.8.3"
251211
}
252212
},
253213
"nbformat": 4,

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ This script converts the datasets into jsonl files with the following format for
3434

3535
```json
3636
{
37+
"id": "id as mentioned in wsd datasets.",
3738
"word": "<the word>",
3839
"start": "<start index of the span>",
3940
"end": "<end index of the span>",

Scorer.class

3.22 KB
Binary file not shown.

evaluate.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
'''
2+
Replicate Scorer.java but also include POS level results.
3+
'''

mfs_baseline.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import argparse
2+
from nltk.corpus import wordnet as wn
3+
from collections import defaultdict
4+
import json
5+
6+
datasets = ['ALL', 'sem']
7+
8+
def wn_first(lemma, pos = None):
9+
for l in wn.synsets(lemma, pos)[0].lemmas():
10+
key = l.key()
11+
if key.startswith('{}%'.format(lemma)):
12+
res = key
13+
break
14+
else:
15+
res = ''
16+
return res
17+
18+
pos = {
19+
'VERB': 'v',
20+
'NOUN': 'n',
21+
'ADJ': 'a',
22+
'ADV': 'r'
23+
}
24+
25+
with open(f'data/outputs/{args.dataset}_mfs.txt', 'w') as fw:
26+
with open('data/jsonl/{args.dataset}.jsonl', 'r') as f:
27+
for line in f:
28+
items = json.loads(line)
29+
mfs = wn_first(items['lemma'], pos[items['pos']])
30+
out = f'{items["id"]} {mfs}\n'
31+
fw.write(out)

0 commit comments

Comments
 (0)