diff --git a/docs/zeta/ops/img_order_of_axes.md b/docs/zeta/ops/img_order_of_axes.md index 05564b3d..666f6e19 100644 --- a/docs/zeta/ops/img_order_of_axes.md +++ b/docs/zeta/ops/img_order_of_axes.md @@ -4,14 +4,11 @@ The `img_order_of_axes` function is a utility designed to reorder the axes of an This documentation provides an in-depth understanding of the `img_order_of_axes` function, its architecture, and the rationale behind its design. We will cover multiple usage examples, detailing the parameters, expected inputs and outputs, along with additional tips and resources. -## Introduction - The `img_order_of_axes` function plays a crucial role in scenarios where a batch of images needs to be combined into a single image with individual images laid out horizontally. This function is particularly useful when there is a need to visualize multiple similar images side by side, such as comparing different stages of image processing or visualization of input-output pairs in machine learning tasks. ## Function Definition ### img_order_of_axes(x) - Rearranges the axes of an image tensor from batch-height-width-channel order to height-(batch * width)-channel order. #### Parameters: @@ -23,9 +20,6 @@ Rearranges the axes of an image tensor from batch-height-width-channel order to #### Returns: A rearranged tensor that combines the batch and width dimensions, resulting in a shape of (h, b * w, c). -## Functionality and Usage - -The `img_order_of_axes` function relies on the 'rearrange' utility, which is commonly provided by libraries like `einops`. This function provides a simple, yet powerful operation that alters the shape and order of axes in a tensor without changing its data. For image tensors, it's often necessary to manipulate their structure to conform to visualization standards or input requirements of certain algorithms. ### Usage Example 1: @@ -36,7 +30,6 @@ import torch from einops import rearrange from zeta.ops import img_order_of_axes -# Assuming torch is the backend used for tensors # Create a dummy batch of images with shape (b, h, w, c) batch_size, height, width, channels = 4, 100, 100, 3 dummy_images = torch.rand(batch_size, height, width, channels) @@ -96,11 +89,3 @@ output = model(large_image.unsqueeze(0)) # Add batch dimension of 1 at the begi - It's important to note that the `rearrange` function used within `img_order_of_axes` is not a PyTorch built-in function. It requires the `einops` library which offers more flexible operations for tensor manipulation. - To install `einops`, use the package manager of your choice, e.g., `pip install einops` for Python's pip package manager. - When visualizing the rearranged tensor, ensure that the visualization tool or library you choose can handle non-standard image shapes, as the resulting tensor will have a width that is a multiple of the original width. - -## References and Resources - -For more information on tensor manipulation and visualization, please refer to the following resources: - -- [Einops Documentation](https://einops.rocks/) -- [PyTorch Tensors Documentation](https://pytorch.org/docs/stable/tensors.html) -- [Image Visualization Techniques](https://matplotlib.org/3.1.1/gallery/images_contours_and_fields/image_demo.html) (using Matplotlib) diff --git a/docs/zeta/ops/merge_small_dims.md b/docs/zeta/ops/merge_small_dims.md index b5a83975..4c166439 100644 --- a/docs/zeta/ops/merge_small_dims.md +++ b/docs/zeta/ops/merge_small_dims.md @@ -1,13 +1,6 @@ # merge_small_dims - -The `merge_small_dims` is a utility function within the fictional `zeta.ops` library, built to manipulate tensor dimensions in order to optimize computation. This document provides comprehensive information, examples, and guidelines for its usage. The following sections will cover the purpose, functionality, usage examples, and additional tips related to `merge_small_dims`. - -## Overview and Introduction - -The `zeta.ops` library provides utility operations for working with tensors. It is common for tensor-oriented computations to encounter scenarios where the shape of a tensor may include dimensions with smaller sizes that can be beneficially merged to optimize performance or conform to specific requirement constraints. - -The `merge_small_dims` function specifically targets such use-cases. It allows reshaping of a tensor by merging its smaller dimensions (below a certain threshold) while ensuring that the overall element count of the tensor remains unchanged. This operation is particularly useful in developing deep learning models where tensor dimensions might need adjustments before passing through layers or operations. +allows reshaping of a tensor by merging its smaller dimensions (below a certain threshold) while ensuring that the overall element count of the tensor remains unchanged. This operation is particularly useful in developing deep learning models where tensor dimensions might need adjustments before passing through layers or operations. ## Class/Function Definition @@ -34,7 +27,7 @@ When to use `merge_small_dims`: ```python from typing import List -from zeta.ops import merge_small_dims # Assuming zeta.ops is the library path +from zeta.ops import merge_small_dims # Original tensor shape orig_shape = [2, 3, 1, 5, 1] diff --git a/docs/zeta/ops/mos.md b/docs/zeta/ops/mos.md index ac4024e2..cf00ba49 100644 --- a/docs/zeta/ops/mos.md +++ b/docs/zeta/ops/mos.md @@ -1,39 +1,10 @@ # `MixtureOfSoftmaxes` Documentation -The `MixtureOfSoftmaxes` module is an implementation of the Mixture of Softmaxes (MoS) as described by Yang et al. in 2017. This module enhances the expressiveness of the softmax function by combining multiple softmaxes. It is particularly useful for tasks where the relationship between input features and output classes is complex and can benefit from a combination of multiple softmax distributions. - -## Table of Contents - -- [Overview](#overview) -- [Installation](#installation) -- [Usage](#usage) - - [Initialization](#initialization) - - [Forward Pass](#forward-pass) -- [Examples](#examples) - - [Basic Example](#basic-example) - - [Complex Task](#complex-task) -- [Parameters](#parameters) -- [Return Value](#return-value) -- [Additional Information](#additional-information) -- [References](#references) - -## Overview The `MixtureOfSoftmaxes` module is designed to improve the modeling capabilities of the softmax function by allowing the combination of multiple softmax distributions. It takes an input tensor and computes a weighted sum of softmax outputs from different softmax layers. These weights are learned during training, enabling the model to adapt to the data's characteristics effectively. The primary use case of the MoS module is in scenarios where a single softmax may not capture the complex relationships between input features and output classes. By combining multiple softmax distributions with learned mixture weights, the module provides a flexible approach to handle such situations. -## Installation - -Before using the `MixtureOfSoftmaxes` module, ensure you have the required dependencies installed. You'll need: - -- zetascale - -You can install Zeta using pip: - -```bash -pip install zetascale -``` Once you have the dependencies installed, you can import the module in your Python code. @@ -139,10 +110,5 @@ The `forward` method of the `MixtureOfSoftmaxes` module returns two values: ## Additional Information - The MoS module can be used in a variety of deep learning tasks, including classification, natural language processing, and more. -- It is important to fine-tune the number of mixtures and other hyperparameters based on the specific task and dataset. -## References - -- Yang, Z., Hu, Z., Salakhutdinov, R., and Berg-Kirkpatrick, T. (2017). Improved variational inference with inverse autoregressive flow. In Proceedings of the 34th International Conference on Machine Learning (ICML). - -This documentation provides a comprehensive guide on using the `MixtureOfSoftmaxes` module. Feel free to explore its capabilities and adapt it to your specific machine learning tasks. \ No newline at end of file +- It is important to fine-tune the number of mixtures and other hyperparameters based on the specific task and dataset. diff --git a/docs/zeta/ops/rearrange.md b/docs/zeta/ops/rearrange.md deleted file mode 100644 index b8ae3610..00000000 --- a/docs/zeta/ops/rearrange.md +++ /dev/null @@ -1,81 +0,0 @@ -# rearrange - -Creating a comprehensive and thorough documentation similar to PyTorch for the `rearrange` operation from the `einops` library would be an extensive task, beyond the practical scope of this platform. The output would also far exceed the character limit for responses. However, here I will outline the structure and provide an abridged version of such documentation that follows the requested format. - ---- - -# Zeta Operations (zeta.ops) Documentation - -## `rearrange` Function - -### Purpose and Architecture - -The `rearrange` function is a significant component of the `einops` library that provides a versatile and intuitive way to manipulate the shape and structure of multidimensional arrays (tensors). It combines the functionality of several familiar tensor operations such as transpose, reshape, squeeze, unsqueeze, stack, and concatenate into one concise and readable operation. - -The purpose of `rearrange` is to create more readable and maintainable code when performing complex tensor transformations. The function uses a pattern string to define the transformation rule, making the operations explicit and reducing the likelihood of errors common in manual calculations of indices and dimensions. - -The class works by interpreting the pattern and applying a series of well-defined operations to transform the input tensor according to the user's specifications. This flexibility makes it valuable for data preprocessing, especially in domains like deep learning where tensor shape manipulation is frequent. - -### Parameters - -| Parameter | Type | Description | -|----------------|--------------------------------|----------------------------------------------------------------| -| tensor | Union[Tensor, List[Tensor]] | Input tensor or list of tensors of the same type and shape. | -| pattern | str | Rearrangement pattern expressed as a string. | -| **axes_lengths | unpacked dict | Dictionary of axes lengths for additional dimension specifics. | - -### Examples - -#### Example 1: Basic Rearrangement - -```python -# Import einops for the rearrange function -from einops import rearrange -import numpy as np - -# Create a set of images in "height-width-channel" format -images = [np.random.randn(30, 40, 3) for _ in range(32)] -# Rearrange to "batch-height-width-channel" format -tensor = rearrange(images, 'b h w c -> b h w c') -print(tensor.shape) # Output: (32, 30, 40, 3) -``` - -#### Example 2: Concatenation Along an Axis - -```python -# Another example using the same images -# Concatenate images along height (vertical concatenation) -tensor = rearrange(images, 'b h w c -> (b h) w c') -print(tensor.shape) # Output: (960, 40, 3) -``` - -#### Example 3: Flattening and Splitting - -```python -# Flatten each image into a vector -flattened_images = rearrange(images, 'b h w c -> b (c h w)') -print(flattened_images.shape) # Output: (32, 3600) - -# Split each image into 4 smaller sections -split_images = rearrange(images, 'b (h1 h) (w1 w) c -> (b h1 w1) h w c', h1=2, w1=2) -print(split_images.shape) # Output: (128, 15, 20, 3) -``` - -### Further Considerations and Tips - -- Ensure the `pattern` provided matches the input tensor's dimensions. -- When providing custom axes_lengths, make sure they divide the corresponding tensor dimension without a remainder. -- Understand the order of operations in `einops` and how they apply to the `pattern` string. - -### References - -- Einops Documentation: [Einops GitHub](https://github.com/arogozhnikov/einops) -- Einops Tutorial and Examples: [Einops Tutorial](https://einops.rocks/) - -### Source Code - -Please refer to [einops GitHub repository](https://github.com/arogozhnikov/einops) for the original source code and additional information. - ---- - -Please note that the above documentation is a much-condensed version and serves as an example template. A complete documentation would entail a variety of additional elements such as in-depth explanations for the usage of patterns, extensive examples covering a wide array of use cases, edge cases, and error handling, performance considerations, and a detailed explanation of the internal workings of the `rearrange` operation. diff --git a/mkdocs.yml b/mkdocs.yml index f734312f..5834bc36 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -190,7 +190,6 @@ nav: - video_tensor_to_gift: "zeta/utils/video_tensor_to_gift.md" - zeta.ops: - img_compose_decompose: "zeta/ops/img_compose_decompose.md" - - rearrange: "zeta/ops/rearrange.md" - img_transpose_2daxis: "zeta/ops/img_transpose_2daxis.md" - img_transpose: "zeta/ops/img_transpose.md" - img_order_of_axes: "zeta/ops/img_order_of_axes.md"