<jupyter_start><jupyter_text>Fully connected network for speech component codes  Database<jupyter_code>import torch
from torch.utils.data import Dataset, DataLoader
import pickle
tr = torch
class CodesDataset(Dataset):
    def __init__(self):
        with open("dbase.pkl", "rb") as f:
            self.db = pickle.load(f)
    
        self.n = len(self.db)
        
        
    def __len__(self):
        return self.n
    
    
    def __getitem__(self, idx):
        src = tr.from_numpy(self.db[idx]["src"])
        trg = tr.from_numpy(self.db[idx]["trg"])
        
        return {"input": src, "target": trg, "id": self.db[idx]["uttr_id"] }
test = CodesDataset()
test[0]<jupyter_output><empty_output><jupyter_text>Network<jupyter_code>class CodeConverter(tr.nn.Module):
    def __init__(self, layer_dims=None, activation=None, dropout_p=0):
        super().__init__()
        self.layer_dims = layer_dims
        self.activation = activation
        if self.layer_dims is None:
            self.layer_dims = [24*82, 1024, 512, 512, 1024, 24*82]
        
        if self.activation is None:
            self.activation = tr.nn.LeakyReLU()
            
        self.layers = tr.nn.ModuleList()
        self.layers.append(tr.nn.Flatten())
        
        n_layers = len(self.layer_dims)
        for cnt, (i, o) in enumerate(zip(self.layer_dims, self.layer_dims[1:])):
            self.layers.append(tr.nn.Linear(i, o))
            
            # do not apply activation on last layer
            if cnt < n_layers-1:
                self.layers.append(self.activation)
                
            # apply dropout on hidden layers
            if cnt > 0 and cnt < n_layers-1:
                self.layers.append(tr.nn.Dropout(dropout_p))
            
            
    def forward(self, x):
        for layer in self.layers:
            x = layer(x)
        
        # codes are in range -1, 1
        x = tr.tanh(x)
        
        return x.view(x.shape[0], 24, 82)

code_converter = CodeConverter()
y = code_converter(tr.randn(1, 24, 82))
print(y.shape, y)
def count_parameters(model):
    return sum(p.numel() for p in model.parameters() if p.requires_grad)

print(count_parameters(code_converter))
cc = CodeConverter(layer_dims=[24*82, 1024, 1024, 24*82])
print(count_parameters(cc))<jupyter_output>5083056
{'fraction_non_alphanumeric': 0.12019022913964549, 'fraction_numerical': 0.027237354085603113, 'mean_word_length': 2.259154929577465, 'pattern_counts': {'":': 3, '<': 10, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '2', 'dir': 'jupyter-structured-clean-dedup', 'id': '619540', 'license': 'MIT', 'n_tokens_mistral': 815, 'n_tokens_neox': 775, 'n_words': 163, 'path': 'fully_connected_on_codes.ipynb', 'repo_name': 'terbed/SpeechSplit', 'size': '2313'}