Skip to content

Commit 8cb6c64

Browse files
Use 0-vector for OOV in StaticVectors (#336)
* Use 0-vector for OOV in StaticVectors * chore: update mac os images on azure (#325) * Bump version for all macos azure pipelines Co-authored-by: Justin DuJardin <[email protected]>
1 parent 5611957 commit 8cb6c64

File tree

3 files changed

+12
-7
lines changed

3 files changed

+12
-7
lines changed

azure-pipelines.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
imageName: 'ubuntu-16.04'
1414
python.version: '2.7.17'
1515
Python27Mac:
16-
imageName: 'macos-10.13'
16+
imageName: 'macos-10.15'
1717
python.version: '2.7'
1818
Python35Linux:
1919
imageName: 'ubuntu-16.04'
@@ -22,7 +22,7 @@ jobs:
2222
imageName: 'vs2017-win2016'
2323
python.version: '3.5'
2424
Python35Mac:
25-
imageName: 'macos-10.13'
25+
imageName: 'macos-10.15'
2626
python.version: '3.5'
2727
Python36Linux:
2828
imageName: 'ubuntu-16.04'
@@ -31,7 +31,7 @@ jobs:
3131
imageName: 'vs2017-win2016'
3232
python.version: '3.6'
3333
Python36Mac:
34-
imageName: 'macos-10.13'
34+
imageName: 'macos-10.15'
3535
python.version: '3.6'
3636
Python37Linux:
3737
imageName: 'ubuntu-16.04'
@@ -40,7 +40,7 @@ jobs:
4040
imageName: 'vs2017-win2016'
4141
python.version: '3.7'
4242
Python37Mac:
43-
imageName: 'macos-10.13'
43+
imageName: 'macos-10.15'
4444
python.version: '3.7'
4545
Python38Linux:
4646
imageName: 'ubuntu-16.04'
@@ -49,7 +49,7 @@ jobs:
4949
imageName: 'vs2017-win2016'
5050
python.version: '3.8'
5151
Python38Mac:
52-
imageName: 'macos-10.13'
52+
imageName: 'macos-10.15'
5353
python.version: '3.8'
5454
maxParallel: 4
5555
pool:

thinc/about.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# https://github.com/pypa/warehouse/blob/master/warehouse/__about__.py
55

66
__name__ = "thinc"
7-
__version__ = "7.4.0.dev2"
7+
__version__ = "7.4.1"
88
__summary__ = "Practical Machine Learning for NLP"
99
__uri__ = "https://github.com/explosion/thinc"
1010
__author__ = "Matthew Honnibal"

thinc/neural/_classes/static_vectors.py

+6-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,10 @@ def begin_update(self, ids, drop=0.0):
5858
if ids.ndim >= 2:
5959
ids = self.ops.xp.ascontiguousarray(ids[:, self.column])
6060
vector_table = self.get_vectors()
61-
vectors = vector_table[ids * (ids < vector_table.shape[0])]
61+
# create a mask for OOV vectors
62+
non_oov = ids < vector_table.shape[0]
63+
# initially use row 0 for OOV vectors
64+
vectors = vector_table[ids * non_oov]
6265
vectors = self.ops.xp.ascontiguousarray(vectors)
6366
assert vectors.shape[0] == ids.shape[0]
6467

@@ -74,4 +77,6 @@ def finish_update(gradients, sgd=None):
7477
mask = self.ops.get_dropout_mask((dotted.shape[1],), drop)
7578
if mask is not None:
7679
dotted *= mask
80+
# replace OOV vectors with zeros
81+
dotted *= self.ops.xp.zeros(dotted.shape, dtype=bool) | non_oov[:, None]
7782
return dotted, finish_update

0 commit comments

Comments
 (0)