tensor_model.bend checks
raw source on the hub · import stelliferous@0.0.2.0/tensor_model.bend as Tensor_model
Models: a step computes with tensors it takes by name from a store, so a network reads as one step after another and its weights are loaded once.
4 imports
import Base import ./tensor.bend as Tensors import ./tensor_layout.bend as Layout import ./tensor_file.bend as Files
Types
type Store source · line 11 · raw
Type
EmptyStore
Entry@name:String -> @tensor:Tensor -> @rest:Store -> Store
Definitions
def Tensor source · line 8 · raw
Type
def Model source · line 16 · raw
@A:Type -> Type
A step: given the store, a value and the store that remains.
def Model.pure source · line 19 · raw
@-A:Type -> @value:A -> Model(A)
def Model.next source · line 22 · raw
@-A:Type -> @-B:Type -> @pair:Pair(A, Store) -> @next:(@_:A -> Model(B)) -> Pair(B, Store)
def Model.bind source · line 26 · raw
@-A:Type -> @-B:Type -> @step:Model(A) -> @next:(@_:A -> Model(B)) -> Model(B)
def missing source · line 29 · raw
@+name:String -> Tensor
def passed source · line 32 · raw
@name:String -> @tensor:Tensor -> @pair:Pair(Tensor, Store) -> Pair(Tensor, Store)
def scan source · line 36 · raw
@rest:Store -> @same:Bool -> @+name:String -> @tensor:Tensor -> @+wanted:String -> Pair(Tensor, Store)
def taken source · line 43 · raw
@store:Store -> @+wanted:String -> Pair(Tensor, Store)
def take source · line 50 · raw
@+name:String -> Model(Tensor)
The tensor of that name leaves the store. A name that is not there gives a failed tensor.
def kept source · line 53 · raw
@+name:String -> @pair:Pair(Tensor, Tensor) -> @store:Store -> Pair(Tensor, Store)
def keep source · line 58 · raw
@+name:String -> @tensor:Tensor -> Model(Tensor)
Puts a copy under the name, for a later take, and gives the tensor back.
def run source · line 61 · raw
@-A:Type -> @step:Model(A) -> @store:Store -> Pair(A, Store)
def value source · line 64 · raw
@-A:Type -> @pair:Pair(A, Store) -> A
def result source · line 69 · raw
@-A:Type -> @step:Model(A) -> @store:Store -> A
Runs the steps on the store and gives the result; what remains in the store is dropped.
def joined source · line 72 · raw
@+name:String -> @first:Tensor -> @second:Tensor -> @rest:Pair(Store, Store) -> Pair(Store, Store)
def copied_entry source · line 76 · raw
@+name:String -> @pair:Pair(Tensor, Tensor) -> @rest:Pair(Store, Store) -> Pair(Store, Store)
def copy source · line 81 · raw
@store:Store -> Pair(Store, Store)
Two stores with the same tensors, to run a model more than once.
def entry source · line 88 · raw
@+name:String -> @tensor:Tensor -> @store:Store -> Store
def load_each source · line 91 · raw
@names:List<&2, String> -> @+folder:String -> IO(Store)
def named source · line 103 · raw
@text:Result<&1, &1, Pair(U32, String), String> -> @+folder:String -> IO(Store)
def listed source · line 108 · raw
@read:Pair(File, Result<&1, &1, Pair(U32, String), String>) -> @+folder:String -> IO(Store)
def opened source · line 114 · raw
@result:Result<&1, &1, Pair(U32, String), File> -> @+folder:String -> IO(Store)
def load source · line 123 · raw
@+folder:String -> IO(Store)
A folder without names.txt gives an empty store; every take then fails by name.
def named_rest source · line 130 · raw
@+name:String -> @tensor:Tensor -> @pair:Pair(Store, String) -> Pair(Store, String)
def first source · line 135 · raw
@written:Pair(File, Result<&1, &1, Pair(U32, String), Unit>) -> File
def names source · line 139 · raw
@store:Store -> Pair(Store, String)
def save_each source · line 144 · raw
@store:Store -> @+folder:String -> IO(Store)
def listing source · line 153 · raw
@result:Result<&1, &1, Pair(U32, String), File> -> @text:String -> IO(Unit)
def save_listed source · line 161 · raw
@pair:Pair(Store, String) -> @+folder:String -> IO(Store)
def save source · line 169 · raw
@+folder:String -> @store:Store -> IO(Store)
Gives the store back; a tensor that could not be written comes back failed.