Git Product home page Git Product logo

end2end's Introduction

Losses and decoders for end-to-end Speech Recognition and Optical Character Recognition with PyTorch

Build

The module focuses on experiments with CTC-loss (Connectionist Temporal Classification) and its modifications.

Under active development.

Documentation

artbataev.github.io/end2end/

Losses

  • CTC (C++, CPU)
  • CTC without blank (python / numba), needs refactoring
  • Dynamic segmentation with CTC (python), needs refactoring

Decoders

  • CTC Greedy Decoder (C++, CPU)
  • CTC Beam Search Decoder (C++, CPU)
  • CTC Beam Search Decoder with language model (C++, CPU)

How to install

Requirements:

  • Python 3.4+
  • PyTorch 1.0 and higher
  • numpy
  • numba
  1. Install PyTorch 1.0 from pytorch.org, e.g.

    pip install torch
  2. Install tools to compile

    sudo add-apt-repository ppa:ubuntu-toolchain-r-test
    sudo apt-get install cmake libboost-all-dev
  3. Install the module

    pip install -v git+https://github.com/artbataev/end2end.git

    or

    git clone --recursive https://github.com/artbataev/end2end.git
    cd end2end
    python setup.py install
    python -m tests.test_ctc
    python -m tests.test_ctc_decoder

How to use

CTC Loss

import torch
from pytorch_end2end import CTCLoss

ctc_loss = CTCLoss(blank_idx=0, time_major=False, 
    reduce=True, size_average=True, after_logsoftmax=False)

batch_size = 4
alphabet_size = 28 # blank + 26 english characters + space

logits = torch.randn(batch_size, 50, alphabet_size).detach().requires_grad_()
targets = torch.randint(1, alphabet_size, (batch_size, 30), dtype=torch.long)
logits_lengths = torch.full((batch_size,), 50, dtype=torch.long)
targets_lengths = torch.randint(10, 30, (batch_size,), dtype=torch.long)

loss = ctc_loss(logits, targets, logits_lengths, targets_lengths)
loss.backward()

CTC Decoder

import torch
from pytorch_end2end import CTCDecoder

batch_size = 4
alphabet_size = 6
decoder = CTCDecoder(blank_idx=0, beam_width=100, time_major=False, 
    labels=["_", "a", "b", "c", "d", " "])

logits = torch.randn(batch_size, 50, alphabet_size).detach()
logits_lengths = torch.full((batch_size,), 50, dtype=torch.long)

decoded_targets, decoded_targets_lengths, decoded_sentences = decoder.decode(logits, logits_lengths)
for sentence in decoded_sentences:
    print(sentence)

Future Plans

Losses

  • CTC without blank (C++, CPU)
  • Gram-CTC
  • CTC (Cuda)

Decoders

  • Speedup CTC Beam Search Decoder
  • Restrict Beam Search with vocabulary
  • Allow custom transcriptions
  • Gram-CTC Beam Search Decoder

end2end's People

Contributors

artbataev avatar

Watchers

James Cloos avatar GRU avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.