Make 'data_or_width' two keyword args in Vectors.__init__

Previously the data and width options were one argument in Vectors,
which meant you couldn't say vectors = Vectors(strings, width=300).
It's better to have two keywords.
This commit is contained in:
Matthew Honnibal 2017-10-20 14:17:15 +02:00
parent 49895fbef6
commit ebecaddb76
2 changed files with 13 additions and 10 deletions

View File

@ -35,18 +35,18 @@ def vocab(en_vocab, vectors):
def test_init_vectors_with_data(strings, data):
v = Vectors(strings, data)
v = Vectors(strings, data=data)
assert v.shape == data.shape
def test_init_vectors_with_width(strings):
v = Vectors(strings, 3)
v = Vectors(strings, width=3)
for string in strings:
v.add(string)
assert v.shape == (len(strings), 3)
def test_get_vector(strings, data):
v = Vectors(strings, data)
v = Vectors(strings, data=data)
for string in strings:
v.add(string)
assert list(v[strings[0]]) == list(data[0])
@ -56,7 +56,7 @@ def test_get_vector(strings, data):
def test_set_vector(strings, data):
orig = data.copy()
v = Vectors(strings, data)
v = Vectors(strings, data=data)
for string in strings:
v.add(string)
assert list(v[strings[0]]) == list(orig[0])

View File

@ -12,7 +12,7 @@ p
p
| Create a new vector store. To keep the vector table empty, pass
| #[code data_or_width=0]. You can also create the vector table and add
| #[code width=0]. You can also create the vector table and add
| vectors one by one, or set the vector values directly on initialisation.
+aside-code("Example").
@ -21,11 +21,11 @@ p
empty_vectors = Vectors(StringStore())
vectors = Vectors([u'cat'], 300)
vectors = Vectors([u'cat'], width=300)
vectors[u'cat'] = numpy.random.uniform(-1, 1, (300,))
vector_table = numpy.zeros((3, 300), dtype='f')
vectors = Vectors(StringStore(), vector_table)
vectors = Vectors(StringStore(), data=vector_table)
+table(["Name", "Type", "Description"])
+row
@ -36,9 +36,12 @@ p
| that maps strings to hash values, and vice versa.
+row
+cell #[code data_or_width]
+cell #[code.u-break numpy.ndarray[ndim=1, dtype='float32']] or int
+cell Vector data or number of dimensions.
+cell #[code data]
+cell #[code.u-break numpy.ndarray[ndim=1, dtype='float32']]
+row
+cell #[code width]
+cell Number of dimensions.
+row("foot")
+cell returns