def StaticVectors( nO: Optional[int] = None, vectors: Optional[Floats2d] = None, *, column: Optional[int] = None, dropout: Optional[float] = None, init_W: Callable = glorot_uniform_init, ) -> Model[InT, OutT]: attrs: Dict[str, Any] = {"column": column, "vectors": Unserializable(vectors)} if dropout is not None: attrs["dropout_rate"] = dropout model = Model( # type: ignore "static_vectors", forward, init=partial(init, init_W), params={"W": None}, attrs=attrs, dims={"nM": None, "nV": None, "nO": nO}, ) if column is not None: # This is equivalent to array[:, column]. What you're actually doing # there is passing in a tuple: array[(:, column)], except in the context # of array indexing, the ":" creates an object slice(0, None). # So array[:, column] is array.__getitem__(slice(0), column). model = chain(ints_getitem((slice(0, None), column)), model) model.attrs["column"] = column return cast(Model[InT, OutT], model)
def StaticVectors( nO: Optional[int] = None, nM: Optional[int] = None, *, dropout: Optional[float] = None, init_W: Callable = glorot_uniform_init, key_attr: str = "ORTH" ) -> Model[List[Doc], Ragged]: """Embed Doc objects with their vocab's vectors table, applying a learned linear projection to control the dimensionality. If a dropout rate is specified, the dropout is applied per dimension over the whole batch. """ return Model( "static_vectors", forward, init=partial(init, init_W), params={"W": None}, attrs={"key_attr": key_attr, "dropout_rate": dropout}, dims={"nO": nO, "nM": nM}, )
def configure_test_initializer(b: int = 1) -> Callable[[int], int]: return partial(test_initializer, b=b)