matnets 3.2.1__tar.gz → 3.2.3__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: matnets
3
- Version: 3.2.1
3
+ Version: 3.2.3
4
4
  Summary: A small experimental neural network library where neurons are represented as matrices.
5
5
  License-Expression: MIT
6
6
  License-File: LICENSE
@@ -4,7 +4,7 @@ build-backend = "poetry.core.masonry.api"
4
4
 
5
5
  [project]
6
6
  name = "matnets"
7
- version = "3.2.1"
7
+ version = "3.2.3"
8
8
  description = "A small experimental neural network library where neurons are represented as matrices."
9
9
  readme = "docs/index.md"
10
10
  requires-python = ">=3.11"
@@ -3,6 +3,7 @@ from matnets.activations.exp import (
3
3
  sigmoidd,
4
4
  softplus,
5
5
  softplusd,
6
+ sss,
6
7
  sst,
7
8
  tanh,
8
9
  tanhd,
@@ -29,6 +30,7 @@ __all__ = [
29
30
  "sigmoidd",
30
31
  "softplus",
31
32
  "softplusd",
33
+ "sss",
32
34
  "sst",
33
35
  "tanh",
34
36
  "tanhd",
@@ -56,3 +56,16 @@ def sst(x: jax.Array) -> jax.Array:
56
56
  s = jnp.matmul(t, t)
57
57
  scale = float(n) ** -2
58
58
  return s * scale
59
+
60
+
61
+ def sss(x: jax.Array) -> jax.Array:
62
+ """Scaled squared sigmoid activation.
63
+
64
+ Applies element-wise sigmoid, squares the resulting matrices, and
65
+ scales them by n^-2 where n is the matrix dimension.
66
+ """
67
+ n = x.shape[-1]
68
+ t = jnn.sigmoid(x)
69
+ s = jnp.matmul(t, t)
70
+ scale = float(n) ** -2
71
+ return s * scale
@@ -30,17 +30,26 @@ def lstm_step(
30
30
  params: Mapping[str, MatrixParams],
31
31
  carry: tuple[Array, Array],
32
32
  x: Array,
33
+ *,
34
+ activations: tuple[Callable[[Array], Array], Callable[[Array], Array]] = (
35
+ jax.nn.sigmoid,
36
+ jnp.tanh,
37
+ ),
33
38
  ) -> tuple[tuple[Array, Array], Array]:
34
39
  """LSTM step using ``i``, ``f``, ``g``, and ``o`` dense gate params."""
35
40
 
36
41
  h, c = carry
42
+ gate_act, state_act = activations
37
43
  combined = jnp.concatenate([h, x], axis=0)
38
- i = dense(params["i"], combined, jax.nn.sigmoid)
39
- f = dense(params["f"], combined, jax.nn.sigmoid)
40
- g = dense(params["g"], combined, jnp.tanh)
41
- o = dense(params["o"], combined, jax.nn.sigmoid)
42
- next_c = f * c + i * g
43
- next_h = o * jnp.tanh(next_c)
44
+
45
+ i = dense(params["i"], combined, gate_act)
46
+ f = dense(params["f"], combined, gate_act)
47
+ g = dense(params["g"], combined, state_act)
48
+ o = dense(params["o"], combined, gate_act)
49
+
50
+ next_c = jnp.matmul(f, c) + jnp.matmul(i, g)
51
+ next_h = jnp.matmul(o, state_act(next_c))
52
+
44
53
  return (next_h, next_c), next_h
45
54
 
46
55
 
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes
File without changes