Skip to content

Commit 177ccfa

Browse files
committed
Fix docstrings for API doc generation.
1 parent 6b4a989 commit 177ccfa

File tree

4 files changed

+43
-18
lines changed

4 files changed

+43
-18
lines changed

src/finalfusion/compat/text.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,10 @@ def load_text(file: Union[str, bytes, int, PathLike]) -> Embeddings:
4848
l2-normalized per default and the corresponding norms are stored in the Norms.
4949
5050
Expects a file with utf-8 encoded lines with:
51-
* word at the start of the line
52-
* followed by whitespace
53-
* followed by whitespace separated vector components
51+
52+
* word at the start of the line
53+
* followed by whitespace
54+
* followed by whitespace separated vector components
5455
5556
Parameters
5657
----------

src/finalfusion/compat/word2vec.py

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ def load_word2vec(file: Union[str, bytes, int, PathLike]) -> Embeddings:
5454

5555
def write_word2vec(file: Union[str, bytes, int, PathLike],
5656
embeddings: Embeddings):
57-
"""
57+
r"""
5858
Write embeddings in word2vec binary format.
5959
6060
If the embeddings are not compatible with the w2v format (e.g. include a SubwordVocab), only
@@ -67,10 +67,11 @@ def write_word2vec(file: Union[str, bytes, int, PathLike],
6767
This is followed by the embeddings.
6868
6969
Each embedding consists of:
70-
* utf-8 encoded word
71-
* single space `' '` following the word
72-
* `cols` single-precision floating point numbers
73-
* `'\n'` newline at the end of each line.
70+
71+
* utf-8 encoded word
72+
* single space ``' '`` following the word
73+
* ``cols`` single-precision floating point numbers
74+
* ``'\n'`` newline at the end of each line.
7475
7576
Parameters
7677
----------

src/finalfusion/embeddings.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -37,14 +37,18 @@ class Embeddings: # pylint: disable=too-many-instance-attributes
3737
3838
Embeddings are composed of the 4 chunk types:
3939
40-
1. :class:`~finalfusion.storage.Storage` *(required)*:
40+
1. :class:`~finalfusion.storage.storage.Storage` *(required)*:
41+
4142
* :class:`~finalfusion.storage.ndarray.NdArray`
4243
* :class:`~finalfusion.storage.ndarray.QuantizedArray`
43-
2. :class:`~finalfusion.vocab.Vocab` *(required)*:
44-
* :class:`~finalfusion.vocab.simple_vocab.SimpleVocab`,
44+
45+
2. :class:`~finalfusion.vocab.vocab.Vocab` *(required)*:
46+
47+
* :class:`~finalfusion.vocab.simple_vocab.SimpleVocab`
4548
* :class:`~finalfusion.vocab.subword.FinalfusionBucketVocab`
4649
* :class:`~finalfusion.vocab.subword.FastTextVocab`
4750
* :class:`~finalfusion.vocab.subword.ExplicitVocab`
51+
4852
3. :class:`~finalfusion.metadata.Metadata`
4953
4. :class:`~finalfusion.norms.Norms`
5054
@@ -81,7 +85,7 @@ def __init__(self,
8185
Initializes Embeddings with the given chunks.
8286
8387
:Conditions:
84-
The following conditions need to hold if the respective chunks are passed.
88+
The following conditions need to hold if the respective chunks are passed:
8589
8690
* Chunks need to have the expected type.
8791
* ``vocab.idx_bound == storage.shape[0]``
@@ -103,6 +107,7 @@ def __init__(self,
103107
------
104108
AssertionError
105109
If any of the conditions don't hold.
110+
106111
"""
107112
Embeddings._check_requirements(storage, vocab, norms, metadata)
108113
self._storage = storage
@@ -112,7 +117,7 @@ def __init__(self,
112117

113118
def __getitem__(self, item: str) -> np.ndarray:
114119
"""
115-
Returns an embeddings.
120+
Returns an embedding.
116121
117122
Parameters
118123
----------
@@ -347,10 +352,11 @@ def chunks(self) -> List[Chunk]:
347352
Get the Embeddings Chunks as a list.
348353
349354
The Chunks are ordered in the expected serialization order:
350-
1. Metadata (optional)
351-
2. Vocabulary
352-
3. Storage
353-
4. Norms (optional)
355+
356+
1. Metadata (optional)
357+
2. Vocabulary
358+
3. Storage
359+
4. Norms (optional)
354360
355361
Returns
356362
-------
@@ -435,7 +441,7 @@ def analogy( # pylint: disable=too-many-arguments
435441
query `word1` is to `word2` as `word3` is to `?`. More concretely,
436442
it searches embeddings that are similar to:
437443
438-
*embedding(word2) - embedding(word1) + embedding(word3)*
444+
``embedding(word2) - embedding(word1) + embedding(word3)``
439445
440446
Words specified in ``skip`` are not considered as answers. If ``skip``
441447
is None, the query words ``word1``, ``word2`` and ``word3`` are

src/finalfusion/storage/ndarray.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,23 @@ class NdArray(np.ndarray, Storage):
2020
Array storage.
2121
2222
Wraps an numpy matrix, either in-memory or memory-mapped.
23+
24+
Examples
25+
--------
26+
>>> storage = NdArray(np.array([[1., 0.5], [0.5, 1.], [0.3, 0.4]],
27+
... dtype=np.float32))
28+
>>> # slicing an NdArray returns a storage backed by the same array
29+
>>> storage[:2]
30+
NdArray([[1. , 0.5],
31+
[0.5, 1. ]], dtype=float32)
32+
>>> # NdArray storage can be treated as numpy arrays
33+
>>> storage * 2
34+
NdArray([[2. , 1. ],
35+
[1. , 2. ],
36+
[0.6, 0.8]], dtype=float32)
37+
>>> # Indexing with arrays, lists or ints returns numpy.ndarray
38+
>>> storage[0]
39+
array([1. , 0.5], dtype=float32)
2340
"""
2441
def __new__(cls, array: np.ndarray):
2542
"""

0 commit comments

Comments
 (0)