### Install PyTorch and GPyTorch Dependencies Source: https://github.com/panaali/word2ket/blob/master/README.md Installs necessary deep learning libraries, PyTorch and GPyTorch, using the conda package manager. These are prerequisites for running word2ket examples. ```bash # Install PyTorch conda install pytorch torchvision -c pytorch # Install GPyTorch conda install gpytorch -c gpytorch ``` -------------------------------- ### Install word2ket Package Source: https://github.com/panaali/word2ket/blob/master/README.md Installs the word2ket library using pip, making its embedding layers and utility functions available for use in PyTorch projects. ```bash pip install word2ket ``` -------------------------------- ### Run Text Summarization Example Source: https://github.com/panaali/word2ket/blob/master/README.md Executes a text summarization task using the GIGAWORD dataset. It provides commands to run the task with standard PyTorch `nn.Embedding`, `EmbeddingKet`, and `EmbeddingKetXS` layers, allowing for comparison of performance and resource usage. ```bash # Using Pytorch nn.Embedding Layer python seq2seq_attn.py --embedding_type nn.Embedding --gpu 4 --runName G_000 --config-model config_model --config-data config_giga # Using EmbeddingKet Layer python seq2seq_attn.py --embedding_type EmbeddingKet --gpu 0 --runName V2K_G_000 --config-model config_model --config-data config_giga --order 4 --rank 1 # Using EmbeddingKetXS Layer python seq2seq_attn.py --embedding_type EmbeddingKetXS --gpu 0 --runName V2K_XS_G_000 --config-model config_model --config-data config_giga --order 4 --rank 1 ``` -------------------------------- ### Run German-English Machine Translation Example Source: https://github.com/panaali/word2ket/blob/master/README.md Sets up and runs a German-English machine translation task using the IWSLT2014 dataset. This example showcases the application of word2ket's embedding layers in a sequence-to-sequence model for translation. ```bash # Install Texar-PyTorch pip install texar-pytorch # Install Rouge pip install rouge cd ./examples/texar/ python ./prepare_data.py --data iwslt2014 ``` -------------------------------- ### Using EmbeddingKetXS Layer in PyTorch Source: https://github.com/panaali/word2ket/blob/master/README.md Demonstrates the creation and usage of the `EmbeddingKetXS` layer from the word2ket library. It shows how to initialize the layer and uses the `summary` function to display its parameter count, highlighting its space efficiency compared to standard PyTorch `nn.Embedding`. ```python # examples/demo.py from word2ket import EmbeddingKet, EmbeddingKetXS, ketify, summary from torch import nn import logging logging.basicConfig(level=logging.INFO) # Word2Ket Embedding Layer w2v_embedding_layer = EmbeddingKetXS(num_embeddings=30000, embedding_dim=256, order=4, rank=1) summary(w2v_embedding_layer) """ INFO:root:EmbeddingKetXS num_embeddings_leaf: 14 INFO:root:EmbeddingKetXS embedding_dim_leaf: 4 INFO:root:EmbeddingKetXS weight_leafs shape: torch.Size([4, 1, 14, 4]) Module Name Total Parameters Trainable Parameters # Elements in Trainable Parametrs EmbeddingKetXS(30000, 256) 1 1 224 Total number of trainable parameters elements 224 """ # PyTorch Embedding Layer class MyModel(nn.Module): def __init__(self, vocab_size, embedding_dim): super(MyModel, self).__init__() self.embedding = nn.Embedding(num_embeddings=vocab_size, embedding_dim=embedding_dim) def forward(self, x): self.embedding() model = MyModel(vocab_size=30000, embedding_dim=256) print("embedding.weight.shape: ", model.embedding.weight.shape) """ embedding.weight.shape: torch.Size([30000, 256]) """ summary(model) """ Module Name Total Parameters Trainable Parameters # Elements in Trainable Parametrs Embedding(30000, 256) 1 1 7,680,000 Total number of trainable parameters elements 7,680,000 """ # Replace the nn.Embedding to EmbeddingKetXS automatically using the ketify function. ketify(model, order=4, rank=2, use_EmbeddingKetXS=True) summary(model) """ INFO:root:EmbeddingKetXS num_embeddings_leaf: 14 INFO:root:EmbeddingKetXS embedding_dim_leaf: 4 INFO:root:EmbeddingKetXS weight_leafs shape: torch.Size([4, 2, 14, 4]) INFO:root:Replaced embedding in MyModel Module Name Total Parameters Trainable Parameters # Elements in Trainable Parametrs EmbeddingKetXS(30000, 256) 1 1 448 Total number of trainable parameters elements 448 """ ``` -------------------------------- ### Run seq2seq_attn with EmbeddingKet Source: https://github.com/panaali/word2ket/blob/master/README.md Executes the seq2seq_attn.py script using the EmbeddingKet layer. This command includes additional parameters for order and rank, specifying the embedding type, GPU, run name, and configuration files. ```python python seq2seq_attn.py --embedding_type EmbeddingKet --gpu 0 --runName V2K_I_000 --config-model config_model --config-data config_iwslt14 --order 4 --rank 1 ``` -------------------------------- ### Run seq2seq_attn with EmbeddingKetXS Source: https://github.com/panaali/word2ket/blob/master/README.md Executes the seq2seq_attn.py script using the EmbeddingKetXS layer. This command specifies the embedding type, GPU, run name, configuration files, and additional parameters for order and rank. ```python python seq2seq_attn.py --embedding_type EmbeddingKetXS --gpu 0 --runName V2K_XS_I_000 --config-model config_model --config-data config_iwslt14 --order 4 --rank 1 ``` -------------------------------- ### Run seq2seq_attn with nn.Embedding Source: https://github.com/panaali/word2ket/blob/master/README.md Executes the seq2seq_attn.py script using PyTorch's nn.Embedding layer. This command specifies the embedding type, GPU to use, a run name, and configuration files for the model and data. ```python python seq2seq_attn.py --embedding_type nn.Embedding --gpu 4 --runName I_000 --config-model config_model --config-data config_iwslt14 ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.