chipiron.players.boardevaluators.neural_networks.models package
Submodules
chipiron.players.boardevaluators.neural_networks.models.multi_layer_perceptron module
This module defines the neural network model NetPP2D2_2_PRELU.
The NetPP2D2_2_PRELU class is a subclass of ChiNN and implements the forward pass of the neural network. It consists of two fully connected layers with PReLU activation functions.
- chipiron.players.boardevaluators.neural_networks.models.multi_layer_perceptron.__init__()
Initializes the NetPP2D2_2_PRELU model.
- forward(x
torch.Tensor) -> torch.Tensor: Performs the forward pass of the neural network.
- init_weights(file
str) -> None: Initializes the weights of the model.
- chipiron.players.boardevaluators.neural_networks.models.multi_layer_perceptron.print_param() None
Prints the parameters of the model.
- print_input(input
torch.Tensor) -> None: Prints the input tensor.
- Helper Functions:
print_piece_param(i: int, vec: torch.Tensor) -> None: Prints the parameters of a specific piece.
- class chipiron.players.boardevaluators.neural_networks.models.multi_layer_perceptron.MultiLayerPerceptron(args: MultiLayerPerceptronArgs)[source]
Bases:
ChiNNNeural network model for board evaluation using 2D2_2_PRELU architecture.
- Variables:
fc1 (nn.Linear) – The first fully connected layer.
relu_1 (nn.PReLU) – The first PReLU activation function.
fc2 (nn.Linear) – The second fully connected layer.
tanh (nn.Tanh) – The tanh activation function.
- forward(x: Tensor) Tensor[source]
Forward pass of the neural network.
- Parameters:
x (torch.Tensor) – The input tensor.
- Returns:
The output tensor.
- Return type:
torch.Tensor
- log_readable_model_weights_to_file(file_path: str) None[source]
Writes the model weights and biases into a YAML file.
- Parameters:
file_path (str) – The path where the YAML file will be saved.
- class chipiron.players.boardevaluators.neural_networks.models.multi_layer_perceptron.MultiLayerPerceptronArgs(type: Literal[<NNModelType.MultiLayerPerceptron: 'multi_layer_perceptron'>], number_neurons_per_layer: list[int], list_of_activation_functions: list[chipiron.players.boardevaluators.neural_networks.NNModelType.ActivationFunctionType])[source]
Bases:
object- list_of_activation_functions: list[chipiron.players.boardevaluators.neural_networks.NNModelType.ActivationFunctionType]
- number_neurons_per_layer: list[int]
- type: MultiLayerPerceptron: 'multi_layer_perceptron'>]
- chipiron.players.boardevaluators.neural_networks.models.multi_layer_perceptron.build_sequential(layers: list[int], activations: list[chipiron.players.boardevaluators.neural_networks.NNModelType.ActivationFunctionType]) Sequential[source]
- chipiron.players.boardevaluators.neural_networks.models.multi_layer_perceptron.extract_sequential_model_data(model: Sequential) Dict[str, Any][source]
Extracts the weights and biases from a Sequential model in a layered dictionary format.
- Parameters:
model (nn.Sequential) – The Sequential model to extract from.
- Returns:
A dictionary with layer names as keys and parameter data as values.
- Return type:
Dict[str, Any]
- chipiron.players.boardevaluators.neural_networks.models.multi_layer_perceptron.print_piece_param(i: int, vec: Tensor) None[source]
Prints the piece parameter at index i from the given tensor.
- Parameters:
i (int) – The index of the piece parameter to print.
vec (torch.Tensor) – The tensor containing the piece parameters.
- Returns:
None
chipiron.players.boardevaluators.neural_networks.models.transformer_one module
- class chipiron.players.boardevaluators.neural_networks.models.transformer_one.Block(n_embd: int, n_head: int, dropout_ratio: float)[source]
Bases:
ModuleTransformer block: communication followed by computation
- forward(x: Tensor) Tensor[source]
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class chipiron.players.boardevaluators.neural_networks.models.transformer_one.FeedFoward(n_embd: int, dropout_ratio: float)[source]
Bases:
Modulea simple linear layer followed by a non-linearity
- forward(x: Tensor) Tensor[source]
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class chipiron.players.boardevaluators.neural_networks.models.transformer_one.Head(n_embd: int, head_size: int, dropout_ratio: float)[source]
Bases:
Moduleone head of self-attention
- forward(x: Tensor) Tensor[source]
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class chipiron.players.boardevaluators.neural_networks.models.transformer_one.MultiHeadAttention(num_heads: int, head_size: int, dropout_ratio: float, n_embd: int)[source]
Bases:
Modulemultiple heads of self-attention in parallel
- forward(x: Tensor) Tensor[source]
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.
- class chipiron.players.boardevaluators.neural_networks.models.transformer_one.TransformerArgs(number_occupancy_types: int = 13, len_square_tensor: int = 832, number_pieces_types: int = 6, type: Literal[<NNModelType.Transformer: 'transformer'>] = <NNModelType.Transformer: 'transformer'>, n_embd: int = 27, n_head: int = 3, n_layer: int = 2, dropout_ratio: float = 0.0)[source]
Bases:
object- dropout_ratio: float = 0.0
- len_square_tensor: int = 832
- n_embd: int = 27
- n_head: int = 3
- n_layer: int = 2
- number_occupancy_types: int = 13
- number_pieces_types: int = 6
- type: Transformer: 'transformer'>] = 'transformer'
- class chipiron.players.boardevaluators.neural_networks.models.transformer_one.TransformerOne(args: TransformerArgs)[source]
Bases:
ChiNN- compute_representation(node: Any, parent_node: Any, board_modifications: Any) None[source]
Compute the input representation for the given node.
- Parameters:
node (Any) – Current node.
parent_node (Any) – Parent node.
board_modifications (Any) – Board modifications.
- forward(indices: list[list[int]]) Tensor[source]
Define the computation performed at every call.
Should be overridden by all subclasses.
Note
Although the recipe for forward pass needs to be defined within this function, one should call the
Moduleinstance afterwards instead of this since the former takes care of running the registered hooks while the latter silently ignores them.