-
Notifications
You must be signed in to change notification settings - Fork 34
Vector #17
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Vector #17
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -102,6 +102,8 @@ def decode_string(v, encoding="utf-8"): | |
| return unicode(v) | ||
|
|
||
|
|
||
| # TODO use one of these (rather than copy and paste in each file) | ||
| # ... if we really have to use any at all | ||
| def encode_string(v, encoding="utf-8"): | ||
| """Returns the given value as a Python byte string (if possible).""" | ||
| if isinstance(encoding, basestring): | ||
|
|
@@ -113,7 +115,12 @@ def encode_string(v, encoding="utf-8"): | |
| except: | ||
| pass | ||
| return v | ||
| return str(v) | ||
| if isinstance(v, bytes): | ||
| return v | ||
| else: | ||
| # TODO Is this ever the correct behaviour (see coverage) | ||
| raise ValueError() | ||
| #return str(v) | ||
|
|
||
| decode_utf8 = decode_string | ||
| encode_utf8 = encode_string | ||
|
|
@@ -3478,10 +3485,17 @@ def _train(self): | |
| H2 = dict((w, i + 1) for i, w in enumerate(self.classes)) | ||
| # Class reversed hash. | ||
| H3 = dict((i + 1, w) for i, w in enumerate(self.classes)) | ||
|
|
||
| # Hashed vectors. | ||
| x = map(lambda v: dict(map(lambda k: (H1[k], v[k]), v)), M) | ||
| x = list(map(lambda v: dict(map(lambda k: (H1[k], v[k]), v)), M)) | ||
| # TODO use this more efficient version? | ||
| # x = [dict(((H1[k], v[k]), v) for k in v) for v in M] | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. confusingly this causes incorrect results (on python 2 and 3)... it looks the same to me!! |
||
|
|
||
| # Hashed classes. | ||
| y = map(lambda v: H2[v[0]], self._vectors) | ||
| y = list(map(lambda v: H2[v[0]], self._vectors)) | ||
| # TODO use this more efficient version? | ||
| # y = [H2[v[0]] for v in self._vectors] | ||
|
|
||
| # For linear SVC, use LIBLINEAR which is faster. | ||
| # For kernel SVC, use LIBSVM. | ||
| if self.extension == LIBLINEAR: | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -189,7 +189,6 @@ def encode_string(v, encoding="utf-8"): | |
| """Returns the given value as a Python byte string (if possible).""" | ||
| if isinstance(encoding, basestring): | ||
| encoding = ((encoding,),) + (("windows-1252",), ("utf-8", "ignore")) | ||
| if isinstance(v, unicode): | ||
| for e in encoding: | ||
| try: | ||
| return v.encode(*e) | ||
|
|
@@ -698,7 +697,7 @@ def redirect(self, timeout=10): | |
| return self.__dict__["_redirect"] or None | ||
|
|
||
| def __str__(self): | ||
| return bytestring(self.string) | ||
| return self._string | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IIRC without this change there was an infinite loop / recursion. |
||
|
|
||
| def __unicode__(self): | ||
| # The string representation includes the query attributes with HTTP | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@tom-de-smedt these functions aren't quite right (before), as if you passed a bytes e.g.
b"a"it became'b"a"'. Python 3 is much less forgiving!