Skip to content

Commit cf2203a

Browse files
committed
Add float list features in ItemSequence
- New class FloatFeatures defined in `pycrfsuite._float_features` - Useful for adding word embedding features - Wrap the word embedding list of float values with FloatFeatures class - The api supports the existing extraction of features from nested dicts. - Added test case in `tests/test_itemsequence.py` Example usage: ``` import pycrfsuite from pycrfsuite._float_features import FloatFeatures as FF seq = pycrfsuite.ItemSequence([ {"w2v": FF([1., 2., 3.])}, {"w2v": FF([-1., 5, 4.])} ]) ```
1 parent 720334f commit cf2203a

File tree

4 files changed

+2167
-1688
lines changed

4 files changed

+2167
-1688
lines changed

pycrfsuite/_float_features.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from __future__ import print_function, absolute_import
2+
3+
4+
class FloatFeatures(object):
5+
def __init__(self, values):
6+
if not isinstance(values, list):
7+
raise ValueError("Values should be an instance of list()")
8+
try:
9+
self.values = [float(v) for v in values]
10+
except ValueError:
11+
print("All elements in values should be castable to type float.", file=sys.stderr)
12+
raise
13+
except:
14+
print("Unexpected error:", sys.exc_info()[0])
15+
raise

0 commit comments

Comments
 (0)