Skip to main content

Squeezeformer

Squeezeformer incorporates the Temporal U-Net structure, which reduces the cost of the multi-head attention modules on long sequences, and a simpler block structure of feed-forward module, followed up by multi-head attention or convolution modules, instead of the Macaron structure proposed in Conformer.

스크린샷 2022-06-11 오전 1 19 40

This repository contains only model code, but you can train with squeezeformer at openspeech.

Installation

pip install squeezeformer

Usage

import torch
import torch.nn as nn
from squeezeformer.model import Squeezeformer


BATCH_SIZE = 4
SEQ_LENGTH = 500
INPUT_SIZE = 80
NUM_CLASSES = 10

device = torch.device('cuda' if torch.cuda.is_available() else 'cpu')

criterion = nn.CTCLoss().to(device)
model = Squeezeformer(
     num_classes=NUM_CLASSES,
).to(device)

inputs = torch.FloatTensor(BATCH_SIZE, SEQ_LENGTH, INPUT_SIZE).to(device)
input_lengths = torch.IntTensor([500, 450, 400, 350]).to(device)
targets = torch.LongTensor([[1, 3, 3, 3, 3, 3, 4, 5, 6, 2],
                           [1, 3, 3, 3, 3, 3, 4, 5, 2, 0],
                           [1, 3, 3, 3, 3, 3, 4, 2, 0, 0],
                           [1, 3, 3, 3, 3, 3, 6, 2, 0, 0]]).to(device)
target_lengths = torch.LongTensor([9, 8, 7, 7]).to(device)

# Forward propagate
outputs, output_lengths = model(inputs, input_lengths)

# Calculate CTC Loss
for _ in range(3):
     outputs, output_lengths = model(inputs, input_lengths)
     loss = criterion(outputs.transpose(0, 1), targets[:, 1:], output_lengths, target_lengths)
     loss.backward()

Reference

License

Copyright 2022 Sangchun Ha.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Metadata

Release files for squeezeformer 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for squeezeformer 1.0.0
File Interpreter ABI Platform Actions
squeezeformer-1.0.0-py3-none-any.whl Python 3 none any Details for squeezeformer-1.0.0-py3-none-any.whl

Release files / squeezeformer-1.0.0-py3-none-any.whl

Download URL squeezeformer-1.0.0-py3-none-any.whl
Size 18.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7c5a4524c5ef2a8eb201ba90ffde0373e2eb5015a99b3deaa658ffa32d6feb2f
BLAKE2b-256 checksum
How to use checksums
1f3e5b71b091d3fcea60936354250a9d70468d5ed5b09cf2eacde8611bb98521
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.8.13

Security for squeezeformer 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page